Skip to content

Instantly share code, notes, and snippets.

@shole
Created April 18, 2018 23:36
Show Gist options
  • Save shole/06976f27ce9d965be16d25587a3a4a75 to your computer and use it in GitHub Desktop.
Save shole/06976f27ce9d965be16d25587a3a4a75 to your computer and use it in GitHub Desktop.
Shader "Hidden/CopyDepth2Color" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
}
SubShader {
Cull Off ZWrite On ZTest Always
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment CopyDepthBufferFragmentShader
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D_float _MainTex;
float CopyDepthBufferFragmentShader(v2f i) : COLOR {
float depth = SAMPLE_DEPTH_TEXTURE(_MainTex, i.uv);
depth = Linear01Depth(depth);
return depth;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment