Advertisement
Guest User

StencilLight.shader

a guest
Feb 17th, 2023
894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/StencilLight"
  2. {
  3.     Properties
  4.     {
  5.         [HDR]_Color("Color",Color) = (1,1,1,0.5)      
  6.     }  
  7.     SubShader
  8.     {
  9.         Tags
  10.         {
  11.             "RenderType" = "Transparent"
  12.             "Queue" = "Transparent"
  13.         }    
  14.         CGINCLUDE
  15.         float4 _Color;
  16.         struct appdata
  17.         {
  18.             float4 vertex : POSITION;
  19.         };
  20.        
  21.         struct v2f
  22.         {
  23.             float4 vertex : SV_POSITION;
  24.         };
  25.  
  26.         v2f vert(appdata v)
  27.         {
  28.             v2f o;
  29.             o.vertex = UnityObjectToClipPos(v.vertex);
  30.             return o;
  31.         }
  32.        
  33.         fixed4 frag(v2f i) : SV_Target
  34.         {
  35.             return _Color * _Color.a;
  36.         }
  37.  
  38.         ENDCG      
  39.         Pass
  40.         {
  41.             Name "Mask"
  42.             Ztest Greater
  43.             Zwrite Off
  44.             Cull Front
  45.             Colormask 0
  46.            
  47.             Stencil
  48.             {
  49.                 Ref 1
  50.                 Comp Greater              
  51.                 Pass Replace
  52.             }
  53.         }
  54.        
  55.         Pass
  56.         {
  57.             Name "Light Outside"
  58.             Zwrite Off
  59.             Ztest Lequal
  60.             Cull Back
  61.             Blend DstColor One
  62.            
  63.             Stencil
  64.             {
  65.                 Comp Equal
  66.                 Ref 1
  67.                 Pass Zero
  68.                 Fail Zero
  69.                 Zfail Zero
  70.             }
  71.            
  72.             CGPROGRAM
  73.             #pragma vertex vert
  74.             #pragma fragment frag
  75.            
  76.             ENDCG
  77.         }
  78.        
  79.         Pass
  80.         {
  81.             Name "Light Inside"
  82.             ZTest Off
  83.             ZWrite Off
  84.             Cull Front
  85.             Blend DstColor One
  86.            
  87.             Stencil
  88.             {
  89.                 Ref 1
  90.                 Comp Equal
  91.                 Pass Zero
  92.             }
  93.            
  94.             CGPROGRAM
  95.             #pragma vertex vert
  96.             #pragma fragment frag
  97.            
  98.             ENDCG
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement