Skip to content

Allow users to provide a custom shadow shader #4443

@Ansraer

Description

@Ansraer

Describe the project you are working on

3D foliage rendering

Describe the problem or limitation you are having in your project

When rendering a scene godot does 5 passes of it: One pre depth pass, three shadow passes, and finally a color pass.
With Godot's default PBR shader the depth and shadow pass use a pretty bare bones fragment shader since only the depth output is wanted.

However, for custom shaders this is not the case. While Godot still creates a shadow pipeline for the custom shader it uses the exact same fragment code as the color pipeline. This means that the depth and shadow passes of custom shaders calculate a lot of unnecessary output, wasting valuable time.

Some tests with Renderdoc have shown that the depth pass for a very basic noise based material with alpha scissors can take up to 60 microseconds. By manually trimming the shader down to only what is necessary for depth rendering (the alpha scissors) I managed to cut down the execution time to 20 microseconds.

With more complex custom shaders the performance loss would be even greater.

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

What I want is the ability to provide a custom shadow shader. As far as I can tell Godot already has code for using a different shader for shadow and depth pass:

https://github.com/godotengine/godot/blob/e80aedbf20a7846a0e21dc8623823eef10b2e676/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp#L2669-L2683

All that would be needed is a way to expose this to the user.

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

Similar to the next pass property users would be able to set another shader as a shadow material. With some modifications to the code linked above it should be possible to use that material for shadow rendering.

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

Not that I am aware of. I suppose you could turn off shadows and create a duplicate that only renders shadows with a different material? But that would come with its own problems.

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

rendering is core.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions