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

Backport support for custom vertex shader attributes to 3.x #3465

Closed
bluenote10 opened this issue Oct 24, 2021 · 2 comments
Closed

Backport support for custom vertex shader attributes to 3.x #3465

bluenote10 opened this issue Oct 24, 2021 · 2 comments
Milestone

Comments

@bluenote10
Copy link

bluenote10 commented Oct 24, 2021

Describe the project you are working on

Guitar practicing app (3d), data visualization app (2d)

Describe the problem or limitation you are having in your project

Advanced rendering techniques often require additional / non-standard vertex attributes on a vertex shader. Currently Godot's shaders only support a fixed set of vertex attributes depending on the shader type, which is much less than what regular GLSL shaders can do, i.e., it's not possible to leverage the full power of GLSL.

See the "can it be worked around" section for more details on the limitation.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Ideally the feature would enable the full power of GLSL vertex attributes in Godot. The OpenGL standard ensures a minimum support (GL_MAX_VERTEX_ATTRIBS) of 8 (ES2) or 16 (ES3) 4-component vertex attributes. These vertex attributes can be used for advanced rendering techniques. I'm not an expert, but a few use cases I've encountered:

  • Nicolas Rougier's Antialiased 2D Grid, Marker, and Arrow Shaders: All relevant marker properties like marker color, type, size, linewidth, or orientation could be passed to the shader on a per vertex (= marker) basis.
  • Nicolas Rougier's Shader-Based Antialiased Dashed Stroked Polylines: In this example it would make sense to use the line segment lengths as a per-vertex attribute (and other dashing specific params), allowing to render connected line segments properly.
  • Scale invariant fat-line rendering techniques like described here require passing additional per-vertex information to perform the proper vertex displacement in the shader.
  • Bezier lines rendering: I haven't looked into that in detail, but I assume it is a likely candidate for additional vertex attributes as well.
  • In the my app that I'm trying to port to Godot, I'm doing similar procedural geometry techniques in the vertex shader that require custom attributes.
  • Use cases raised by the Godot community: Need more vertex attributes (for terrain shading) godot#9134 VERTEX_ID and mesh-less rendering godot#19473

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I'd have to think about it. I'm raising the issue now for some initial brainstorming ;).

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not always, mainly depending on how many custom vertex attributes are needed.

In some cases it is possible to use a hack and abuse some of the standard attributes for a different purpose. This is not only suboptimal in terms of readability, it can also mean that the data passed to the shader can be "too much" due to the granularity of these additional attributes. For instance, if a shader needs 1 additional float attribute (say marker size) and one uses the first float of UV for that, the second float is passed unnecessarily. Similarly when one wants to pass an int/id or only individual bits for enum like attributes.

However if the number of required vertex attributes exceeds what is possible with the hack, there doesn't seem a way to implement the equivalent of a raw GLSL shader. In this case, perhaps the only work-around is to resort to multiple draw calls, i.e., use a uniform instead of a vertex attributes. This can mean that instead of 1 draw call, one has to perform thousands of draw calls, which could become a showstopper in terms of performance.

Is there a reason why this should be core and not an add-on in the asset library?

It's a core property of Godot's shaders I assume.

@Calinou
Copy link
Member

Calinou commented Oct 24, 2021

This is already available in the master branch, but it can't be backported to 3.x. A completely different implementation is needed there, but most importantly, a contributor needs to do that work 🙂

@bluenote10
Copy link
Author

bluenote10 commented Apr 16, 2023

This is already available in the master branch, but it can't be backported to 3.x. A completely different implementation is needed there, but most importantly, a contributor needs to do that work slightly_smiling_face

It should be noted that I didn't really mean backporting anything to Godot 3.

What I was hoping for was that it really allows custom shader attributes, including using custom attributes names (not hard coded ones => readability issue), and also different types, not just vec4.

@Calinou Calinou closed this as not planned Won't fix, can't repro, duplicate, stale Apr 16, 2023
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

2 participants