-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Logarithmic depth buffer gives no shadows #7815
Comments
Could you create a jsfiddle? |
I added a jsfiddle with a moving directional light. When I run it i see a shadow when the light is furthest away, and the shadow disappears as the light moves closer to the objects, and then reappear again as the camera moves away. The problem depends on the values of |
Actually, Logarithmic depth buffer can be made to give shadows for certain parameter settings. |
upvoting this one, it's still present and very annoying... |
Is there any update on this? I don't manage to find any I have a setup where I dynamically change the shadow camera box to fit it tightly around the scene extend to optimise shadows and it would be great if this would work together with logarithmic depth buffer. |
@jbaicoianu do you know if this is doable? |
I have a similar situation to @sandromartis. Being able to use logarithmic depth buffer would be a great help as scenes being viewed can be in any number of incoming unit systems and scales. Here are a few simple jsfiddles of the same scene: Does it have to do with the material shader chunks? I've tried MeshStandardMaterial, MeshPhongMaterial, and MeshLambertMaterial on the objects to no avail. Looking a bit deeper, I see that there are some ShadeChunks for logarithmic depth buffering, and it does seem that they are being included at least in MeshStandard(v)(f), MeshLambert(v)(f), and MeshPhong(v)(f): |
Changing the |
Hi, sorry I've been travelling and haven't had a chance to look at this. I'm not very familiar with the shadow map code but I believe either it would need to account for the altered gl_Position.z value when calculating the shadow, or the shadow map vertex shaderchunk would need to be moved before the logdepthbuf shaderchunk. |
Hello. I made a quick test by naively changing the position of
In meshphong_vert.glsl, meshlambert_vert.glsl, and meshphysical_vert.glsl. These updates led to the same behavior and no forseeable difference. I do get the following in the console, but I'm not sure if it is related (Windows 10, Firefox Dev 50.0a2 (2016-09-01)):
This is building |
Any other insight on this? Not sure where the problem lies or what would be necessary to attempt to fix this. |
I spoke with MrDoob about this yesterday actually. I really need the help of someone who understands how the shadowmap code works to fix this. The logarithmic depth buffer code only changes one value, gl_Position.z - but I don't understand how that is conflicting with what the shadowmap code is doing. The original implementation for this was based on an article by Brano Kemen - I'll ping him on twitter and ask if he knows of any reasons why it would cause problems. |
Dropping some URLs in here because all the information about how this particular logarithmic depth buffer implementation works is spread out over a series of blog posts. One of them apparently contains information about the shadow problem, and all are of interest to anyone who wants to know how it works and why/when they should use it http://outerra.blogspot.com/2009/08/logarithmic-z-buffer.html |
Is this still a thing? Shadow for DirectionalLight with logarithmicDepthBuffer doesn't work. |
@Fyrestar Yes, this is still a thing. |
I wish I knew enough about shadows to fix this, but yes, as it is now shadows don't work properly with logarithmic depth buffer. I asked the original author of the technique who said that this topic was covered in the articles, but I couldn't find any reference, and I don't know enough about Three's shadow implementation to know how to solve it. I would be more than happy to work with whoever might have the knowledge of the shadow code to figure out what needs changing to make this work. |
Oh!? Pull Request! 😮 |
I guess the depth shader should get a kinda Another thing i noticed, but this is not related to this issue, is very pixelated edges for such meshes which cast an receive shadows. Wouldn't it help to remove the artifacts by using the camera-normal slope to early reject those faces in the depth shader for this purpose? |
Well, yes. That is the issue. But the solution you are proposing is to remove logarithmicDepthBuffer from the depth map calculation, instead of adding it to the shadow calculation. That will work, but... ...it begs the question: Why are you using logarithmicDepthBuffer in the first place? |
Why are you using logarithmicDepthBuffer? Can you provide a simple, live example to demonstrate why it is needed in your case? Your shadow frustum should be tight around your scene for quality shadows. Are your adapting the shadow frustum accordingly? |
The scene in the image is just for testing purposes, the actual world has real scale planets rendering thousands of kilometers and also close intersecting surfaces like water. Depth fighting was a big issue before, even for decent distances. The shadow frustum is centered around the camera, basically it's a cube since it's a orthographic camera, i can decrease the distance, this increases the quality but shortens the distance. Using multiple shadows similar to geoclipping and fade them seems to be the only option for this case. |
I expect your problems are self-imposed, then -- not three.js issues. There are limits to the precision of your machine.
For quality shadows, the shadow frustum should be tight around the rendered scene. |
This is the exact purpose of the logarithmic DepthBuffer, in fact the logarithmic DepthBuffer code is adapted from Outerra, you asked why it's needed in my case. As i said, the frustum couldn't be any closer matching. |
I believe the following statements are correct as of three.js r.87: For spot lights and directional lights: Shadows work correctly with logarithmic depth buffer when the Shadows do not work correctly with logarithmic depth buffer when the For point lights, shadows work correctly in all cases. |
see #17525 (comment) |
https://github.com/mrdoob/three.js/blob/r73/examples/webgl_shadowmap.html#L136
change to
With that change, there are no longer any shadows.
Tested with r73 and dev as of today on Chrome Version 47.0.2526.80 (64-bit) and Firefox 43.0, both on Mac.
jsfiddle: http://jsfiddle.net/xrd3gcpy/
The text was updated successfully, but these errors were encountered: