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

Document global and per-instance uniforms in Shading language #6414

Merged

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Nov 22, 2022

See #5121. This takes some parts from https://godotengine.org/article/godot-40-gets-global-and-instance-shader-uniforms (thanks reduz 🙂).

Some questions I have to further complete this documentation:

  • Does using GeometryInstance3D.get_instance_shader_parameter() have a performance cost like getting global uniform values through a script? I don't get any warning when using it, but I also can't seem to get any value from it anyway.
  • What's the difference between RenderingServer's global_shader_parameter_set() and global_shader_parameter_set_override()? I'm not sure what use cases each method has in practice. The former fails with an error if the uniform doesn't exist, while the latter fails silently. Only the latter fails early if the uniform's type extends Object.
  • Is a default value assigned to a global uniform ever used? Shader compilation fails if the global uniform isn't defined in the project settings.

@mhilbrunner
Copy link
Member

cc @clayjohn :) Looks good to me and spotted nothing on a first glance, will give it a more thorough read later.

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I left a few comments and suggestions

@Calinou
Copy link
Member Author

Calinou commented Dec 8, 2022

I'm copying the team color bit below as it was removed from the docs (but it wasn't part of the original blog post). Still, it may be useful for others in the future.

  1. Providing team colors. In team-based games, you can use global uniforms
    to provide "friendly" and "enemy" colors that can automatically be used
    everywhere relevant (player materials, map textures, special effects, GUI
    elements, ...). This can be used to let players choose team colors freely, for
    better accessibility. The "friendly" and "enemy" states themselves can be
    determined by using a :ref:per-instance uniform <doc_shading_language_per_instance_uniforms> that indicates the instance's
    current team.

@clayjohn Do you know the answer to the questions in OP? This would help flesh out the documentation 🙂

@Calinou Calinou force-pushed the add-global-per-instance-shader-uniforms branch from 1e02b90 to 0e369eb Compare December 8, 2022 01:11
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does using GeometryInstance3D.get_instance_shader_parameter() have a performance cost like getting global uniform values through a script? I don't get any warning when using it, but I also can't seem to get any value from it anyway.

Not really, it is just reading from a hashmap

What's the difference between RenderingServer's global_shader_parameter_set() and global_shader_parameter_set_override()? I'm not sure what use cases each method has in practice. The former fails with an error if the uniform doesn't exist, while the latter fails silently. Only the latter fails early if the uniform's type extends Object.

Its for use by the ShaderGlobalOverrides node

Is a default value assigned to a global uniform ever used? Shader compilation fails if the global uniform isn't defined in the project settings.

I don't think so. Imagine if you had multiple shaders that each used a different default value, which one should be picked?

@Calinou Calinou force-pushed the add-global-per-instance-shader-uniforms branch from 0e369eb to 5d61587 Compare December 19, 2022 17:02
@Calinou Calinou merged commit 319106b into godotengine:master Dec 23, 2022
@Calinou Calinou deleted the add-global-per-instance-shader-uniforms branch December 23, 2022 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants