- Home /
Rendering Depth Texture
Hello, I'm trying to render a depth texture for my scene with this code:
sampler2D _MainTex;
sampler2D _CameraDepthNormalsTexture;
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
float4 NormalDepth;
DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture,i.uv),NormalDepth.w,NormalDepth.xyz);
col.rgb = NormalDepth.w;
return col;
}
ENDCG
and then here is the camera's script:
using UnityEngine;
[ExecuteInEditMode]
public class PPCamera : MonoBehaviour
{
public Material postProcessingMat;
void OnRenderImage(RenderTexture source, RenderTexture dest){
Camera cam = GetComponent<Camera>();
if(cam != null){
cam.depthTextureMode = DepthTextureMode.DepthNormals;
}
Graphics.Blit(source,dest,postProcessingMat);
}
}
Though I have depth in my scene, the objects are rendering solely as completely black or completely white. I'm using unity 2021.1.7f1, does anyone know how to fix?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613034722im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Shaders - offset texture coordinates by a single pixel 2 Answers
Lines on 360 image? 1 Answer