Skip to content

Commit ac11c0e

Browse files
authored
Create ColorCycle.shader
1 parent ef1910f commit ac11c0e

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Shader "UnityLibrary/2D/Effects/ColorCycle"
2+
{
3+
Properties
4+
{
5+
_MainTex ("Grayscale", 2D) = "white" {}
6+
_GradientTex ("Gradient", 2D) = "white" {}
7+
_Speed("Speed",float) = 1
8+
}
9+
10+
SubShader
11+
{
12+
Tags { "RenderType"="Opaque" }
13+
LOD 100
14+
15+
Pass
16+
{
17+
CGPROGRAM
18+
#pragma vertex vert
19+
#pragma fragment frag
20+
21+
#include "UnityCG.cginc"
22+
23+
struct appdata
24+
{
25+
float4 vertex : POSITION;
26+
float2 uv : TEXCOORD0;
27+
};
28+
29+
struct v2f
30+
{
31+
float2 uv : TEXCOORD0;
32+
float4 vertex : SV_POSITION;
33+
};
34+
35+
sampler2D _MainTex;
36+
sampler2D _GradientTex;
37+
float4 _MainTex_ST;
38+
float _Speed;
39+
40+
v2f vert (appdata v)
41+
{
42+
v2f o;
43+
o.vertex = UnityObjectToClipPos(v.vertex);
44+
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
45+
return o;
46+
}
47+
48+
fixed4 frag (v2f i) : SV_Target
49+
{
50+
// get (grayscale texture) pixel color
51+
float gray = tex2D(_MainTex, i.uv).r;
52+
53+
// get scrolling
54+
float scroll = frac(_Time.x*_Speed);
55+
56+
// get gradient color from texture
57+
fixed4 col = tex2D(_GradientTex,float2(gray+scroll,0.5));
58+
59+
return col;
60+
}
61+
ENDCG
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)