- Home /
Question by
unnamed_game_dev · Oct 25, 2017 at 02:28 PM ·
shadergraphics
Using clip() in a custom unity shader depends on camera view angle?
I'm trying to implement a shader that will cut out a section of a generated mesh. This is what I have so far:
Properties
{
_MainTex("Texture", 2D) = "white" {}
_Cutoff("Cutoff", float) = 0
}
SubShader
{
Tags { "DisableBatching" = "true" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float2 uv : TEXCOORD0;
float4 vertex : POSITION;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 position : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _Cutoff;
v2f vert(appdata v)
{
v2f o;
o.position = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
_MainTex
is a gradient from black to white and I'm remapping the UVs of the generated mesh manually depending on the bounding box. It works when the generated mesh is small, but when it is large and I set _Cutoff to 0.9, there are some leftover pieces rendered, and rotating the camera reveals even more unwanted sections being displayed. Here's a gif of what the problem. How can I show any percentage of this mesh without this issue?
Comment