Created
October 6, 2019 10:05
-
-
Save Madgvox/de0baa0216cb250cf4edc7cf91d7e31e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/WorldSpaceClip" { | |
Properties { | |
_Color ("Color", Color) = (1,1,1,1) | |
_InteriorColor( "Interior Color", Color ) = ( 1,1,1,1 ) | |
_MainTex ("Albedo (RGB)", 2D) = "white" {} | |
_Glossiness ("Smoothness", Range(0,1)) = 0.5 | |
_Metallic ("Metallic", Range(0,1)) = 0.0 | |
_ClipOffset ( "Clip Height", Float) = 10.0 | |
} | |
SubShader { | |
Tags { "RenderType" = "Opaque" } | |
LOD 200 | |
CGPROGRAM | |
#pragma surface surf Standard fullforwardshadows | |
#pragma target 3.0 | |
sampler2D _MainTex; | |
struct Input { | |
float2 uv_MainTex; | |
float3 worldPos; | |
}; | |
half _Glossiness; | |
half _Metallic; | |
fixed4 _Color; | |
float _ClipOffset; | |
void surf( Input IN, inout SurfaceOutputStandard o ) { | |
clip( _ClipOffset - IN.worldPos.y ); | |
fixed4 c = tex2D( _MainTex, IN.uv_MainTex ) * _Color; | |
o.Albedo = c.rgb; | |
o.Metallic = _Metallic; | |
o.Smoothness = _Glossiness; | |
o.Alpha = c.a; | |
} | |
ENDCG | |
Pass { | |
Cull Front | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma target 3.0 | |
#include "UnityCG.cginc" | |
sampler2D _MainTex; | |
struct appdata { | |
float4 vertex : POSITION; | |
float3 texcoord : TEXCOORD0; | |
}; | |
struct v2f { | |
float4 pos : POSITION; | |
float4 worldPos : TEXCOORD0; | |
}; | |
v2f vert( appdata v ) | |
{ | |
v2f o; | |
o.pos = UnityObjectToClipPos( v.vertex ); | |
o.worldPos = mul( unity_ObjectToWorld, v.vertex ); | |
return o; | |
} | |
float4 _InteriorColor; | |
float _ClipOffset; | |
half4 frag( v2f i ) : COLOR | |
{ | |
clip( _ClipOffset - i.worldPos.y ); | |
return _InteriorColor; | |
} | |
ENDCG | |
} | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment