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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
|
--- a/plugins/cube/cube.cpp
+++ b/plugins/cube/cube.cpp
@@ -31,6 +31,7 @@
#include "simple-background.hpp"
#include "skydome.hpp"
#include "cubemap.hpp"
+#include "warp-background.hpp"
#include "cube-control-signal.hpp"
#include "wayfire/region.hpp"
#include "wayfire/scene-render.hpp"
@@ -443,8 +444,49 @@
std::string last_background_mode;
std::unique_ptr<wf_cube_background_base> background;
+ std::unique_ptr<wf_cube_warp_background> warp_background;
+ wf::wl_timer<true> warp_timer;
wf::option_wrapper_t<std::string> background_mode{"cube/background_mode"};
+
+ bool warp_visible() const
+ {
+ return render_node && !resting_renderer && !cube_render_paused && !shutting_down &&
+ std::string(background_mode) == "warp";
+ }
+
+ void sync_warp_animation()
+ {
+ if (!warp_background) return;
+ warp_background->set_active(warp_visible());
+ if (!warp_background->animated())
+ {
+ warp_timer.disconnect();
+ } else if (!warp_timer.is_connected())
+ {
+ warp_timer.set_timeout(warp_background->frame_interval(), [this]
+ {
+ if (!warp_visible() || !warp_background->animated()) return false;
+ wf::scene::damage_node(render_node, render_node->get_bounding_box());
+ output->render->schedule_redraw();
+ return true;
+ });
+ }
+ }
+
+ template<class T> void ensure_warp_option(const std::string& name, const T& value)
+ {
+ // A running compositor may have loaded its metadata before this
+ // plugin upgrade. Promote only missing/untyped new options in place.
+ auto section = wf::get_core().config->get_section("cube");
+ auto existing = section->get_option_or(name);
+ if (!std::dynamic_pointer_cast<wf::config::option_t<T>>(existing))
+ {
+ auto option = std::make_shared<wf::config::option_t<T>>(name, value);
+ if (existing) option->set_value_str(existing->get_value_str());
+ section->register_new_option(option);
+ }
+ }
void reload_background()
{
@@ -464,6 +506,9 @@
} else if (last_background_mode == "cubemap")
{
background = std::make_unique<wf_cube_background_cubemap>();
+ } else if (last_background_mode == "warp")
+ {
+ background.reset();
} else
{
LOGE("cube: Unrecognized background mode %s. Using default \"simple\"",
@@ -592,6 +637,28 @@
}
mouse_overview.load_option("cube/mouse_overview");
render_at_rest.load_option("cube/render_at_rest");
+ ensure_warp_option<double>("warp_speed", 0.8);
+ ensure_warp_option<double>("warp_density", 1.0);
+ ensure_warp_option<double>("warp_streak_length", 0.6);
+ ensure_warp_option<double>("warp_glow", 0.7);
+ ensure_warp_option<double>("warp_brightness", 0.85);
+ ensure_warp_option<double>("warp_twist", 0.10);
+ ensure_warp_option<double>("warp_ring_strength", 0.15);
+ ensure_warp_option<wf::color_t>("warp_color", wf::color_t{0.45, 0.62, 0.90, 1.0});
+ ensure_warp_option<int>("warp_quality", 1);
+ ensure_warp_option<int>("warp_fps", 30);
+ warp_background = std::make_unique<wf_cube_warp_background>([this]
+ {
+ warp_timer.disconnect();
+ sync_warp_animation();
+ output->render->damage_whole();
+ });
+ background_mode.set_callback([this]
+ {
+ reload_background();
+ sync_warp_animation();
+ output->render->damage_whole();
+ });
input_grab = std::make_unique<wf::input_grab_t>("cube", output, nullptr, this, nullptr);
input_grab->set_wants_raw_input(true);
@@ -904,6 +971,7 @@
if (render_node) wf::scene::remove_child(render_node);
render_node = nullptr;
resting_renderer = false;
+ sync_warp_animation();
output->render->set_require_depth_buffer(false);
clear_unused_fixed_top_node();
output->render->damage_whole();
@@ -924,6 +992,7 @@
refresh_cube_geometry();
resting_renderer = true;
+ sync_warp_animation();
return_to_rest = false;
animation.in_exit = false;
animation.cube_animation.rotation.set(0, 0);
@@ -958,6 +1027,7 @@
output->render->damage_whole();
}
cube_render_paused = true;
+ sync_warp_animation();
return;
}
@@ -1119,6 +1189,7 @@
output->render->set_require_depth_buffer(true);
reload_background();
+ sync_warp_animation();
animation.cube_animation.offset_z.set(identity_z_offset + front_face_distance(),
identity_z_offset + front_face_distance());
return true;
@@ -1144,6 +1215,7 @@
render_node = nullptr;
output->render->rem_effect(&pre_hook);
+ sync_warp_animation();
output->render->set_require_depth_buffer(false);
// Vswitch already committed its destination before starting this
@@ -1520,6 +1592,8 @@
}
/* The fixed output background is scheduled behind the cube. */
+ if (warp_visible()) warp_background->render(data.target, data.damage,
+ wf::dimensions(output->get_relative_geometry()));
program.use(wf::TEXTURE_TYPE_RGBA);
GL_CALL(glEnable(GL_DEPTH_TEST));
@@ -1591,6 +1665,7 @@
}
update_view_matrix();
+ sync_warp_animation();
const bool running = animation.cube_animation.running();
if (render_node && (running || animation_was_running))
{
@@ -1771,6 +1846,7 @@
void fini() override
{
shutting_down = true;
+ warp_timer.disconnect();
clear_post_move_window_dim();
if (output->is_plugin_active(grab_interface.name))
{
@@ -1782,6 +1858,7 @@
{
program.free_resources();
});
+ warp_background.reset();
}
};
--- a/plugins/cube/meson.build
+++ b/plugins/cube/meson.build
@@ -1,5 +1,5 @@
animiate = shared_module('cube',
- ['cube.cpp', 'cubemap.cpp', 'skydome.cpp', 'simple-background.cpp'],
+ ['cube.cpp', 'cubemap.cpp', 'skydome.cpp', 'simple-background.cpp', 'warp-background.cpp'],
include_directories: [wayfire_api_inc, wayfire_conf_inc, plugins_common_inc, ipc_include_dirs],
dependencies: [wlroots, pixman, wfconfig, json, plugin_pch_dep],
install: true,
--- a/metadata/cube.xml
+++ b/metadata/cube.xml
@@ -167,12 +167,98 @@
<value>cubemap</value>
<_name>Cubemap</_name>
</desc>
+ <desc>
+ <value>warp</value>
+ <_name>Warp tunnel</_name>
+ </desc>
</option>
<option name="background" type="color">
<_short>Background color</_short>
<_long>Sets the background color for the simple background mode.</_long>
<default>0.1 0.1 0.1 1.0</default>
</option>
+ <group>
+ <_short>Warp tunnel</_short>
+ <_long>Choose Warp tunnel in Background mode to fly through a starfield behind Cube. The viewpoint spans joined monitors. It animates during mouse and keyboard Cube movement and returns to the normal desktop background at rest.</_long>
+ <option name="warp_speed" type="double">
+ <_short>Travel speed</_short>
+ <_long>Forward travel speed. Set to zero to pause the stars and tunnel.</_long>
+ <default>0.8</default>
+ <min>0</min>
+ <max>5</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="warp_density" type="double">
+ <_short>Star density</_short>
+ <_long>Number of stars relative to the selected quality level. Stars keep their individual colours, brightness and depth.</_long>
+ <default>1.0</default>
+ <min>0</min>
+ <max>3</max>
+ <precision>0.1</precision>
+ </option>
+ <option name="warp_streak_length" type="double">
+ <_short>Streak length</_short>
+ <_long>Length of the trails behind nearby stars. Distant stars remain sharp points.</_long>
+ <default>0.6</default>
+ <min>0</min>
+ <max>3</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="warp_glow" type="double">
+ <_short>Star glow</_short>
+ <_long>Strength of the soft halos around stars and faint background dust.</_long>
+ <default>0.7</default>
+ <min>0</min>
+ <max>2</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="warp_brightness" type="double">
+ <_short>Tunnel brightness</_short>
+ <_long>Brightness of the complete warp background.</_long>
+ <default>0.85</default>
+ <min>0</min>
+ <max>2</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="warp_twist" type="double">
+ <_short>Tunnel twist</_short>
+ <_long>Gentle rotation of the starfield and tunnel. Negative values reverse the twist.</_long>
+ <default>0.1</default>
+ <min>-2</min>
+ <max>2</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="warp_ring_strength" type="double">
+ <_short>Tunnel rings</_short>
+ <_long>Brightness of the perspective rings. Set to zero for a starfield without visible tunnel walls.</_long>
+ <default>0.15</default>
+ <min>0</min>
+ <max>1</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="warp_color" type="color">
+ <_short>Tunnel colour</_short>
+ <_long>Tint of the tunnel, dust and star halos. Stars retain warm, cool and white variations.</_long>
+ <default>0.45 0.62 0.90 1.0</default>
+ </option>
+ <option name="warp_quality" type="int">
+ <_short>Tunnel quality</_short>
+ <_long>Star count at normal density. Higher quality adds more stars.</_long>
+ <default>1</default>
+ <min>0</min>
+ <max>2</max>
+ <desc><value>0</value><_name>Low</_name></desc>
+ <desc><value>1</value><_name>Balanced</_name></desc>
+ <desc><value>2</value><_name>Detailed</_name></desc>
+ </option>
+ <option name="warp_fps" type="int">
+ <_short>Tunnel frame rate</_short>
+ <_long>Animation frame rate while Cube is held still. Workspace transitions retain their normal refresh rate.</_long>
+ <default>30</default>
+ <min>10</min>
+ <max>120</max>
+ </option>
+ </group>
<!-- Skydome -->
<option name="skydome_mirror" type="bool">
<_short>Skydome mirror</_short>
--- a/plugins/cube/warp-background.hpp
+++ b/plugins/cube/warp-background.hpp
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <wayfire/option-wrapper.hpp>
+#include <wayfire/opengl.hpp>
+#include <chrono>
+#include <functional>
+
+// A fixed camera shared by the whole logical output, including stitched
+// monitors. Particle seeds are stable; only their depth advances each frame.
+class wf_cube_warp_background
+{
+ wf::option_wrapper_t<double> speed{"cube/warp_speed"};
+ wf::option_wrapper_t<double> density{"cube/warp_density"};
+ wf::option_wrapper_t<double> streaks{"cube/warp_streak_length"};
+ wf::option_wrapper_t<double> glow{"cube/warp_glow"};
+ wf::option_wrapper_t<double> brightness{"cube/warp_brightness"};
+ wf::option_wrapper_t<double> twist{"cube/warp_twist"};
+ wf::option_wrapper_t<double> rings{"cube/warp_ring_strength"};
+ wf::option_wrapper_t<wf::color_t> tint{"cube/warp_color"};
+ wf::option_wrapper_t<int> quality{"cube/warp_quality"};
+ wf::option_wrapper_t<int> fps{"cube/warp_fps"};
+ OpenGL::program_t tunnel_program, star_program;
+ GLuint star_buffer = 0;
+ int star_count = -1;
+ bool active = false;
+ double travel = 0, orientation = 0, twinkle = 0, ambience = 0;
+ std::chrono::steady_clock::time_point last_frame;
+
+ void load_programs();
+ void update_particles();
+
+ public:
+ explicit wf_cube_warp_background(std::function<void()> changed);
+ ~wf_cube_warp_background();
+ void set_active(bool enabled);
+ bool animated() const;
+ unsigned frame_interval() const;
+ void render(const wf::render_target_t& target, const wf::regionf_t& damage,
+ wf::dimensions_t resolution);
+};
--- a/plugins/cube/warp-background.cpp
+++ b/plugins/cube/warp-background.cpp
@@ -0,0 +1,157 @@
+#include "warp-background.hpp"
+#include "warp-shaders.tpp"
+#include <algorithm>
+#include <cmath>
+#include <cstddef>
+#include <cstdint>
+#include <vector>
+
+namespace
+{
+struct star_vertex_t
+{
+ float seed[4];
+ float corner[2];
+};
+
+float random_unit(uint32_t value)
+{
+ value ^= value >> 16;
+ value *= 0x7feb352du;
+ value ^= value >> 15;
+ value *= 0x846ca68bu;
+ value ^= value >> 16;
+ return (value & 0x00ffffffu) / 16777216.0f;
+}
+}
+
+wf_cube_warp_background::wf_cube_warp_background(std::function<void()> changed)
+{
+ speed.set_callback(changed);
+ density.set_callback(changed);
+ streaks.set_callback(changed);
+ glow.set_callback(changed);
+ brightness.set_callback(changed);
+ twist.set_callback(changed);
+ rings.set_callback(changed);
+ tint.set_callback(changed);
+ quality.set_callback(changed);
+ fps.set_callback(changed);
+ last_frame = std::chrono::steady_clock::now();
+}
+
+wf_cube_warp_background::~wf_cube_warp_background()
+{
+ wf::gles::run_in_context_if_gles([&]
+ {
+ tunnel_program.free_resources();
+ star_program.free_resources();
+ if (star_buffer) { GL_CALL(glDeleteBuffers(1, &star_buffer)); }
+ });
+}
+
+void wf_cube_warp_background::set_active(bool enabled)
+{
+ if (active != enabled) last_frame = std::chrono::steady_clock::now();
+ active = enabled;
+}
+
+bool wf_cube_warp_background::animated() const
+{
+ return active && double(speed) > 0;
+}
+
+unsigned wf_cube_warp_background::frame_interval() const
+{
+ return unsigned(std::ceil(1000.0 / std::clamp(int(fps), 10, 120)));
+}
+
+void wf_cube_warp_background::load_programs()
+{
+ if (!tunnel_program.get_program_id(wf::TEXTURE_TYPE_RGBA))
+ tunnel_program.set_simple(OpenGL::compile_program(warp_vertex, warp_fragment));
+ if (!star_program.get_program_id(wf::TEXTURE_TYPE_RGBA))
+ star_program.set_simple(OpenGL::compile_program(warp_star_vertex, warp_star_fragment));
+}
+
+void wf_cube_warp_background::update_particles()
+{
+ const int counts[] = {1536, 4096, 8192};
+ const int count = int(counts[std::clamp(int(quality), 0, 2)] * std::clamp(double(density), 0.0, 3.0));
+ if (count == star_count) return;
+ star_count = count;
+ std::vector<star_vertex_t> vertices;
+ vertices.reserve(count * 6);
+ const float corners[6][2] = {{0, -1}, {1, -1}, {1, 1}, {0, -1}, {1, 1}, {0, 1}};
+ for (int i = 0; i < count; ++i)
+ {
+ float seed[] = {2 * random_unit(i * 4 + 17) - 1, 2 * random_unit(i * 4 + 18) - 1,
+ random_unit(i * 4 + 19), random_unit(i * 4 + 20)};
+ for (const auto& corner : corners)
+ vertices.push_back({{seed[0], seed[1], seed[2], seed[3]}, {corner[0], corner[1]}});
+ }
+ if (!star_buffer) { GL_CALL(glGenBuffers(1, &star_buffer)); }
+ GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, star_buffer));
+ GL_CALL(glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(star_vertex_t),
+ vertices.data(), GL_STATIC_DRAW));
+ GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, 0));
+}
+
+void wf_cube_warp_background::render(const wf::render_target_t& target, const wf::regionf_t& damage,
+ wf::dimensions_t resolution)
+{
+ const auto now = std::chrono::steady_clock::now();
+ if (active)
+ {
+ const double advance = std::clamp(std::chrono::duration<double>(now - last_frame).count(), 0.0, 0.25) *
+ std::clamp(double(speed), 0.0, 5.0) * 1.8;
+ // Each bounded phase is periodic at its own wrap point, retaining
+ // smooth motion and float precision throughout long sessions.
+ travel = std::fmod(travel + advance, 12.0);
+ orientation = std::fmod(orientation + advance * std::clamp(double(twist), -2.0, 2.0) * 0.10, 2 * M_PI);
+ twinkle = std::fmod(twinkle + advance * 0.9, 2 * M_PI);
+ ambience = std::fmod(ambience + advance * 0.025, 2 * M_PI);
+ }
+ last_frame = now;
+ load_programs();
+ update_particles();
+ const float width = resolution.width, height = resolution.height;
+ const GLfloat quad[] = {0, 0, width, 0, width, height, 0, 0, width, height, 0, height};
+ const auto color = wf::color_t(tint);
+ auto uniforms = [&] (OpenGL::program_t& program)
+ {
+ program.uniformMatrix4f("mvp", wf::gles::render_target_orthographic_projection(target));
+ program.uniform2f("resolution", width, height);
+ program.uniform1f("travel", travel);
+ program.uniform1f("orientation", orientation);
+ program.uniform1f("twinkle", twinkle);
+ program.uniform1f("ambience", ambience);
+ program.uniform1f("brightness", std::clamp(double(brightness), 0.0, 2.0));
+ program.uniform1f("glow", std::clamp(double(glow), 0.0, 2.0));
+ program.uniform1f("twist", std::clamp(double(twist), -2.0, 2.0));
+ program.uniform3f("tint", color.r, color.g, color.b);
+ };
+ GL_CALL(glDisable(GL_DEPTH_TEST));
+ GL_CALL(glDisable(GL_CULL_FACE));
+ GL_CALL(glDisable(GL_BLEND));
+ tunnel_program.use(wf::TEXTURE_TYPE_RGBA);
+ uniforms(tunnel_program);
+ tunnel_program.uniform1f("ring_strength", std::clamp(double(rings), 0.0, 1.0));
+ tunnel_program.attrib_pointer("position", 2, 0, quad);
+ wf::gles::for_each_scissor_rect(target, damage, [&] { GL_CALL(glDrawArrays(GL_TRIANGLES, 0, 6)); });
+ tunnel_program.deactivate();
+ if (!star_count) return;
+ star_program.use(wf::TEXTURE_TYPE_RGBA);
+ uniforms(star_program);
+ star_program.uniform1f("speed", std::clamp(double(speed), 0.0, 5.0));
+ star_program.uniform1f("streaks", std::clamp(double(streaks), 0.0, 3.0));
+ GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, star_buffer));
+ star_program.attrib_pointer("seed", 4, sizeof(star_vertex_t), reinterpret_cast<void*>(offsetof(star_vertex_t, seed)));
+ star_program.attrib_pointer("corner", 2, sizeof(star_vertex_t), reinterpret_cast<void*>(offsetof(star_vertex_t, corner)));
+ GL_CALL(glEnable(GL_BLEND));
+ GL_CALL(glBlendFunc(GL_ONE, GL_ONE));
+ wf::gles::for_each_scissor_rect(target, damage, [&] { GL_CALL(glDrawArrays(GL_TRIANGLES, 0, star_count * 6)); });
+ GL_CALL(glDisable(GL_BLEND));
+ star_program.deactivate();
+ GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, 0));
+}
--- a/plugins/cube/warp-shaders.tpp
+++ b/plugins/cube/warp-shaders.tpp
@@ -0,0 +1,119 @@
+static const char *warp_vertex = R"(
+#version 100
+attribute vec2 position;
+uniform mat4 mvp;
+uniform vec2 resolution;
+varying vec2 uv;
+void main()
+{
+ uv = position / resolution;
+ gl_Position = mvp * vec4(position, 0.0, 1.0);
+}
+)";
+
+static const char *warp_fragment = R"(
+#version 100
+#extension GL_OES_standard_derivatives : enable
+precision highp float;
+uniform vec2 resolution;
+uniform float travel, brightness, glow, twist, ring_strength, orientation, ambience;
+uniform vec3 tint;
+varying vec2 uv;
+
+float hash(vec2 p)
+{
+ return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
+}
+float noise(vec2 p)
+{
+ vec2 cell = floor(p), f = fract(p);
+ f = f * f * (3.0 - 2.0 * f);
+ return mix(mix(hash(cell), hash(cell + vec2(1.0, 0.0)), f.x),
+ mix(hash(cell + vec2(0.0, 1.0)), hash(cell + vec2(1.0)), f.x), f.y);
+}
+void main()
+{
+ vec2 p = (uv - 0.5) * vec2(resolution.x / resolution.y, 1.0) * 2.0;
+ float radius = length(p);
+ float depth = 2.2 / max(radius, 0.045);
+ float angle = atan(p.y, p.x) + orientation + twist * depth * 0.15;
+ // World-space ring spacing gives perspective compression toward the
+ // vanishing point. Derivatives keep its thin edges stable at 4K.
+ float phase = depth + travel;
+ float aa = max(fwidth(phase), 0.008);
+ float line = 1.0 - smoothstep(0.0, aa + 0.035, abs(fract(phase) - 0.5));
+ float centre_fade = smoothstep(0.10, 0.40, radius);
+ float ring = line * centre_fade / (1.0 + radius * radius * 0.6);
+ float filaments = pow(max(0.0, 0.5 + 0.5 * cos(angle * 12.0)), 18.0);
+ vec2 drift = vec2(cos(ambience), sin(ambience));
+ float haze = noise(p * 1.8 + drift);
+ haze *= noise(p * 4.3 - drift * 0.7);
+ vec3 color = vec3(0.0015, 0.003, 0.009);
+ color += tint * haze * 0.021 * glow;
+ color += tint * ring_strength * (ring * 0.20 + filaments * centre_fade * 0.013);
+ gl_FragColor = vec4(color * brightness, 1.0);
+}
+)";
+
+static const char *warp_star_vertex = R"(
+#version 100
+precision highp float;
+attribute vec4 seed;
+attribute vec2 corner;
+uniform mat4 mvp;
+uniform vec2 resolution;
+uniform float travel, speed, streaks, brightness, twist, orientation, twinkle;
+uniform vec3 tint;
+varying vec2 local;
+varying float trail_length, radius, luminosity;
+varying vec3 star_color;
+void main()
+{
+ float z = mod(seed.z * 12.0 - travel, 12.0) + 0.45;
+ float angle = orientation + twist * z * 0.10;
+ mat2 rotation = mat2(cos(angle), sin(angle), -sin(angle), cos(angle));
+ vec2 world = rotation * (seed.xy * vec2(resolution.x / resolution.y, 1.0) * 6.0);
+ vec2 head = world / z * resolution.y * 0.5;
+ vec2 tail = world / (z + speed * streaks * 0.22) * resolution.y * 0.5;
+ vec2 direction = normalize(head - tail + vec2(0.00001));
+ vec2 normal = vec2(-direction.y, direction.x);
+ trail_length = min(length(head - tail), resolution.y * 0.30);
+ tail = head - direction * trail_length;
+ radius = (1.1 + 2.4 * pow(seed.w, 3.0)) * clamp(resolution.y / 1080.0, 0.65, 2.0);
+ radius *= 0.65 + 1.4 / (z + 0.5);
+ local = vec2(corner.x * (trail_length + 2.0 * radius) - radius, corner.y * radius);
+ vec2 pixel = resolution * 0.5 + tail + direction * local.x + normal * local.y;
+ gl_Position = mvp * vec4(pixel, 0.0, 1.0);
+ float fade = smoothstep(0.45, 0.90, z) * (1.0 - smoothstep(11.0, 12.45, z));
+ float shimmer = mix(1.0, 0.88 + 0.12 * sin(twinkle + seed.w * 80.0), smoothstep(4.0, 10.0, z));
+ luminosity = brightness * fade * shimmer * (0.30 + 1.50 * pow(seed.w, 4.0));
+ float spectral = fract(seed.w * 17.0);
+ vec3 natural = spectral < 0.12 ? vec3(1.0, 0.50, 0.32) :
+ (spectral < 0.36 ? vec3(1.0, 0.87, 0.64) :
+ (spectral < 0.68 ? vec3(0.68, 0.82, 1.0) : vec3(1.0)));
+ star_color = mix(natural, tint, 0.14);
+}
+)";
+
+static const char *warp_star_fragment = R"(
+#version 100
+precision highp float;
+uniform float glow;
+varying vec2 local;
+varying float trail_length, radius, luminosity;
+varying vec3 star_color;
+void main()
+{
+ vec2 head_distance = vec2(local.x - trail_length, local.y) / radius;
+ float along = clamp(local.x / max(trail_length, 0.01), 0.0, 1.0);
+ float end_distance = max(max(-local.x, local.x - trail_length), 0.0);
+ float distance2 = (local.y * local.y + end_distance * end_distance) / (radius * radius);
+ float core = exp(-dot(head_distance, head_distance) * 18.0);
+ float trail = exp(-distance2 * 15.0) * (0.10 + 0.65 * along);
+ float halo = exp(-distance2 * 4.0) * 0.22 * glow;
+ float edge = 1.0 - smoothstep(0.75, 1.0, distance2);
+ vec3 color = star_color * luminosity * (core + trail + halo) * edge;
+ // Additive RGB preserves the opaque backdrop's alpha.
+ gl_FragColor = vec4(color, 0.0);
+}
+)";
|