-
-
Notifications
You must be signed in to change notification settings - Fork 67
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 depth-writing shaders to work with shadow maps #1942
Comments
See also #1843 (comment). |
In 3.2.3-stable (at least), depth-writing shaders already write to shadow maps (and to any depth pre-pass, in general) if they use alpha-cutoff or I would suggest checking if depth is written to, in rasterizer_scene_gles3.cpp, in the same if statement where For now, a work around would be to just do something like "if(false) discard;" in the shader, to trigger Note: there would still be some problems with the shadow maps, with bias or with dual paraboloid maps, but that would require further thought. See also #974 (comment) |
The shader shown in the screenshot uses |
Ran into this issue with a depth writing shader. The resulting (carved out) surface receives some shadow, but it corresponds to the original mesh (a cube), not to the 3D surface defined by the DEPTH written by the shader. It drops proper shadow according to its carved out shape. It cannot shadow itself. It would be nice to have a way to fix the shadows in this case, even at a performance cost. |
I think the fragment shader may just allow overwriting the VERTEX variable, so it can correct the view space position according to the DEPTH applied. In the shader code it should override |
Describe the project you are working on
A node rendering SDF models with raymarching: https://github.com/Zylann/godot_sdf_blender
Describe the problem or limitation you are having in your project
The node cannot cast shadows, and cannot receive shadows.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
In my use case, the node uses a simple geometry primitive (such as a quad, a box, or a sphere). The goal of that primitive is solely to render pixels in a certain location on screen. It might be displaced to be fullscreen (like post-processing effects do by assigning
POSITION
), or only part of the screen when a box is chosen.But unlike post-processing effects,
DEPTH
is written into, as well asNORMAL
,ALBEDO
and other various pixel properties, anddiscard
is used to cut out the edges of the model. This allows the result to fit nicely in a scene with regular meshes.The AABB is also altered to match the real extents of the object.
Because the shader writes to
DEPTH
, it provides the information for shadowmaps to also work on it. Currently that doesn't seem to happen.I tried using a cube without displacing it and the resulting shadow was following the cube and not the real depths.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Take
DEPTH
-writing shaders into account?I'm not expert in that area, but from what I understand of shadow maps, they render depth from the point of view of the light, and the result is used by the regular render pass to darken occluded pixels. So it sounds like it should be possible.
If it incurs at the expense of other "classic" shaders, maybe add a
render_mode
to treat the shader differently? Or have ashadow()
function to allow customizing the shadow pass?This should ideally not take effect on shaders that actually just do post-processing, because while those displace their quad to be fullscreen, it doesnt mean such quad should put everything in shadow by being right in front of the frustrum. Perhaps it would just work as long as they dont write to
DEPTH
.If this enhancement will not be used often, can it be worked around with a few lines of script?
No. Unless you re-implement a shadow mapping system on top of the
VisualServer
API using viewports, it's going to be terribly inefficient, hard to maintain and share as a plugin.Is there a reason why this should be core and not an add-on in the asset library?
It targets a part of the rendering engine.
NB: this is an area I only started experimenting, so maybe Godot actually supports this and I got something wrong somewhere. If that's the case this proposal could be closed, but at the moment it's not certain yet ;)
The text was updated successfully, but these errors were encountered: