Skip to content
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

How is the zbuffer gradient computed? Why is it non-zero if it's just pulled from OpenGL? #1906

Open
MartensCedric opened this issue Oct 24, 2024 · 1 comment

Comments

@MartensCedric
Copy link

Unexpected behavior

Looking at DIB-R: https://research.nvidia.com/labs/toronto-ai/DIB-R/files/diff_shader.pdf, which this library seems to have a similar implementation, when calculating the derivative of pixel color with respect to vertex position, the derivatives of barycentric coordinates are computed to get smooth gradients (for foreground pixels). This library appears to be doing something similar, but does not do this for the depth calculation.

In the case that I'm optimizing only a depth map (I don't care about texture, and shading), I saw that the HardDepthShader just takes the zbuffer from OpenGL (essentially from the shader). It does not compute the depth from the barycentric coordinates of a face (it could because the depth of each vertex can be known from the camera parameters).

This means that the gradient of the image color with respect to vertex position seems incorrect, or at least computed differently. I expected the derivative dDepth/dVertexPos to always be 0. However, I have to admit that I am not getting this in my code, which is unexpected. I would like to know whether or not the depthmap gradient is computed like I understand.

@bottler
Copy link
Contributor

bottler commented Oct 29, 2024

Can you share some code? How do you initialize the rasterizer and shader?

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

No branches or pull requests

2 participants