-
-
Notifications
You must be signed in to change notification settings - Fork 23.6k
Add custom shader support to SpriteBase3D #103274
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
base: master
Are you sure you want to change the base?
Add custom shader support to SpriteBase3D #103274
Conversation
8330368 to
36e80b5
Compare
Calinou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, it works as expected.
Testing project: test_pr_103274.zip
Some feedback:
- There should be a Sprite3D shader template you can choose from, with the correct uniforms already in place:
The shader template could also have render_mode unshaded; below shader_mode spatial;, as most Sprite3Ds are used in an unshaded manner (this is their default property).
Note that if #103312 is merged before this PR, the cache key should vary depending on the custom shader used. It should be possible for meshes with the same ShaderMaterial resource to be reused, but different shaders will require a different cache key.
36e80b5 to
79b7adf
Compare
79b7adf to
9be33cc
Compare
godot-sprite3d-custom-shader-template.mp4
Note that |
9be33cc to
3f13a5a
Compare
|
Just looking at this because it came up during the rendering meeting, with clay on holiday don't want to make an in-depth judgement call. But my question would be, why make this work with a special uniform? Why not make this work with the normal albedo color hint so the code is the same as with normal geometry? What makes this a different situation? |
Oh, I was admittedly not aware of the The design here was so the code path is consistent between both cases. I see how it's possible to replace Though |
3f13a5a to
71dc166
Compare
|
(Rebased to fix conflict with ad9b661 ) Follow up: I think there's an actual argument against using
As such, I think the current approach is fine as-is. |


Closes godotengine/godot-proposals#3266
godot-sprite3d-custom-shader-demo.mp4
This PR lets custom shaders (via Material Override) access the sprite texture used by SpriteBase3D. (and its child classes Sprite3D and AnimatedSprite3D by extension)
Validation is implemented to warn the user if a Material Override without the necessary uniforms (namely
uniform sampler2D texture_albedoanduniform ivec2 albedo_texture_size) is being used. The "Flags" group properties of SpriteBase3D are also hidden when a Material Override is being used, as those properties are used in the default automatic material generation. (StandardMaterial3D::get_material_for_2d()) The user can reimplement those features in the custom shader code anyway, so they have been hidden.Side note: This pattern of requiring the shader to have uniforms of specific names and types can be turned into a reusable "shader interface/trait" system if needed. Users could make their own high-level 3D nodes that send data to shaders like SpriteBase3D does. (Maybe a more advanced version of Sprite3D that assigns normal maps and SDF texture maps as uniforms) The main benefit of such a system would be to reduce the amount of builtin shader types, though. (No need to add a new
sprite_3dshader type) Though this probably would have to be a separate proposal.This PR was originally made to add custom shader support for AnimatedSprite3D in particular, but it is evident that implementing the support for SpriteBase3D makes more sense here.