Skip to content

Instantly share code, notes, and snippets.

@N-Carter
Created January 15, 2014 10:21
Show Gist options
  • Save N-Carter/8433919 to your computer and use it in GitHub Desktop.
Save N-Carter/8433919 to your computer and use it in GitHub Desktop.
A shader that discards the part of a mesh that's on one side of a plane.
// Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position
// Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION'
// Upgrade NOTE: replaced 'glstate.matrix.projection' with 'UNITY_MATRIX_P'
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
// Upgrade NOTE: excluded shader from Xbox360; has structs without semantics (struct v2f members newPos)
#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