Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/Slicer"
- {
- Properties
- {
- _Color ("Main Color", Color) = (1,0.5,0.5,1)
- _SlicePos ("Slice", float) = 3.0
- }
- SubShader
- {
- pass
- {
- Tags { "RenderType"="Opaque" }
- Cull Front //ignore front facing polygons
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- uniform float _SlicePos;
- struct vertOut
- {
- float4 position : POSITION;
- float4 worldPos : TEXCOORD0;
- };
- vertOut vert(appdata_full vertIn)
- {
- vertOut o;
- o.position = mul(UNITY_MATRIX_MVP, vertIn.vertex);
- o.worldPos = mul(_Object2World, vertIn.vertex);
- return o;
- }
- float4 _Color;
- void frag(float4 worldPos : TEXCOORD0, out float4 c : COLOR)
- {
- if(worldPos.y > _SlicePos)
- {
- c = float4(0,0,0,0); //make fragments above slicer transparent
- discard; //and then discard them
- }
- else
- {
- c = _Color; //draw backfacing polygons with chosen solid color
- }
- }
- ENDCG
- }
- Tags { "RenderType" = "Opaque" }
- CGPROGRAM
- #pragma surface surf Lambert
- struct Input
- {
- float3 worldPos;
- };
- float4 _Color;
- float _SlicePos;
- void surf (Input IN, inout SurfaceOutput o)
- {
- if(IN.worldPos.y > _SlicePos)
- {
- discard; //discard pixels above given y.coodrinate (in world space)
- }
- else
- {
- o.Albedo = _Color;
- }
- }
- ENDCG
- }
- Fallback "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement