-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPolyColorWave.shader
More file actions
114 lines (95 loc) · 2.81 KB
/
Copy pathPolyColorWave.shader
File metadata and controls
114 lines (95 loc) · 2.81 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Shader "snail/PolyColorWave" {
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Saturation ("Saturation", Range(0, 1)) = 1
_Value ("Value", Range(0, 1)) = 1
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent" "LightMode" = "ForwardBase" }
Cull Back
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma geometry geom
#pragma multi_compile_fwdbase
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
uniform float _Saturation;
uniform float _Value;
float3 HSVToRGB( float3 c )
{
float4 K = float4( 1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0 );
float3 p = abs( frac( c.xxx + K.xyz ) * 6.0 - K.www );
return c.z * lerp( K.xxx, clamp( p - K.xxx, 0.0, 1.0 ), c.y );
}
float3 getColor(float f) {
return HSVToRGB(float3(f*1.618, _Saturation, _Value));
}
float getTime(float phase, float step) {
float t = (_Time.y + phase) * .1;
return t - frac(t) * step;
}
float random (in float2 st) {
return frac(
cos(dot(st, float2(12.9898, 78.233)))
* 43758.5453123
);
}
struct v2g
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
};
struct g2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
fixed4 col : COLOR;
};
v2g vert (appdata_base v)
{
v2g o;
o.vertex = v.vertex;
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.normal = v.normal;
return o;
}
[maxvertexcount(3)]
void geom(triangle v2g IN[3], inout TriangleStream<g2f> tristream)
{
float2 mid = (IN[0].uv + IN[1].uv + IN[2].uv)/3;
float hash = random(mid);
float3 pos = mul(unity_ObjectToWorld, mid);
float freq = .1;
float transitionSpeed = 2;
float v = getTime(IN[0].uv.y * .9 + hash * .1, 0);
float3 color = getColor(floor(v));
float flash = 1-saturate(frac(v) * 30);
g2f o;
for(int i = 0 ; i < 3 ; i ++) {
o.pos = UnityObjectToClipPos(IN[i].vertex);
o.uv = IN[i].uv;
o.col.rgb = color;
o.col.a = flash;
tristream.Append(o);
}
tristream.RestartStrip();
}
fixed4 frag (g2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
col.rgb *= i.col.rgb;
clip(col.a-0.01);
return lerp(col, fixed4(1,1,1,1) , i.col.a);
}
ENDCG
}
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}