-
Notifications
You must be signed in to change notification settings - Fork 24
/
fireworks-rockets.glsl
109 lines (86 loc) · 3.16 KB
/
fireworks-rockets.glsl
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
// This Ghostty shader is a lightly modified port of https://www.shadertoy.com/view/4dBGRw
#define BLACK_BLEND_THRESHOLD .4
//Creates a diagonal red-and-white striped pattern.
vec3 barberpole(vec2 pos, vec2 rocketpos) {
float d = (pos.x - rocketpos.x) + (pos.y - rocketpos.y);
vec3 col = vec3(1.0);
d = mod(d * 20., 2.0);
if (d > 1.0) {
col = vec3(1.0, 0.0, 0.0);
}
return col;
}
vec3 rocket(vec2 pos, vec2 rocketpos) {
vec3 col = vec3(0.0);
float f = 0.;
float absx = abs(rocketpos.x - pos.x);
float absy = abs(rocketpos.y - pos.y);
// Wooden stick
if (absx < 0.01 && absy < 0.22) {
col = vec3(1.0, 0.5, 0.5);
}
// Barberpole
if (absx < 0.05 && absy < 0.15) {
col = barberpole(pos, rocketpos);
}
// Rocket Point
float pointw = (rocketpos.y - pos.y - 0.25) * -0.7;
if ((rocketpos.y - pos.y) > 0.1) {
f = smoothstep(pointw - 0.001, pointw + 0.001, absx);
col = mix(vec3(1.0, 0.0, 0.0), col, f);
}
// Shadow
f = -.5 + smoothstep(-0.05, 0.05, (rocketpos.x - pos.x));
col *= 0.7 + f;
return col;
}
float rand(float val, float seed) {
return cos(val * sin(val * seed) * seed);
}
float distance2(in vec2 a, in vec2 b) {
return dot(a - b, a - b);
}
mat2 rr = mat2(cos(1.0), -sin(1.0), sin(1.0), cos(1.0));
vec3 drawParticles(vec2 pos, vec3 particolor, float time, vec2 cpos, float gravity, float seed, float timelength) {
vec3 col = vec3(0.0);
vec2 pp = vec2(1.0, 0.0);
for (float i = 1.0; i <= 128.0; i++) {
float d = rand(i, seed);
float fade = (i / 128.0) * time;
vec2 particpos = cpos + time * pp * d;
pp = rr * pp;
col = mix(particolor / fade, col, smoothstep(0.0, 0.0001, distance2(particpos, pos)));
}
col *= smoothstep(0.0, 1.0, (timelength - time) / timelength);
return col;
}
vec3 drawFireworks(float time, vec2 uv, vec3 particolor, float seed) {
float timeoffset = 2.0;
vec3 col = vec3(0.0);
if (time <= 0.) {
return col;
}
if (mod(time, 6.0) > timeoffset) {
col = drawParticles(uv, particolor, mod(time, 6.0) - timeoffset, vec2(rand(ceil(time / 6.0), seed), -0.5), 0.5, ceil(time / 6.0), seed);
} else {
col = rocket(uv * 3., vec2(3. * rand(ceil(time / 6.0), seed), 3. * (-0.5 + (timeoffset - mod(time, 6.0)))));
}
return col;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 uv = 1.0 - 2.0 * fragCoord.xy / iResolution.xy;
uv.x *= iResolution.x / iResolution.y;
vec3 col = vec3(0.1, 0.1, 0.2);
// Flip the y-axis so that the rocket is drawn from the bottom of the screen
uv.y = -uv.y;
col += 0.1 * uv.y;
col += drawFireworks(iTime, uv, vec3(1.0, 0.1, 0.1), 1.);
col += drawFireworks(iTime - 2.0, uv, vec3(0.0, 1.0, 0.5), 2.);
col += drawFireworks(iTime - 4.0, uv, vec3(1.0, 1.0, 0.1), 3.);
vec2 termUV = fragCoord.xy / iResolution.xy;
vec4 terminalColor = texture(iChannel0, termUV);
float alpha = step(length(terminalColor.rgb), BLACK_BLEND_THRESHOLD);
vec3 blendedColor = mix(terminalColor.rgb * 1.0, col.rgb * 0.3, alpha);
fragColor = vec4(blendedColor, terminalColor.a);
}