-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path04_Gradient.shader
55 lines (47 loc) · 1.31 KB
/
04_Gradient.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
Shader "Workbook/04 Gradient"
{
Properties
{
_ColorA ("Color A", Color) = (1, 1, 1, 1)
_ColorB ("Color B", Color) = (1, 1, 1, 1)
}
SubShader
{
Tags { "RenderType" = "Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _ColorA;
float4 _ColorB;
// Per-vertex mesh data:
struct MeshData
{
float4 vertex : POSITION;
float2 uv0 : TEXCOORD0;
};
// Per-fragment interpolated data:
struct Interpolated
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD1;
};
Interpolated vert (MeshData v)
{
Interpolated o;
o.vertex = UnityObjectToClipPos(v.vertex); // Converts local space to clip space.
o.uv = v.uv0;
return o;
}
float4 frag (Interpolated i) : SV_Target
{
// Blend between 2 colors based on the x UV coordinate.
float4 outColor = lerp(_ColorA, _ColorB, i.uv.x);
return outColor;
}
ENDCG
}
}
}