Hello,
I want to render the depth buffer of my scene (as a grayscale texture).
How can I access to camera Depth ?
Do I need to do apply particular shader at all meshes in my scene?
Thanks.
Kcm.
Hello,
I want to render the depth buffer of my scene (as a grayscale texture).
How can I access to camera Depth ?
Do I need to do apply particular shader at all meshes in my scene?
Thanks.
Kcm.
Check out the Shader Replacement Demo. If you take a look at the Edge Detection scene, look at the camera and the scripts/shaders attached to it, mainly the “RenderNormalsAndDepth” shader. This shader renders both normals and depth information of the scene into a render target, normals into the RGB channel, and depth information into the A channel. You can then access the pixels of the texture either through a script or through another shader.
You don’t need to apply a particular shader to all the objects as this is done with the “Camera.SetReplacementShader()” function. Note however that this shader will not work with any shaders that use transparency without some editing. It will only render objects of RenderType Opaque, mainly due to the fact that transparent shaders generally write to the depth buffer. You can read more about replacement shaders here.
Note that you will need Unity Pro to be able to use the render targets for this shader.