PDA

View Full Version : How can I convert a 3D model to a depth map?



prerna1
07-12-2013, 06:59 AM
What I am trying to do is perhaps similar to generating a Z-buffer representation (https://en.wikipedia.org/wiki/Z-buffering). However, how do I do this?
I can use glReadPixels(...) to get the z-depth data, however, how do I render this z-depth data into a depth image?

GClements
07-12-2013, 12:26 PM
I can use glReadPixels(...) to get the z-depth data, however, how do I render this z-depth data into a depth image?
With glTexImage2D() or (if you're writing into an existing texture) glTexSubImage2D(). Or you could skip the glReadPixels() step altogether and use glCopyTexImage2D() or glCopyTexSubImage2D() to copy data directly from the depth buffer to a texture.

marcClintDion
07-18-2013, 04:46 PM
I think what you are looking for is the first stage of a shadow mapping setup.

(i) Generate an FBO that is setup for depth rendering only.
(ii) In the render loop, activate the depth FBO and render the models. This will create the depth map.
(iii) Deactivate the FBO.
(v) Apply the texture generated by the FBO to a screen aligned quad. This will display the depth map.