Skip to content

Set logarithmicDepthBuffer: true bring some error #30981

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

Open
MrYang614 opened this issue Apr 23, 2025 · 10 comments
Open

Set logarithmicDepthBuffer: true bring some error #30981

MrYang614 opened this issue Apr 23, 2025 · 10 comments

Comments

@MrYang614
Copy link

Description

see example

Reproduction steps

Set logarithmicDepthBuffer: true

Code

line 265

	renderer = new THREE.WebGPURenderer({ antialias: true, logarithmicDepthBuffer: true });

Live example

example

Screenshots

Image

Version

r175

Device

No response

Browser

No response

OS

No response

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 23, 2025

I can reproduce an issue with logarithmic depth buffer in the example. However, the glitch looks different on my device (mac mini).

Image

There is this kind of imaginary plane that is position parallel towards the camera where rain drops move along. You can see this plane quite clearly when looking at Suzanne.

There are no errors or warnings in the browser console and both the WebGL and WebGPU backend are affected.

@Spiri0
Copy link
Contributor

Spiri0 commented Apr 23, 2025

@MrYang614 Here I have a small codePen that nicely illustrates the logarithmicDepthBuffer.

https://codepen.io/Spiri0/pen/vYqpRga?editors=0010

The reason why this doesn't work in the example is because the depthNode is not served.

Import this in the example:

import { viewZToLogarithmicDepth, depth, cameraNear, cameraFar } from "three/tsl";

and for the rain implement this:

rainMaterial.depthNode = viewZToLogarithmicDepth( depth.negate(), cameraNear, cameraFar );
rippleMaterial.depthNode = viewZToLogarithmicDepth( depth.negate(), cameraNear, cameraFar );

Then it looks fine:
Image

In the example it is MeshBasicNodeMaterials, so you have to take care of everything yourself with them.
So if you enable the logarithmicDepthBuffer, you also need to serve the depthNode.
I hope I could help you with this

@Mugen87 I suspect the reason there's no error in the console is that everything is functionally correct. It's just using a linear depth if the depth node isn't being served.

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 23, 2025

It's just using a linear depth if the depth node isn't being served.

I just wonder if the engine should update the "default" depth node automatically depending on whether linear or logarithmic depth is used. The average user won't properly figure out to assign viewZToLogarithmicDepth( depth.negate(), cameraNear, cameraFar ); to every depthNode property of all node material in the scene.

@Spiri0
Copy link
Contributor

Spiri0 commented Apr 23, 2025

I just wonder if the engine should update the "default" depth node automatically depending on whether linear or logarithmic depth is used.

Please not with the MeshBasicNodeMaterial. I'm glad that threejs gives me all the options with the MeshBasicNodeMaterial. And in my case, pretty much everything is a special case where well-intentioned build-ins often would cause problems.
As far as I know, all higher materials do this by automatically setting the depthNode like in the logarithmicDepthBuffer example. Build-ins that make life easier for users are a great thing. I use a lot of them by myself. But since it's not possible to cover every possible scenario, it's good that threejs gives you free rein with the MeshBasicNodeMaterial. I would rather leave the MeshBasicNodeMaterial basic.

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 23, 2025

The basic term only refers to the fact that it's unlit and thus implements a basic shader.

As far as I know, all higher materials do this by automatically setting the depthNode like in the logarithmicDepthBuffer example.

I'm not sure I understand but do you say MeshBasicNodeMaterial does not belong to these "higher" materials? Regarding depth, it should definitely behave similar to MeshPhongNodeMaterial and MeshStandardNodeMaterial.

@Spiri0
Copy link
Contributor

Spiri0 commented Apr 23, 2025

The basic term only refers to the fact that it's unlit and thus implements a basic shader.

Ah, you mean that as soon as I pass my own shader to the depthNode, the internal assignment, whatever it may be, is overwritten? Well then I don't have any pain with it.

P.S. Yes, I admit I had always perceived the MeshBasicNodeMaterial as a material that stands out from the others through minimalism

@MrYang614
Copy link
Author

@Spiri0 @Mugen87 thanks . I need to learn more , I meet these problem without log err , I can't find the problem myself .

@MrYang614
Copy link
Author

@Spiri0 @Mugen87 I can not still solve this problem perfectly , I set

rainMaterial.depthNode = viewZToLogarithmicDepth( depth.negate(), cameraNear, cameraFar );

It bring another depth problem

Image

I reset logarithmicDepthBuffer:false

@Spiri0
Copy link
Contributor

Spiri0 commented Apr 30, 2025

rainMaterial.depthNode = viewZToLogarithmicDepth( depth.negate(), cameraNear, cameraFar );

The same applies to the ripple material

rippleMaterial.depthNode = viewZToLogarithmicDepth( depth.negate(), cameraNear, cameraFar );

@MrYang614
Copy link
Author

rainMaterial.depthNode = viewZToLogarithmicDepth( depth.negate(), cameraNear, cameraFar );

The same applies to the ripple material

rippleMaterial.depthNode = viewZToLogarithmicDepth( depth.negate(), cameraNear, cameraFar );

I have set this too , depth problem between collisionBox and rain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants