Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need more vertex attributes (for terrain shading) #9134

Closed
Zylann opened this issue Jun 12, 2017 · 10 comments
Closed

Need more vertex attributes (for terrain shading) #9134

Zylann opened this issue Jun 12, 2017 · 10 comments

Comments

@Zylann
Copy link
Contributor

Zylann commented Jun 12, 2017

Shading a heightmap terrain as a module using texture arrays requires at least the following vertex attributes:

By usage + type:

  • POSITION (Vector3)
  • NORMAL (Vector3)
  • BLEND_INDICES (Vector4)
  • BLEND_WEIGHTS (Vector4) <-- also note the engine doesn't have Vector4

In order to be able to do this in the shader (assuming texarrays are supported):

	c += texture2DArray(s, vec3(uv.xy, indices.x)) * weigths.x;
	c += texture2DArray(s, vec3(uv.xy, indices.y)) * weigths.y;
	c += texture2DArray(s, vec3(uv.xy, indices.z)) * weigths.z;
	c += texture2DArray(s, vec3(uv.xy, indices.w)) * weigths.w;

However the amount of attributes currently in engine are limited for this.
In theory I could use COLOR, UV and UV2 to have those 8 missing floats, but if COLOR needs to be used for something else then there is not enough attributes left (TANGENTS, BONES and WEIGHTS give only 2 floats and an int).

Given that GLES3 allows for any number of attributes (no longer hardcoded), is there a chance we can have more, or at best custom vertex attributes in 3.0?

@reduz
Copy link
Member

reduz commented Aug 7, 2017

not going to happen, but as mentioned a while ago, you can use vertexID and vertex texture fetch to get as much data as you want

@reduz reduz closed this as completed Aug 7, 2017
@Zylann
Copy link
Contributor Author

Zylann commented Aug 7, 2017

But isn't a texture fetch a lot more expensive than vertex attributes? Especially when it's about rendering pretty large patches of pixels

@reduz
Copy link
Member

reduz commented Aug 7, 2017 via email

@jwurzer
Copy link

jwurzer commented Dec 7, 2019

Is there a way to use the vertexID in a shader?

I need additional attributes in a CanvasItem shader for a MeshInstance2D. The idea now would be to use the vertexId inside the vertex() shader function to calculate the UV texcoord for the vertex texture fetch. The trick with a MultiMesh to use INSTANCE_CUSTOM (see #31299 ) should not be possible because MeshInstance2D uses a Mesh and not a MultiMesh.

@jwurzer
Copy link

jwurzer commented Dec 7, 2019

Okay, I've now found a solution. Instead of using vertexID, I now use UV as vertexID. It even has the advantage that I can already precalculate the correct fetch coordinates between 0.0 and 1.0.
For the real UV coordinates I need now an additional vertex texture (because the original UV is now used for vertexID). It would be great if something like CUSTOM_ATTR (e.g. as vec4) would be available.

@clayjohn
Copy link
Member

clayjohn commented Dec 7, 2019

@jwurzer just use UV2 and or Color.

@jwurzer
Copy link

jwurzer commented Dec 8, 2019

UV2 doesn't exist for CanvasItem shaders. Only for Spatial shaders. COLOR is used at my example for colors.

In my MeshInstance2D example I want to realize Multitexturing with two textures via CanvasItem shader. Where different UV coordinates are to be used for the textures. The two textures doesn't share the same uv coordinates. Therefore the UV attribute is not enough. Since a CanvasItem shader does not provide UV2, I solved it as described above.

@FrederickDesimpel
Copy link

you can use vertexID

How can we use it it's not exposed ?

Even then, for dynamic geometry, how is updating a texture on cpu then fetching it in shader faster then passing another array ?

@FrederickDesimpel
Copy link

Will vertex id and custom vertex attributes come to Godot4.0 with Vulcan ?

how about geometry / tesselation / mesh shaders ?

@SleepProgger
Copy link

Currently i don't see ANY way to implement anything that needs more than Color and UV attributes in a canvas_item shader.
There is no UV2 or anything else that could be used. There is no vertexID that could be used to circumvent it..
At least give us some additional 4 floats or something to use please.
Adding proper support for custom attributes would be way nicer but hey, anything would be better than nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants