1

So I'm trying to render the depth map of a scene using three.js

An example can be found here: http://threejs.org/docs/#Reference/Materials/MeshDepthMaterial

The depth map looks good when the scene is setup carefully, for example:

camera.position.z = 30;
camera.near = 0.1;
camera.far  = 50;
object.position.z = 0;

However, if the camera is setup in some other ways, for example:

camera.position.z = 600;
camera.near = 550;
camera.far  = 650;
object.position.z = 0;

In the second example, the depth resolution is all taken up by the depth range from -45 to -50 in the world coordinate system. This means for -50 < objects.position.z < -45, you can still see grayscale values in the depth map. Anything that has depth ranging from -45 to 50 will appear completely white in the depth map...

Ideally, I would like to see depth values uniformly distributed in the -50 to 50 range.

Is there a way to get the depth map I want? Is there a way to increase the precision of depth map?

Eventually, I would like to save the Depth Map of the three.js scene as a .png image on to local disk for some analysis. Methods that don't use three.js are also welcome. Thanks.

lakex24
  • 51
  • 1
  • 8
  • There is a good explanation of the depth buffer resolution here: http://outerra.blogspot.com/2012/11/maximizing-depth-buffer-range-and.html. Also take a look at one of the threejs example about a logarithmic depth buffer at: http://threejs.org/examples/#webgl_camera_logarithmicdepthbuffer – gaitat Jan 29 '15 at 13:57
  • not an answer but might be helpful: http://stackoverflow.com/questions/21080619/three-js-webgl-large-spheres-appear-broken-at-intersection/21106656#21106656 – gman Jan 30 '15 at 09:20
  • Thank you for the suggestions. I've found a way to solve this problem. – lakex24 Jan 30 '15 at 21:58

1 Answers1

0

Together with MeshDepthMaterial and the logarithmicDepthBuffer flag, I can get pretty nice looking depth map with the weird camera setup.

var renderer = new THREE.WebGLRenderer({logarithmicDepthBuffer: true });
lakex24
  • 51
  • 1
  • 8