ShaderMaterial depth information lost

Can anyone help me understand why depth information is lost for the ShaderMaterial when logarithmicDepthBuffer is true and the camera’s near plane is set to a small value <= 0.1 for the ShaderMaterial? Additionally, what steps can be taken to address this issue?
Screenshot 2024-04-11 003806

I have no developer’s experience with logarithmic depth buffers, but most likely it requires some additional code in the shaders. This is, it is not just a flag that is turned on/off, while keeping the code intact.

The reason for thinking that more code is necessary is that there are vertex and fragment shaders chunks specific for logarithmic buffers. If such chunks exist, most likely they are used when the depth buffer is logarithmic.

My suggestion is to test some simple material (e.g. MeshBasicMaterial) and inspect the generated by Three.js shaders codes when the depth buffer is linear and when it is logarithmic. If there is any difference, then you also have to have similar difference in your code.


couldn’t sleep. Did some digging and found a direct solution. shaderMaterial: render-order with logarithmicDepthBuffer is wrong - #3 by berkaycirak

1 Like