- Home /
Desaturating based on camera depth in an image effect?
I'm trying to desaturate objects based on their distance from the camera, but I'm having serious trouble getting depth information into my post-processing shader. I've tried using a texture parameter on the shader (_DepthTex) that I assign to every frame from the image effect script:
RenderTexture depth = RenderTexture.GetTemporary (source.width, source.height, 24, RenderTextureFormat.Depth);
desaturateMaterial.SetTexture("_DepthTex", depth);
Which seems to just return white, and I've tried using the Unity depth macros (_CameraDepthTexture, UNITY_OUTPUT_DEPTH), which only seem to return black.
Thanks for your help!
How are you rendering the camera into the depth texture?
I've tried just blitting it (Graphics.Blit(source, depth)) before passing it into the shader, and I've also tried getting it directly from the Camera using DepthTexture$$anonymous$$ode.Depth and _CameraDepthTexture.