Advertisement
tonynogo

Demo 36 - Discard fragment

Jul 6th, 2017
3,382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/DiscardFragment"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _Value ("Value", Range(0, 1)) = 0.0
  7.         _ColorInside ("Color inside", Color) = (1, 1, 1, 1)
  8.         _ColorOutside ("Color outside", Color) = (1, 1, 1, 1)
  9.     }
  10.  
  11.     SubShader
  12.     {
  13.             Tags { "RenderType"="Opaque" }
  14.        
  15.             CGPROGRAM
  16.             #pragma surface surf Lambert
  17.  
  18.             struct Input {
  19.                 float2 uv_MainTex;
  20.             };
  21.  
  22.             float _Value;
  23.             fixed4 _ColorOutside;
  24.             sampler2D _MainTex;
  25.  
  26.             void surf(Input IN, inout SurfaceOutput o) {
  27.                 fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
  28.  
  29.                 if(c.r > _Value)
  30.                 {
  31.                     discard;
  32.                 }
  33.  
  34.                 o.Albedo = _ColorOutside;
  35.                 o.Alpha = 1;
  36.             }
  37.  
  38.             ENDCG
  39.  
  40.             Cull Front
  41.  
  42.             CGPROGRAM
  43.             #pragma surface surf Lambert
  44.  
  45.             struct Input {
  46.                 float2 uv_MainTex;
  47.             };
  48.  
  49.             fixed4 _ColorInside;
  50.             float _Value;
  51.             sampler2D _MainTex;
  52.  
  53.             void surf(Input IN, inout SurfaceOutput o) {
  54.                 fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
  55.  
  56.                 if(c.r > _Value)
  57.                 {
  58.                     discard;
  59.                 }
  60.  
  61.                 o.Albedo = _ColorInside;
  62.                 o.Alpha = 1;
  63.             }
  64.  
  65.             ENDCG
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement