Shader "Hidden/OcclusionReplacementShader" { SubShader { Tags { "RenderType"="Opaque" } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; }; struct v2f { float4 vertex : SV_POSITION; }; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); return o; } fixed4 frag (v2f i) : SV_Target { return half4(0,0,0,1); } ENDCG } } SubShader { Tags { "RenderType"="CullHighlightOne" } ZWrite Off Cull Off Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" uniform sampler2D _CameraDepthTexture; sampler2D _MainTex; float4 _MainTex_ST; struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float4 vertex : SV_POSITION; float2 uv : TEXCOORD0; float4 screenPos : TEXCOORD1; float2 depth : TEXCOORD2; float dist : TEXCOORD3; }; v2f vert (appdata v) { v2f o; o.vertex = mul(UNITY_MATRIX_MV, v.vertex); //o.depth = o.vertex.z; o.vertex = mul(UNITY_MATRIX_P, o.vertex); //UNITY_TRANSFER_DEPTH(o.depth); //o.screenPos = ComputeScreenPos(o.vertex); o.dist = distance(_WorldSpaceCameraPos, mul(unity_ObjectToWorld, v.vertex) ); o.uv = TRANSFORM_TEX(v.uv, _MainTex); return o; } half4 frag (v2f i) : COLOR { //float depth = saturate(-0.005f * i.depth);//(i.depth) / _ProjectionParams.z; float depth = i.dist/_ProjectionParams.z;//SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.screenPos)).r; //depth = Linear01Depth(depth); //depth = Linear01Depth(depth)* _ProjectionParams.z; return half4(1-depth,0,depth,1-depth); //UNITY_OUTPUT_DEPTH(i.depth); } ENDCG } } /* SubShader { Tags { "RenderType"="CullHighlightTwo" } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" sampler2D _CameraDepthTexture; sampler2D _MainTex; float4 _MainTex_ST; struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float4 vertex : SV_POSITION; float2 uv : TEXCOORD0; }; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); return o; } fixed4 frag (v2f i) : SV_Target { float depth = tex2D(_CameraDepthTexture,i.uv).r; depth = Linear01Depth(depth)* _ProjectionParams.z; return half4(0,1,0,depth); } ENDCG } } SubShader { Tags { "RenderType"="CullHighlightThree" } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" sampler2D _CameraDepthTexture; sampler2D _MainTex; float4 _MainTex_ST; struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float4 vertex : SV_POSITION; float2 uv : TEXCOORD0; }; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); return o; } fixed4 frag (v2f i) : SV_Target { float depth = tex2D(_CameraDepthTexture,i.uv).r; depth = Linear01Depth(depth)* _ProjectionParams.z; return half4(0,0,1,depth); } ENDCG } } */ }