Advertisement
romanilyin

Shader "SGG/Special/DepthPaste"

Oct 6th, 2022
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | Gaming | 0 0
  1. Shader "SGG/Special/DepthPaste"
  2. {
  3. Properties{
  4. _MainCamDepthTex("Texture", 2D) = "white" {}
  5. [HideInInspector] _MainTex("Texture", 2D) = "white" {}
  6. }
  7.  
  8. SubShader{
  9. // markers that specify that we don't need culling
  10. // or comparing/writing to the depth buffer
  11. Cull Off
  12. ZWrite Off
  13. ZTest Always
  14.  
  15. Pass{
  16. CGPROGRAM
  17. //include useful shader functions
  18. #include "UnityCG.cginc"
  19.  
  20. //define vertex and fragment shader
  21. #pragma vertex vert
  22. #pragma fragment frag
  23.  
  24. sampler2D _MainTex;
  25. sampler2D _MainCamDepthTex;
  26. sampler2D _CameraDepthTexture;
  27.  
  28.  
  29. struct appdata {
  30. float4 vertex : POSITION;
  31. float2 uv : TEXCOORD0;
  32. };
  33.  
  34. struct v2f {
  35. float4 position : SV_POSITION;
  36. float2 uv : TEXCOORD0;
  37. };
  38.  
  39. v2f vert(appdata v) {
  40. v2f o;
  41. o.position = UnityObjectToClipPos(v.vertex);
  42. o.uv = v.uv;
  43. return o;
  44. }
  45.  
  46. fixed4 frag(v2f i) : SV_TARGET{
  47. fixed4 col = tex2D(_MainTex, i.uv);
  48. float depth0 = tex2D(_MainCamDepthTex, i.uv).r;
  49. float depth = tex2D(_CameraDepthTexture, i.uv).r;
  50. if (depth < depth0)
  51. col.a = 0;
  52. return col;
  53. }
  54. ENDCG
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement