-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Allow users to provide a custom shadow shader #4443
Comments
We have currently a section for shadow meshes in inspector. Those meshes have a material slot which could be used for this purpose. Currently it is a little bit counter intuitive, because overriding this does nothing. |
@wojtekpil Maybe I am blind, but where are shadow meshes exposed to the editor in godot 4.0? Afaik Godot creates shadow meshes automatically on import. Also, based on my understanding of the code, godot uses a shared material for those shadow meshes. My idea was to add a field below next pass like in the mockup below: |
The problem with this shadow mesh is that it is only used as long as you don't use a custom shader and edit anything vertex, position or alpha related. If you look at the code I linked in my initial post you can see how it isn't used once you edit one of those. |
We discussed this at the proposals meeting today, the consensus was that we should instead introduce an From a user perspective it would allow users to write things like:
|
Ah damn it, I keep missing the meetings. |
I wouldn't worry about exposing In the GLES3 backend, this can be done with a shader varient (which is roughly equivalent to a specialization constant) |
Oh, I think you misunderstood what I meant @clayjohn. The reason why I proposed the second (not const) bool was so that people could manipulate only the shadows without affecting the depth pass. While not useful for my particular usecase I could totally see how someone working on a horror game might want to modify only the shadows without changing the depth or color pass. EDIT: Now I really want to make a horror game with shadows that try to grasp the player somehow. Just imagine seeing a completely unassuming tree, and then you look down and notice how the shadows of its branches slowly creep towards you... |
+1 that would be a super useful feature and just increases engine flexibility. |
That's a plus one for being able to manipulate the shadow pass apart from the depth pre-pass? Or a plus one to the proposal in general? If the former, can you please elaborate? |
My thinking at the time was the ability to affect how shadows would be drawn vs in the depth pass as I thought that having them tied could lead to issues. Upon rereading, I think you're right that Naming this My appologies, I was up rather late. |
Nit on the name: |
+1 for being able to customize shadows. I currently have a need overide the shadows influence on color, and id like to be able so apply my own smoothing/blur |
This may already be feasible; see the comments in godotengine/godot#60360. |
Just tested with alpha16, setting the The idea of having a shadow mess with its own material (which can be a custom shader) is good. But the interface needs to support using the same mesh, but with different material as well, in case the mesh does not need to be simplified for shadow rendering. I suggest adding two new properties to
I also suggest removing |
I believe the IN_SHADOW_PASS flag would be very helpful. I'm coming from Unreal which has the "Shadow Pass Switch" node in the visual shader editor, and it makes it very easy to do things like have an x-ray effect into a building where shadows from walls and ceilings are still applied to the inside. |
I found a somewhat hacky workaround to detect being in the shadow pass which allowed me to test my x-ray method (and things do work out as desired). I say it's hacky because it won't work properly if the camera is ever in same position as one of the lights. In the shadow passes, Godot sets the "camera_position_world" built-in to the position of the the light, so I did the following in my project:
Having IN_SHADOW_PASS flag (plus visual shader node switch equivalent) would be ideal though since I wouldn't have to worry about the camera and light positions overlapping (and presumably the shader compiler could possibly optimize things away in the shadow vs non-shadow case). |
Well, I just discovered another work around that relies on the fact that near_z is set to 0 for the shadow passes. This means that PROJECTION_MATRIX[3][2] will be zero in shadow passes, so you can do the following in the shader code to detect shadow passes:
UPDATE: |
The ability to know if we are in shadow pass should be nice.
|
This is surely due to reverse Z being implemented in 4.3. You should be able to adjust the check to account for this. |
Thanks Calinou, i have read the new at time but don't realize it was important for me ! |
This trick does work in 4.3 Shader. But in VisualShader, it seems that there is no way to access PROJECTION_MATRIX[2][3]. |
Doesn't work for me. Should it work for all types of light? I'm trying to disable distance fade for shadows. |
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.
The text was updated successfully, but these errors were encountered: