- Home /
Detailed gradient shader
Hello, I have a gradient shader but it is very low definition because it is in the vert constructor, I wrote in vert/frag cg, but how can I make it better?
Shader "Custom/Spawn" {
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_HeightMin ("Min Height", float) = 0
_HeightMax ("Max Height", float) = 1
_Cutoff ("Alpha Cutoff", Range (0, 1)) = 0
}
SubShader
{
Blend SrcAlpha OneMinusSrcAlpha
Tags
{
"Queue" = "Transparent"
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
float4 _Color;
float _HeightMin;
float _HeightMax;
float _Cutoff;
struct VertexInput {
float4 vertex : POSITION;
};
struct VertexOutput {
float4 pos : POSITION;
float4 col : COLOR;
float4 texcoord : TEXCOORD0;
};
VertexOutput vert (VertexInput input) {
VertexOutput output;
output.col = _Color;
float vertexHeight = input.vertex.y;
if (vertexHeight < _HeightMin)
{
output.col.a = 1;
}
else
{
float alpha = lerp (0, 1, (_HeightMax - input.vertex.y) / (_HeightMax - _HeightMin));
if (alpha < 0)
{
alpha = 0;
}
output.col.a = alpha;
}
if (output.col.a < _Cutoff)
{
output.col.a = 0;
}
output.pos = mul (UNITY_MATRIX_MVP, input.vertex);
return output;
}
float4 frag (VertexOutput output) : COLOR {
return output.col;
}
ENDCG
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612054053im_/https://answers.unity.com/themes/thub/images/avi.jpg)