Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.09 KB | None | 0 0
  1. Shader "Custom/Slicer"
  2. {
  3.     Properties
  4.     {
  5.         _Color ("Main Color", Color) = (1,0.5,0.5,1)
  6.         _SlicePos ("Slice", float) = 3.0              
  7.     }
  8.     SubShader
  9.     {
  10.         pass
  11.         {
  12.             Tags { "RenderType"="Opaque" }
  13.                        
  14.             Cull Front //ignore front facing polygons
  15.  
  16.             CGPROGRAM
  17.             #pragma vertex vert
  18.             #pragma fragment frag
  19.             #include "UnityCG.cginc"
  20.  
  21.             uniform float _SlicePos;
  22.  
  23.             struct vertOut
  24.             {
  25.                 float4 position : POSITION;
  26.                 float4 worldPos : TEXCOORD0;
  27.             };
  28.  
  29.             vertOut vert(appdata_full vertIn)
  30.             {
  31.                 vertOut o;
  32.                 o.position = mul(UNITY_MATRIX_MVP, vertIn.vertex);                                                            
  33.                 o.worldPos = mul(_Object2World, vertIn.vertex);
  34.                 return o;
  35.             }
  36.  
  37.             float4 _Color;
  38.  
  39.             void frag(float4 worldPos : TEXCOORD0, out float4 c : COLOR)
  40.             {                                
  41.                 if(worldPos.y > _SlicePos)
  42.                 {
  43.                     c = float4(0,0,0,0); //make fragments above slicer transparent
  44.                     discard; //and then discard them
  45.                 }
  46.                 else
  47.                 {
  48.                     c = _Color;  //draw backfacing polygons with chosen solid color
  49.                 }
  50.             }
  51.             ENDCG
  52.         }
  53.  
  54.         Tags { "RenderType" = "Opaque" }
  55.  
  56.         CGPROGRAM
  57.         #pragma surface surf Lambert
  58.  
  59.         struct Input
  60.         {              
  61.                 float3 worldPos;
  62.         };
  63.  
  64.         float4 _Color;
  65.         float _SlicePos;
  66.  
  67.         void surf (Input IN, inout SurfaceOutput o)
  68.         {
  69.                 if(IN.worldPos.y > _SlicePos)
  70.                 {
  71.                     discard; //discard pixels above given y.coodrinate (in world space)
  72.                 }
  73.                 else
  74.                 {
  75.                     o.Albedo = _Color;
  76.                 }
  77.         }
  78.         ENDCG
  79.     }
  80.     Fallback "Diffuse"
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement