Skip to content

Instantly share code, notes, and snippets.

@N-Carter
Created August 21, 2011 20:05
Show Gist options
  • Save N-Carter/1161083 to your computer and use it in GitHub Desktop.
Save N-Carter/1161083 to your computer and use it in GitHub Desktop.
Geometry clipping shader
Shader "Mine/Spatial Cutoff Test"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Cutoff ("Cutoff", Float) = 1
}
SubShader
{
Pass
{
CGPROGRAM
#pragma exclude_renderers xbox360
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#include "UnityCG.cginc"
float4 _Color;
sampler2D _MainTex;
float _Cutoff;
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 newPos;
};
v2f vert(appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_UV(0);
o.newPos = mul(UNITY_MATRIX_P, v.vertex);
return o;
}
half4 frag(v2f i) : COLOR
{
half4 texcol = tex2D(_MainTex, i.uv);
if(i.newPos[2] > _Cutoff)
discard;
return texcol * _Color;
}
ENDCG
}
}
FallBack "VertexLit"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment