Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
- Shader "Custom/Sliced"
- {
- Properties
- {
- _Color ("Color", COLOR) = (0, 0, 0, 0)
- _MainTex ("MainTex", 2D) = "white" {}
- _Slice ("Slice", Range (-1.1, 2)) = 1
- _SliceColor ("SliceColor", COLOR) = (1, 1, 1, 1)
- }
- SubShader
- {
- Tags {
- "RenderType"="Opaque"
- "LightMode"="ForwardBase"
- }
- Cull Off
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- // user difined
- uniform float4 _Color;
- uniform sampler2D _MainTex;
- uniform float _Slice;
- uniform float4 _SliceColor;
- // unity defined
- uniform float4 _LightColor0;
- struct appdata
- {
- float4 vertex : POSITION;
- float3 normal : NORMAL;
- float2 uv : TEXCOORD0;
- };
- struct v2f
- {
- float4 vertex : SV_POSITION;
- float3 normal : TEXCOORD0;
- float3 wVertex : TEXCOORD1;
- float2 uv : TEXCOORD2;
- };
- v2f vert (appdata v)
- {
- v2f o;
- o.normal = v.normal;
- //o.wVertex = UnityObjectToWorldDir (v.vertex);
- o.wVertex = v.vertex;
- o.uv = v.uv;
- o.vertex = UnityObjectToClipPos(v.vertex);
- return o;
- }
- fixed4 frag (v2f i) : SV_Target
- {
- float3 normalWorld = UnityObjectToWorldNormal (i.normal);
- float3 lightDirection = normalize (_WorldSpaceLightPos0.xyz); // it's inverted light direction, or "direction towards the light" in other words
- float3 diffuseReflection = _LightColor0.rgb * saturate ( dot (normalWorld, lightDirection) );
- float slice = _Slice - i.wVertex.y;
- float4 edge = _SliceColor * saturate (1 - slice * 35);
- clip (slice);
- float4 mainTex = tex2D (_MainTex, i.uv);
- return float4 (mainTex * _Color * (diffuseReflection + UNITY_LIGHTMODEL_AMBIENT.rgb), 1.0) + edge;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement