1 year ago
#332453
Lilla
Increased precision when rendering depth map
In OpenGL, I'm trying to render a depth map that doesn't loose precision with fa away objects. Do you know of any way I can accomplish this task?
My approach so far: I tried the "reverse depth" trick (here for example).
- I modified the perspective projection matrix in such a way that the near and far values are mapped as
[-n, -f] -> [1, 0]
instead of the usual[-n, -f] -> [-1, 1]
- I rendered the depth map to a framebuffer, using in particular the 32F depth component
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, conf::SCR_WIDTH, conf::SCR_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL)
- plus I tackled the need for clipping to
[1,0]
usingglClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE)
(documentation here) - lastly, after rendering the depth map to the framebuffer, I take the depth values and map them back to eye coordinates, divide by the far plane value, and use this value as a color
However I couldn't notice any gain in precision. Am I doing anything wrong? Is there any better approach?
Example on a close by cube: you can really see the discrete transitions, I would like a smoother output
opengl
depth-buffer
0 Answers
Your Answer