-
Notifications
You must be signed in to change notification settings - Fork 15
/
Plasma Waves.sksl
118 lines (98 loc) · 4.33 KB
/
Plasma Waves.sksl
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
117
118
/* This work is protected under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
* more information canbe found at:
* https://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
*/
uniform float3 iResolution; // Viewport resolution (pixels)
uniform float iTime; // Shader playback time (s)
// Plasma Waves
// Created by scarletshark in 2017-09-15
// https://www.shadertoy.com/view/ltXczj
const float overallSpeed = 0.2;
const float gridSmoothWidth = 0.015;
const float axisWidth = 0.05;
const float majorLineWidth = 0.025;
const float minorLineWidth = 0.0125;
const float majorLineFrequency = 5.0;
const float minorLineFrequency = 1.0;
const vec4 gridColor = vec4(0.5);
const float scale = 5.0;
const vec4 lineColor = vec4(0.25, 0.5, 1.0, 1.0);
const float minLineWidth = 0.02;
const float maxLineWidth = 0.5;
const float lineSpeed = 1.0 * overallSpeed;
const float lineAmplitude = 1.0;
const float lineFrequency = 0.2;
const float warpSpeed = 0.2 * overallSpeed;
const float warpFrequency = 0.5;
const float warpAmplitude = 1.0;
const float offsetFrequency = 0.5;
const float offsetSpeed = 1.33 * overallSpeed;
const float minOffsetSpread = 0.6;
const float maxOffsetSpread = 2.0;
const int linesPerGroup = 16;
const vec4 bgColors0 = vec4(lineColor * 0.5);
const vec4 bgColors1 = lineColor - vec4(0.2, 0.2, 0.7, 1);
float drawSmoothLine(float pos, float halfWidth, float t) {
return smoothstep(halfWidth, 0.0, abs(pos - (t)));
}
float drawCrispLine(float pos, float halfWidth, float t) {
return smoothstep(halfWidth + gridSmoothWidth, halfWidth, abs(pos - (t)));
}
float drawPeriodicLine(float freq, float width, float t) {
return drawCrispLine(freq / 2.0, width, abs(mod(t, freq) - (freq) / 2.0));
}
float drawGridLines(float axis)
{
return drawCrispLine(0.0, axisWidth, axis)
+ drawPeriodicLine(majorLineFrequency, majorLineWidth, axis)
+ drawPeriodicLine(minorLineFrequency, minorLineWidth, axis);
}
float drawGrid(vec2 space)
{
return min(1., drawGridLines(space.x)
+drawGridLines(space.y));
}
// probably can optimize w/ noise, but currently using fourier transform
float random(float t)
{
return (cos(t) + cos(t * 1.3 + 1.3) + cos(t * 1.4 + 1.4)) / 3.0;
}
float getPlasmaY(float x, float horizontalFade, float offset)
{
return random(x * lineFrequency + iTime * lineSpeed) * horizontalFade * lineAmplitude + offset;
}
vec4 main( in vec2 fragCoord )
{
vec4 fragColor;
vec2 uv = fragCoord.xy / iResolution.xy;
vec2 space = (fragCoord - iResolution.xy / 2.0) / iResolution.x * 2.0 * scale;
float horizontalFade = 1.0 - (cos(uv.x * 6.28) * 0.5 + 0.5);
float verticalFade = 1.0 - (cos(uv.y * 6.28) * 0.5 + 0.5);
// fun with nonlinear transformations! (wind / turbulence)
space.y += random(space.x * warpFrequency + iTime * warpSpeed) * warpAmplitude * (0.5 + horizontalFade);
space.x += random(space.y * warpFrequency + iTime * warpSpeed + 2.0) * warpAmplitude * horizontalFade;
vec4 lines = vec4(0);
for(int l = 0; l < linesPerGroup; l++)
{
float normalizedLineIndex = float(l) / float(linesPerGroup);
float offsetTime = iTime * offsetSpeed;
float offsetPosition = float(l) + space.x * offsetFrequency;
float rand = random(offsetPosition + offsetTime) * 0.5 + 0.5;
float halfWidth = mix(minLineWidth, maxLineWidth, rand * horizontalFade) / 2.0;
float offset = random(offsetPosition + offsetTime * (1.0 + normalizedLineIndex)) * mix(minOffsetSpread, maxOffsetSpread, horizontalFade);
float linePosition = getPlasmaY(space.x, horizontalFade, offset);
float line = drawSmoothLine(linePosition, halfWidth, space.y) / 2.0 + drawCrispLine(linePosition, halfWidth * 0.15, space.y);
float circleX = mod(float(l) + iTime * lineSpeed, 25.0) - 12.0;
vec2 circlePosition = vec2(circleX, getPlasmaY(circleX, horizontalFade, offset));
float circle = smoothstep(0.01 + gridSmoothWidth, 0.01, length(space - (circlePosition))) * 4.0;
line = line + circle;
lines += line * lineColor * rand;
}
fragColor = mix(bgColors0, bgColors1, uv.x);
fragColor *= verticalFade;
fragColor.a = 1.0;
// debug grid:
//fragColor = mix(fragColor, gridColor, drawGrid(space));
fragColor += lines;
return fragColor;
}