-
-
Notifications
You must be signed in to change notification settings - Fork 23.5k
Add Use Radiance as Background render mode to sky shaders #105889
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 Use Radiance as Background render mode to sky shaders #105889
Conversation
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.
I would just make this an option in the ProceduralSkyMaterial and the PhysicalSkyMaterial. I don't think there is any benefit gained by making this a render mode and I don't think it is needed for the PanoramaSkyMaterial (since it would just lower the effective resolution for no performance gain).
You can directly use the code I posted in the bug report #88394 (comment)
|
You may want to do this for complex custom sky shaders. |
Is there a way to do this without imposing a runtime I'm not sure if the Godot shader preprocessor is able to achieve this with For complex sky shaders, this can make a significant difference as the branch that is always Note that this PR already doesn't expose the option in PanoramaSkyMaterial by design, just in ProceduralSkyMaterial and PhysicalSkyMaterial. |
You already can. I've been doing it in my cloud demo for 3 years https://github.com/clayjohn/godot-volumetric-cloud-demo/blob/main/clouds.gdshader
Yes, my example code uses a compile time branch. My example code results in the exact same code as your render mode, but it is simpler and keeps the logic in the GDShader |
Does the Godot shader compiler fold |
`render_mode use_radiance_as_background;` will make the sky render its background using the radiance map that is generated for reflections. This is an optimization that makes the sky rendering faster, especially on low-end GPUs limited by their fragment shading rate (which is common on mobile). The benefit is especially noticeable on demanding sky shaders, as they will skip all demanding computations for rendering the background. The downside is that the background's resolution will depend on the radiance map's size configured in the Environment properties. Its update rate also depends on the chosen update mode, with the real-time update mode allowing for real-time updates at the cost of a fixed 256×256 resolution.
Not the Godot shader compiler. But the shader compiler will. The docs also include an example of how to do this https://docs.godotengine.org/en/latest/tutorials/shaders/shader_reference/sky_shader.html |
9b77400 to
f5908f8
Compare
|
I've pushed a second commit that switches to a shader-level toggle instead of a render mode. It also reorganizes code a bit to improve its formatting when converting it to a custom shader. However, there are 2 issues:
|
The shader compiler has code to handle this. It might only trigger in scene shaders though. If so, this is a pre-existing bug and should be fixed. The relevant code is here: godot/servers/rendering/shader_compiler.cpp Line 1339 in b1b873a
Instead of just triggering for |
I've pushed a third commit that aims to address this, but despite the line of code in question being reached (as evidenced by the print), it's not having any effect. |
This isn't in the correct place. It needs to be in the same location as the code I linked. The code you wrote is replacing The code needs to be in the location where the godot/servers/rendering/shader_compiler.cpp Lines 1338 to 1340 in b1b873a
You can create a local variable godot/servers/rendering/shader_compiler.cpp Lines 1152 to 1155 in b1b873a
Then here, before the if statement you can add your own check for RADIANCE the same as what you did in this PR: godot/servers/rendering/shader_compiler.cpp Lines 1248 to 1250 in b1b873a
|
render_mode use_radiance_as_background;will make the sky render its background using the radiance map that is generated for reflections. This is an optimization that makes the sky rendering faster, especially on low-end GPUs limited by their fragment shading rate (which is common on mobile). The benefit is especially noticeable on demanding sky shaders, as they will skip all demanding computations for rendering the background.The downside is that the background's resolution will depend on the radiance map's size configured in the Environment properties. Its update rate also depends on the chosen update mode, with the real-time update mode allowing for real-time updates at the cost of a fixed 256×256 resolution.
Testing project: test_radiance_as_background.zip
Preview
Benchmark
PC specifications
NVIDIA
Software rendering on CPU (Lavapipe)
TODO
SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP(along with other samplers used in the same shader) aren't defined in GLES3 (they are not present anywhere else indrivers/gles3/). See also my PR comment in Document sky shader half/quarter-res builtins not being available in Compatibility godot-docs#10905 which is tangentially related.mobilefeature tag override for performance reasons.