Shader "Hidden/Off-Screen Particles Replace" { Category { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } AlphaTest Greater .01 Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } CGINCLUDE #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex:POSITION; float4 texcoord:TEXCOORD0; float4 color:COLOR; }; struct v2f { float4 pos:POSITION; float3 uvz:TEXCOORD0; float3 depth:TEXCOORD1; float4 color:COLOR; }; uniform sampler2D _MainTex : register(s0); uniform samplerRECT _CameraDepthTexture; uniform float4 _CameraDepthTexture_TexelSize, _CameraDepthTexture_Size; uniform float4 _TintColor; v2f vert(appdata v) { v2f o; o.pos = mul(glstate.matrix.mvp, v.vertex); o.color = v.color; o.uvz.xy = MultiplyUV(glstate.matrix.texture[0], v.texcoord); COMPUTE_EYEDEPTH(o.uvz.z); float3x4 mat = float3x4 ( 0.5, 0, 0, 0.5, 0, 0.5, 0, 0.5, 0, 0, 0, 1 ); o.depth = mul(mat, o.pos); #ifdef SHADER_API_OPENGL o.depth.xy *= _CameraDepthTexture_Size.xy; #endif return o; } half4 frag(v2f i):COLOR { half4 texCol = tex2D(_MainTex, i.uvz.xy); half4 outCol = i.color * _TintColor * texCol * 2; #ifdef SHADER_API_D3D9 // Directx is off by half a texel // so we need to do the projection seperately i.depth.xy = i.depth.xy/i.depth.z; // then offset the uvs by 0.5*TexelSize i.depth.xy += 0.5 * _CameraDepthTexture_TexelSize.xy; // we also need to flip the y if in directx i.depth.y = 1 - i.depth.y + _CameraDepthTexture_TexelSize.y; float z = texRECT(_CameraDepthTexture, i.depth.xy).r; #else float z = texRECTproj(_CameraDepthTexture, i.depth).r; #endif float sceneDepth = DECODE_EYEDEPTH(z); float myDepth = i.uvz.z; if(sceneDepth < myDepth) discard; return outCol; } ENDCG SubShader { Pass { Blend SrcAlpha OneMinusSrcAlpha ColorMask RGB CGPROGRAM ENDCG } Pass { Blend Zero OneMinusSrcAlpha ColorMask A CGPROGRAM ENDCG } } } }