- Home /
How does _CameraDepthTexture work with Cameras that are using a RenderTexture?
I have a scene with a waterfall which uses the SimpleWater4 shaders and scripts. I want to reflect the waterfall in the lake below, which uses the same shaders. The problem is that the waterfall never ends up in the RenderTexture used by the lake for its planar reflection. The shader "FX/SimpleWater" reads the camera's depth texture for edge blending the waterfall in line 189:
half depth = UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.screenPos)));
However, when the waterfall is rendered into the reflection helper cam's RenderTexture, depth is always 0. The Camera with the RenderTexture seems to have no _CameraDepthTexture (or it hasn't been created in a separate path yet?), although it is created with a depth buffer with
RenderTexture rt = new RenderTexture(Mathf.FloorToInt(cam.pixelWidth*0.5F), Mathf.FloorToInt(cam.pixelHeight*0.5F), 24);
in PlanarReflection.cs line 60.
Any help would be much appreciated!
Having the same problem doing anything with depth in the reflections. Do you know any way to switch shader properties for the reflection pass? I could at least change my shader when rendered into the reflections.