-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColourfulWaves.shader
116 lines (90 loc) · 2.81 KB
/
ColourfulWaves.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
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
115
116
Shader "Custom/Colourful Waves"
{
Properties
{
_Speed("Color Speed" ,Range(0.0,1.0)) = 0.02
_WaveSpeed("Wave Speed" ,Range(-1.0,1.0)) = 0.1
_WavesNumber("Waves number" ,Range(0.1,20.0)) = 8.0
_ColorModifierX("Color modifier X",Range(0.0,2.0)) = 0.12
_ColorModifierY("Color modifier Y",Range(0.0,2.0)) = 0.2
_ColorPaletteA("Color Palette A", Color) = (0.5, 0.5, 0.5)
_ColorPaletteB("Color Palette B", Color) = (0.5, 0.5, 0.5)
_ColorPaletteC("Color Palette C", Color) = (2., 1., 0.)
_ColorPaletteD("Color Palette D", Color) = (0.5, 0.2, 0.25)
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct VertexInput
{
fixed4 vertex : POSITION;
fixed2 uv : TEXCOORD0;
};
struct VertexOutput
{
fixed4 pos : SV_POSITION;
fixed2 uv : TEXCOORD0;
};
fixed _Speed;
fixed _WaveSpeed;
int _WavesNumber;
fixed _ColorModifierX;
fixed _ColorModifierY;
fixed3 _ColorPaletteA;
fixed3 _ColorPaletteB;
fixed3 _ColorPaletteC;
fixed3 _ColorPaletteD;
#define PI 3.14159265359
fixed wavePosition(fixed2 uv, fixed i)
{
return sin((uv.x + i * 8.456) * (sin(_Time.y * _WaveSpeed + 7.539 + i * 0.139) + 2.) * 0.5) * 0.65
+ sin(uv.x * (sin(_Time.y * _WaveSpeed + i * 0.2) + 2.) * 0.3) * 0.3
- (i - _WavesNumber / 2.) * 2. - uv.y;
}
// http://iquilezles.org/www/articles/palettes/palettes.htm
fixed3 colorPalette(fixed t, fixed3 a, fixed3 b, fixed3 c, fixed3 d)
{
return a + b * cos(PI * 2. * (c * t + d));
}
fixed3 color(fixed x)
{
return colorPalette(x, _ColorPaletteA, _ColorPaletteB, _ColorPaletteC, _ColorPaletteD);
}
VertexOutput vert(VertexInput v)
{
VertexOutput o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag(VertexOutput i) : SV_Target
{
fixed4 fragColor = 0;
fixed2 uv = i.uv;
fixed2 waveUv = (2.0 * i.uv - 1) / 1 * (_WavesNumber - 1.);
fixed aa = _WavesNumber * 2. / _ScreenParams.y;
for (fixed i = 0.; i < _WavesNumber; i++)
{
fixed waveTop = wavePosition(waveUv, i);
fixed waveBottom = wavePosition(waveUv, i + 1.);
fixed3 col = color(i * _ColorModifierX + uv.x * _ColorModifierY + _Time.y * _Speed);
col += smoothstep(0.3, 0., waveTop) * 0.05;
col += (1. - abs(0.5 - smoothstep(waveTop, waveBottom, 0.))) * 0.06;
col += smoothstep(-0.3, 0., waveBottom) * -0.05;
fragColor.xyz = lerp(fragColor.xyz, col, smoothstep(0., aa, waveTop));
}
fragColor.w = 1.0;
return fragColor;
}
ENDCG
}
}
}