Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
  2.  
  3. Shader "Custom/Sliced"
  4. {
  5.     Properties
  6.     {
  7.         _Color ("Color", COLOR)  = (0, 0, 0, 0)
  8.         _MainTex ("MainTex", 2D) = "white" {}
  9.         _Slice ("Slice", Range (-1.1, 2)) = 1
  10.         _SliceColor ("SliceColor", COLOR) = (1, 1, 1, 1)
  11.     }
  12.     SubShader
  13.     {
  14.         Tags {
  15.             "RenderType"="Opaque"
  16.             "LightMode"="ForwardBase"
  17.         }
  18.  
  19.         Cull Off
  20.  
  21.         Pass
  22.         {
  23.             CGPROGRAM
  24.             #pragma vertex vert
  25.             #pragma fragment frag
  26.            
  27.             #include "UnityCG.cginc"
  28.  
  29.             // user difined
  30.             uniform float4 _Color;
  31.             uniform sampler2D _MainTex;
  32.             uniform float _Slice;
  33.             uniform float4 _SliceColor;
  34.  
  35.             // unity defined
  36.             uniform float4 _LightColor0;
  37.  
  38.             struct appdata
  39.             {
  40.                 float4 vertex : POSITION;
  41.                 float3 normal : NORMAL;
  42.                 float2 uv : TEXCOORD0;
  43.             };
  44.  
  45.             struct v2f
  46.             {
  47.                 float4 vertex : SV_POSITION;
  48.                 float3 normal : TEXCOORD0;
  49.                 float3 wVertex : TEXCOORD1;
  50.                 float2 uv : TEXCOORD2;
  51.             };
  52.            
  53.             v2f vert (appdata v)
  54.             {
  55.                 v2f o;
  56.  
  57.                 o.normal = v.normal;
  58.  
  59.                 //o.wVertex = UnityObjectToWorldDir (v.vertex);
  60.                 o.wVertex = v.vertex;
  61.  
  62.                 o.uv = v.uv;
  63.                 o.vertex = UnityObjectToClipPos(v.vertex);
  64.                 return o;
  65.             }
  66.            
  67.             fixed4 frag (v2f i) : SV_Target
  68.             {
  69.                 float3 normalWorld = UnityObjectToWorldNormal (i.normal);
  70.                 float3 lightDirection = normalize (_WorldSpaceLightPos0.xyz); // it's inverted light direction, or "direction towards the light" in other words
  71.                 float3 diffuseReflection = _LightColor0.rgb * saturate ( dot (normalWorld, lightDirection) );
  72.  
  73.                 float slice = _Slice - i.wVertex.y;
  74.                 float4 edge = _SliceColor * saturate (1 - slice * 35);
  75.                 clip (slice);
  76.  
  77.                 float4 mainTex = tex2D (_MainTex, i.uv);
  78.  
  79.                 return float4 (mainTex * _Color * (diffuseReflection + UNITY_LIGHTMODEL_AMBIENT.rgb), 1.0) + edge;
  80.             }
  81.             ENDCG
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement