Advertisement
Guest User

Untitled

a guest
Jan 7th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "_Test/Transparent With Depth Mask"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Main Texture", 2D) = "white" {}
  6.         _DepthMask ("Depth Mask", 2D) = "white" {}
  7.     }
  8.  
  9.     SubShader
  10.     {
  11.         Tags { "Queue" = "Transparent-1" }
  12.         ZWrite Off
  13.  
  14.         Pass
  15.         {
  16.             Blend SrcAlpha OneMinusSrcAlpha    // alpha blending
  17.  
  18.             CGPROGRAM
  19.  
  20.             #pragma exclude_renderers flash gles ps3 xbox360
  21.             #pragma fragmentoption ARB_precision_hint_fastest
  22.             #pragma vertex vert
  23.             #pragma fragment frag
  24.  
  25.             #include "UnityCG.cginc"
  26.  
  27.  
  28.             // uniforms
  29.  
  30.             uniform sampler2D _MainTex;
  31.             uniform float4 _MainTex_ST;
  32.  
  33.  
  34.             // structs
  35.  
  36.             struct vertexInput
  37.             {
  38.                 float4 vertex : POSITION;        // position in object coordinates
  39.                 float4 texcoord : TEXCOORD0;    // 0th set of texture coordinates (UV)
  40.             };
  41.  
  42.             struct fragmentInput
  43.             {
  44.                 float4 pos : SV_POSITION;
  45.                 half2 uv : TEXCOORD0;
  46.             };
  47.  
  48.  
  49.             // functions
  50.  
  51.             fragmentInput vert(vertexInput i)
  52.             {
  53.                 fragmentInput o;
  54.  
  55.                 o.pos = mul(UNITY_MATRIX_MVP, i.vertex);
  56.                 o.uv = TRANSFORM_TEX(i.texcoord, _MainTex);
  57.  
  58.                 return o;
  59.             }
  60.  
  61.             half4 frag(fragmentInput i) : COLOR
  62.             {
  63.                 return tex2D(_MainTex, i.uv);
  64.             }
  65.  
  66.             ENDCG
  67.  
  68.         } // end pass
  69.  
  70.  
  71.         Pass
  72.         {
  73.             //Blend SrcAlpha OneMinusSrcAlpha    // alpha blending
  74.             Blend Zero One
  75.  
  76.             ZWrite On
  77.  
  78.             CGPROGRAM
  79.  
  80.             #pragma exclude_renderers flash gles ps3 xbox360
  81.             #pragma fragmentoption ARB_precision_hint_fastest
  82.             #pragma vertex vert
  83.             #pragma fragment frag
  84.  
  85.             #include "UnityCG.cginc"
  86.  
  87.  
  88.             // uniforms
  89.  
  90.             uniform sampler2D _DepthMask;
  91.             uniform float4 _DepthMask_ST;
  92.  
  93.  
  94.             // structs
  95.  
  96.             struct vertexInput
  97.             {
  98.                 float4 vertex : POSITION;        // position in object coordinates
  99.                 float4 texcoord : TEXCOORD0;    // 0th set of texture coordinates (UV)
  100.             };
  101.  
  102.             struct fragmentInput
  103.             {
  104.                 float4 pos : SV_POSITION;
  105.                 half2 uv : TEXCOORD1;
  106.             };
  107.  
  108.             struct fragmentOutput
  109.             {
  110.                 half4 color : COLOR;
  111.                 float depth : DEPTH;
  112.             };
  113.  
  114.  
  115.             // functions
  116.  
  117.             fragmentInput vert(vertexInput i)
  118.             {
  119.                 fragmentInput o;
  120.  
  121.                 o.pos = mul(UNITY_MATRIX_MVP, i.vertex);
  122.                 o.uv = TRANSFORM_TEX(i.texcoord, _DepthMask);
  123.  
  124.                 return o;
  125.             }
  126.  
  127.             fragmentOutput frag(fragmentInput i) : COLOR
  128.             {
  129.                 fragmentOutput o;
  130.                 //o.color = half4(0.5, 0.5, 0.5, 0.0);
  131.                 o.color = half4(0.0);
  132.                 if (i.uv.x > 0.0)
  133.                     o.depth = 0.0;
  134.                 else
  135.                     o.depth = 1.0;
  136.                 return o;
  137.             }
  138.  
  139.             ENDCG
  140.  
  141.         } // end pass
  142.  
  143.     }  // end SubShader
  144.  
  145.  
  146.  
  147.     FallBack "Diffuse"
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement