-
Notifications
You must be signed in to change notification settings - Fork 0
/
VertexGradient.shader
59 lines (51 loc) · 1.52 KB
/
VertexGradient.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Shader "Unlit/VertexGradient"
{
Properties
{
_Color ("Color", Color) = (1,1,0,1)
_MinHeight ("Min Height", Float) = -1.0
_MaxHeight ("Max Height", Float) = 1.0
_GradientStrength ("Gradient Strength", Range(0, 1)) = 0.5
}
SubShader
{
Tags { "RenderType"="Opaque"
"LightMode" = "ForwardBase"
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertexClipSpace : SV_POSITION;
float4 vertexObjectSpace : TEXCOORD0;
};
float4 _Color;
float _GradientStrength;
float _MinHeight;
float _MaxHeight;
v2f vert (appdata v)
{
v2f o;
o.vertexClipSpace = UnityObjectToClipPos(v.vertex);
o.vertexObjectSpace = v.vertex;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float height = i.vertexObjectSpace.y;
float gradient = saturate((height - _MinHeight) / (_MaxHeight - _MinHeight));
fixed4 col = float4(_Color.xyz, 1.0);
return float4(col.xyz * lerp(0, _GradientStrength, gradient), 1);
}
ENDCG
}
}
}