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
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
|
--- a/metadata/cube.xml
+++ b/metadata/cube.xml
@@ -172,6 +172,10 @@
<_name>Warp tunnel</_name>
</desc>
<desc>
+ <value>hyperspace</value>
+ <_name>Hyperspace</_name>
+ </desc>
+ <desc>
<value>none</value>
<_name>None</_name>
</desc>
@@ -183,7 +187,7 @@
</option>
<option name="backdrop_image_opacity" type="double">
<_short>Backdrop image opacity</_short>
- <_long>Opacity of the fixed desktop image behind Cube. Set to zero to remove the image, or use a value between zero and one to fade it into Cube's background. Windows and panels keep their opacity. Warp replaces the image during movement. At rest, a visible tunnel keeps moving when Animate at rest is enabled. None always removes the image and effects.</_long>
+ <_long>Opacity of the fixed desktop image behind Cube. Set to zero to remove the image, or use a value between zero and one to fade it into Cube's background. Windows and panels keep their opacity. Warp and Hyperspace replace the image during movement. At rest, a visible effect keeps moving when its animation-at-rest setting is enabled. None always removes the image and effects.</_long>
<default>1.0</default>
<min>0</min>
<max>1</max>
@@ -213,6 +217,11 @@
<max>3</max>
<precision>0.1</precision>
</option>
+ <option name="warp_coloured_stars" type="double">
+ <_short>Coloured stars</_short>
+ <_long>Fraction of stars with a warm or blue colour. Most stars are white at the default 12%. Zero makes all stars white; one colours every star.</_long>
+ <default>0.12</default><min>0</min><max>1</max><precision>0.01</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>
@@ -276,6 +285,112 @@
<max>120</max>
</option>
</group>
+ <group>
+ <_short>Hyperspace</_short>
+ <_long>Layered clouds, flowing light ribbons, a soft destination glow and two star layers. Distant stars drift very slowly behind the clouds; mostly white nearby stars pass in faster trails. Select Hyperspace in Background mode. Backdrop image opacity blends the resting effect with the desktop image.</_long>
+ <option name="hyperspace_animate_at_rest" type="bool">
+ <_short>Animate hyperspace at rest</_short>
+ <_long>Keep a visible Hyperspace background moving after Cube rotation ends. A fully opaque backdrop image hides the resting effect.</_long>
+ <default>true</default>
+ </option>
+ <option name="hyperspace_speed" type="double">
+ <_short>Hyperspace speed</_short>
+ <_long>Continuous forward travel speed. Zero freezes clouds and both star layers.</_long>
+ <default>0.65</default>
+ <min>0</min><max>5</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="hyperspace_cloud_density" type="double">
+ <_short>Cloud density</_short>
+ <_long>Strength and absorption of the layered clouds around the tunnel. Zero removes cloud haze.</_long>
+ <default>0.85</default>
+ <min>0</min><max>2</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="hyperspace_turbulence" type="double">
+ <_short>Cloud turbulence</_short>
+ <_long>Amount of flowing distortion in the cloud shells and ribbons.</_long>
+ <default>0.65</default>
+ <min>0</min><max>2</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="hyperspace_ribbon_strength" type="double">
+ <_short>Light ribbons</_short>
+ <_long>Brightness of the long light ribbons flowing around the tunnel.</_long>
+ <default>0.75</default>
+ <min>0</min><max>2</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="hyperspace_glow" type="double">
+ <_short>Destination glow</_short>
+ <_long>Soft light at the vanishing point and halos around stars.</_long>
+ <default>0.65</default>
+ <min>0</min><max>2</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="hyperspace_brightness" type="double">
+ <_short>Hyperspace brightness</_short>
+ <_long>Brightness of the complete Hyperspace effect.</_long>
+ <default>0.85</default>
+ <min>0</min><max>2</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="hyperspace_surge" type="double">
+ <_short>Jump surge</_short>
+ <_long>Smooth acceleration during workspace transitions, easing back to continuous travel afterward. Zero keeps a steady speed.</_long>
+ <default>0.7</default>
+ <min>0</min><max>2</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="hyperspace_star_density" type="double">
+ <_short>Passing stars</_short>
+ <_long>Density of the nearby stars that stretch into fast trails.</_long>
+ <default>0.65</default>
+ <min>0</min><max>3</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="hyperspace_coloured_stars" type="double">
+ <_short>Coloured stars</_short>
+ <_long>Fraction of warm or blue stars in both layers. Most stars are white at the default 12%. Zero makes all stars white; one colours every star.</_long>
+ <default>0.12</default>
+ <min>0</min><max>1</max>
+ <precision>0.01</precision>
+ </option>
+ <option name="hyperspace_distant_stars" type="double">
+ <_short>Distant stars</_short>
+ <_long>Density of the faint distant stars behind the clouds. They remain points and never inherit the foreground jump surge.</_long>
+ <default>1</default>
+ <min>0</min><max>3</max>
+ <precision>0.05</precision>
+ </option>
+ <option name="hyperspace_distant_drift" type="double">
+ <_short>Distant star drift</_short>
+ <_long>Very slow drift of the distant starfield. Zero keeps distant stars stationary while nearby stars continue moving.</_long>
+ <default>0.1</default>
+ <min>0</min><max>1</max>
+ <precision>0.01</precision>
+ </option>
+ <option name="hyperspace_color" type="color">
+ <_short>Hyperspace colour</_short>
+ <_long>Tint of the clouds and light ribbons. White stars retain their neutral colour.</_long>
+ <default>0.20 0.52 1.0 1.0</default>
+ </option>
+ <option name="hyperspace_quality" type="int">
+ <_short>Hyperspace quality</_short>
+ <_long>Cloud resolution, cloud detail and star count. Stars always render at full output resolution.</_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="hyperspace_fps" type="int">
+ <_short>Hyperspace frame rate</_short>
+ <_long>Frame rate at rest or while mouse Cube is held still. Workspace transitions keep 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/cube.cpp
+++ b/plugins/cube/cube.cpp
@@ -32,6 +32,7 @@
#include "skydome.hpp"
#include "cubemap.hpp"
#include "warp-background.hpp"
+#include "hyperspace-background.hpp"
#include "cube-control-signal.hpp"
#include "wayfire/region.hpp"
#include "wayfire/scene-render.hpp"
@@ -450,44 +451,64 @@
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;
+ std::unique_ptr<wf_cube_hyperspace_background> hyperspace_background;
+ wf::wl_timer<true> background_timer;
wf::option_wrapper_t<std::string> background_mode{"cube/background_mode"};
wf::option_wrapper_t<double> backdrop_image_opacity;
wf::option_wrapper_t<bool> warp_animate_at_rest;
+ wf::option_wrapper_t<bool> hyperspace_animate_at_rest;
wf::option_wrapper_t<wf::color_t> backdrop_color{"cube/background"};
- bool warp_visible() const
+ bool procedural_background_active() const
{
return render_node && !resting_renderer && !cube_render_paused && !shutting_down &&
- std::string(background_mode) == "warp";
+ (std::string(background_mode) == "warp" || std::string(background_mode) == "hyperspace");
}
bool show_backdrop_image() const
{
return std::string(background_mode) != "none" &&
- double(backdrop_image_opacity) > 0 && !warp_visible();
- }
-
- bool warp_should_animate() const
- {
+ double(backdrop_image_opacity) > 0 && !procedural_background_active();
+ }
+
+ bool procedural_should_animate() const
+ {
+ const auto mode = std::string(background_mode);
+ const bool animate_at_rest = mode == "warp" ? bool(warp_animate_at_rest) :
+ mode == "hyperspace" && bool(hyperspace_animate_at_rest);
return render_node && !cube_render_paused && !shutting_down &&
- std::string(background_mode) == "warp" &&
- (!resting_renderer || (bool(warp_animate_at_rest) && double(backdrop_image_opacity) < 1));
- }
-
- void sync_warp_animation()
- {
- if (!warp_background) return;
- warp_background->set_active(warp_should_animate());
- if (!warp_background->animated())
- {
- warp_timer.disconnect();
- } else if (!warp_timer.is_connected())
- {
- warp_timer.set_timeout(warp_background->frame_interval(), [this]
- {
- if (!warp_should_animate() || !warp_background->animated()) return false;
+ (mode == "warp" || mode == "hyperspace") &&
+ (!resting_renderer || (animate_at_rest && double(backdrop_image_opacity) < 1));
+ }
+
+ bool background_animation_running() const
+ {
+ return (warp_background && warp_background->animated()) ||
+ (hyperspace_background && hyperspace_background->animated());
+ }
+
+ void sync_background_animation()
+ {
+ if (!warp_background || !hyperspace_background) return;
+ const auto mode = std::string(background_mode);
+ const bool enabled = procedural_should_animate();
+ warp_background->set_active(enabled && mode == "warp");
+ hyperspace_background->set_active(enabled && mode == "hyperspace");
+ // A workspace turn gently accelerates the backdrop. Mouse inspection
+ // retains a steady pace and never changes the Cube camera or input.
+ hyperspace_background->set_transition(!resting_renderer && !input_is_grabbed && !animation.in_exit &&
+ animation.cube_animation.running());
+ if (!background_animation_running())
+ {
+ background_timer.disconnect();
+ } else if (!background_timer.is_connected())
+ {
+ const unsigned interval = mode == "hyperspace" ? hyperspace_background->frame_interval() :
+ warp_background->frame_interval();
+ background_timer.set_timeout(interval, [this]
+ {
+ if (!procedural_should_animate() || !background_animation_running()) return false;
wf::scene::damage_node(render_node, render_node->get_bounding_box());
output->render->schedule_redraw();
return true;
@@ -527,7 +548,8 @@
} else if (last_background_mode == "cubemap")
{
background = std::make_unique<wf_cube_background_cubemap>();
- } else if (last_background_mode == "warp" || last_background_mode == "none")
+ } else if (last_background_mode == "warp" || last_background_mode == "hyperspace" ||
+ last_background_mode == "none")
{
background.reset();
} else
@@ -662,7 +684,7 @@
backdrop_image_opacity.load_option("cube/backdrop_image_opacity");
backdrop_image_opacity.set_callback([this]
{
- sync_warp_animation();
+ sync_background_animation();
output->render->damage_whole();
});
backdrop_color.set_callback([this] { output->render->damage_whole(); });
@@ -670,11 +692,19 @@
warp_animate_at_rest.load_option("cube/warp_animate_at_rest");
warp_animate_at_rest.set_callback([this]
{
- sync_warp_animation();
+ sync_background_animation();
+ output->render->damage_whole();
+ });
+ ensure_warp_option<bool>("hyperspace_animate_at_rest", true);
+ hyperspace_animate_at_rest.load_option("cube/hyperspace_animate_at_rest");
+ hyperspace_animate_at_rest.set_callback([this]
+ {
+ sync_background_animation();
output->render->damage_whole();
});
ensure_warp_option<double>("warp_speed", 0.8);
ensure_warp_option<double>("warp_density", 1.0);
+ ensure_warp_option<double>("warp_coloured_stars", 0.12);
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);
@@ -683,16 +713,33 @@
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();
+ ensure_warp_option<double>("hyperspace_speed", 0.65);
+ ensure_warp_option<double>("hyperspace_cloud_density", 0.85);
+ ensure_warp_option<double>("hyperspace_turbulence", 0.65);
+ ensure_warp_option<double>("hyperspace_ribbon_strength", 0.75);
+ ensure_warp_option<double>("hyperspace_glow", 0.65);
+ ensure_warp_option<double>("hyperspace_brightness", 0.85);
+ ensure_warp_option<double>("hyperspace_surge", 0.70);
+ ensure_warp_option<double>("hyperspace_star_density", 0.65);
+ ensure_warp_option<double>("hyperspace_coloured_stars", 0.12);
+ ensure_warp_option<double>("hyperspace_distant_stars", 1.0);
+ ensure_warp_option<double>("hyperspace_distant_drift", 0.10);
+ ensure_warp_option<wf::color_t>("hyperspace_color", wf::color_t{0.20, 0.52, 1.0, 1.0});
+ ensure_warp_option<int>("hyperspace_quality", 1);
+ ensure_warp_option<int>("hyperspace_fps", 30);
+ auto background_changed = [this]
+ {
+ background_timer.disconnect();
+ sync_background_animation();
output->render->damage_whole();
- });
+ };
+ warp_background = std::make_unique<wf_cube_warp_background>(background_changed);
+ hyperspace_background = std::make_unique<wf_cube_hyperspace_background>(background_changed);
background_mode.set_callback([this]
{
reload_background();
- sync_warp_animation();
+ background_timer.disconnect();
+ sync_background_animation();
output->render->damage_whole();
});
input_grab = std::make_unique<wf::input_grab_t>("cube", output, nullptr, this, nullptr);
@@ -1007,7 +1054,7 @@
if (render_node) wf::scene::remove_child(render_node);
render_node = nullptr;
resting_renderer = false;
- sync_warp_animation();
+ sync_background_animation();
output->render->set_require_depth_buffer(false);
clear_unused_fixed_top_node();
output->render->damage_whole();
@@ -1040,7 +1087,7 @@
update_view_matrix();
render_node = std::make_shared<cube_render_node_t>(this);
add_cube_render_node();
- sync_warp_animation();
+ sync_background_animation();
output->render->add_effect(&pre_hook, wf::OUTPUT_EFFECT_PRE);
output->render->set_require_depth_buffer(true);
output->render->damage_whole();
@@ -1063,7 +1110,7 @@
output->render->damage_whole();
}
cube_render_paused = true;
- sync_warp_animation();
+ sync_background_animation();
return;
}
@@ -1225,7 +1272,7 @@
output->render->set_require_depth_buffer(true);
reload_background();
- sync_warp_animation();
+ sync_background_animation();
animation.cube_animation.offset_z.set(identity_z_offset + front_face_distance(),
identity_z_offset + front_face_distance());
return true;
@@ -1251,7 +1298,7 @@
render_node = nullptr;
output->render->rem_effect(&pre_hook);
- sync_warp_animation();
+ sync_background_animation();
output->render->set_require_depth_buffer(false);
// Vswitch already committed its destination before starting this
@@ -1630,11 +1677,15 @@
// Fill the pixels withheld from the wallpaper pass before drawing
// the faces. Never fade windows or foreground desktop surfaces.
const bool no_background = std::string(background_mode) == "none";
- const float opacity = (no_background || warp_visible()) ? 1.0f :
+ const float opacity = (no_background || procedural_background_active()) ? 1.0f :
1.0f - std::clamp(double(backdrop_image_opacity), 0.0, 1.0);
if (opacity > 0 && std::string(background_mode) == "warp")
{
warp_background->render(data.target, data.damage,
+ wf::dimensions(output->get_relative_geometry()), opacity);
+ } else if (opacity > 0 && std::string(background_mode) == "hyperspace")
+ {
+ hyperspace_background->render(data.target, data.damage,
wf::dimensions(output->get_relative_geometry()), opacity);
} else if (opacity > 0)
{
@@ -1723,7 +1774,7 @@
}
update_view_matrix();
- sync_warp_animation();
+ sync_background_animation();
const bool running = animation.cube_animation.running();
if (render_node && (running || animation_was_running))
{
@@ -1904,7 +1955,7 @@
void fini() override
{
shutting_down = true;
- warp_timer.disconnect();
+ background_timer.disconnect();
clear_post_move_window_dim();
if (output->is_plugin_active(grab_interface.name))
{
@@ -1917,6 +1968,7 @@
program.free_resources();
});
warp_background.reset();
+ hyperspace_background.reset();
}
};
--- /dev/null
+++ b/plugins/cube/hyperspace-background.cpp
@@ -0,0 +1,202 @@
+#include "hyperspace-background.hpp"
+#include "hyperspace-shaders.tpp"
+#include <algorithm>
+#include <cmath>
+#include <cstddef>
+#include <cstdint>
+#include <vector>
+
+namespace
+{
+struct hyperspace_star_t
+{
+ float seed[4];
+ float corner[2];
+};
+
+float star_random(uint32_t value)
+{
+ value ^= value >> 16;
+ value *= 0x7feb352du;
+ value ^= value >> 15;
+ value *= 0x846ca68bu;
+ value ^= value >> 16;
+ return (value & 0x00ffffffu) / 16777216.0f;
+}
+}
+
+wf_cube_hyperspace_background::wf_cube_hyperspace_background(std::function<void()> changed)
+{
+ auto update = [this, changed] { cloud_dirty = backdrop_dirty = true; changed(); };
+ speed.set_callback(update); clouds.set_callback(update); turbulence.set_callback(update);
+ ribbons.set_callback(update); glow.set_callback(update); brightness.set_callback(update);
+ surge.set_callback(update); density.set_callback(update); coloured.set_callback(update);
+ distant_density.set_callback(update); distant_drift.set_callback(update);
+ tint.set_callback(update); quality.set_callback(update); fps.set_callback(update);
+ last_frame = std::chrono::steady_clock::now();
+}
+
+wf_cube_hyperspace_background::~wf_cube_hyperspace_background()
+{
+ wf::gles::run_in_context_if_gles([&]
+ {
+ cloud_program.free_resources(); star_program.free_resources();
+ cloud_buffer.free(); backdrop_buffer.free();
+ if (star_buffer) { GL_CALL(glDeleteBuffers(1, &star_buffer)); }
+ });
+}
+
+void wf_cube_hyperspace_background::set_active(bool enabled)
+{
+ if (active != enabled) last_frame = std::chrono::steady_clock::now();
+ active = enabled;
+}
+
+void wf_cube_hyperspace_background::set_transition(bool moving)
+{
+ transition = moving;
+}
+
+bool wf_cube_hyperspace_background::animated() const { return active && double(speed) > 0; }
+
+unsigned wf_cube_hyperspace_background::frame_interval() const
+{
+ return unsigned(std::ceil(1000.0 / std::clamp(int(fps), 10, 120)));
+}
+
+void wf_cube_hyperspace_background::load_programs()
+{
+ if (!cloud_program.get_program_id(wf::TEXTURE_TYPE_RGBA))
+ cloud_program.set_simple(OpenGL::compile_program(hyperspace_vertex, hyperspace_cloud_fragment));
+ if (!star_program.get_program_id(wf::TEXTURE_TYPE_RGBA))
+ star_program.set_simple(OpenGL::compile_program(hyperspace_star_vertex, hyperspace_star_fragment));
+}
+
+void wf_cube_hyperspace_background::update_particles()
+{
+ const int near_counts[] = {768, 2048, 4096}, far_counts[] = {1024, 2560, 5120};
+ int level = std::clamp(int(quality), 0, 2);
+ int near = int(near_counts[level] * std::clamp(double(density), 0.0, 3.0));
+ int far = int(far_counts[level] * std::clamp(double(distant_density), 0.0, 3.0));
+ if (near == near_count && far == far_count) return;
+ near_count = near; far_count = far;
+ std::vector<hyperspace_star_t> vertices;
+ vertices.reserve((near + far) * 6);
+ const float corners[6][2] = {{0,-1},{1,-1},{1,1},{0,-1},{1,1},{0,1}};
+ // Independent seeds retain both populations when either density changes.
+ for (int layer = 0; layer < 2; ++layer)
+ for (int i = 0; i < (layer ? near : far); ++i)
+ {
+ uint32_t base = i * 4 + (layer ? 7183 : 419);
+ float seed[] = {2 * star_random(base) - 1, 2 * star_random(base + 1) - 1,
+ star_random(base + 2), star_random(base + 3)};
+ 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(hyperspace_star_t), vertices.data(), GL_STATIC_DRAW));
+ GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, 0));
+}
+
+void wf_cube_hyperspace_background::render(const wf::render_target_t& target,
+ const wf::regionf_t& damage, wf::dimensions_t resolution, float opacity)
+{
+ const auto now = std::chrono::steady_clock::now();
+ const double dt = std::clamp(std::chrono::duration<double>(now - last_frame).count(), 0.0, 0.25);
+ rendered_speed = std::clamp(double(speed), 0.0, 5.0) * (1 + boost * std::clamp(double(surge), 0.0, 2.0) * 3);
+ if (animated())
+ {
+ boost += ((transition ? 1.0 : 0.0) - boost) * (1 - std::exp(-dt / (transition ? 0.18 : 0.55)));
+ rendered_speed = std::clamp(double(speed), 0.0, 5.0) * (1 + boost * std::clamp(double(surge), 0.0, 2.0) * 3);
+ const double advance = dt * rendered_speed * 1.8;
+ travel = std::fmod(travel + advance, 12.0);
+ cloud_phase = std::fmod(cloud_phase + advance * 0.55, 64.0);
+ // Distant stars never inherit the jump surge or foreground velocity.
+ drift_phase = std::fmod(drift_phase + dt * double(speed) *
+ std::clamp(double(distant_drift), 0.0, 1.0) * 0.04, 2 * M_PI);
+ cloud_dirty = backdrop_dirty = true;
+ }
+ last_frame = now;
+ load_programs(); update_particles();
+ const int level = std::clamp(int(quality), 0, 2);
+ const float scales[] = {0.25f, 1.0f / 3, 0.5f};
+ const float cloud_scale = scales[level] * target.scale;
+ if (cloud_buffer.allocate(resolution, cloud_scale) == wf::buffer_reallocation_result_t::REALLOCATED)
+ cloud_dirty = backdrop_dirty = true;
+ if (backdrop_buffer.allocate(resolution, target.scale) == wf::buffer_reallocation_result_t::REALLOCATED)
+ backdrop_dirty = true;
+ wf::geometry_t box{0,0,double(resolution.width),double(resolution.height)};
+ 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);
+ GL_CALL(glDisable(GL_DEPTH_TEST)); GL_CALL(glDisable(GL_CULL_FACE));
+ if (cloud_dirty)
+ {
+ wf::render_target_t cloud_target{cloud_buffer}; cloud_target.geometry = box;
+ cloud_target.scale = cloud_scale;
+ wf::gles::bind_render_buffer(cloud_target);
+ GL_CALL(glDisable(GL_BLEND));
+ cloud_program.use(wf::TEXTURE_TYPE_RGBA);
+ cloud_program.uniformMatrix4f("mvp", wf::gles::render_target_orthographic_projection(cloud_target));
+ cloud_program.uniform2f("resolution", width, height);
+ cloud_program.uniform1f("phase", cloud_phase);
+ cloud_program.uniform1f("cloud_density", std::clamp(double(clouds), 0.0, 2.0));
+ cloud_program.uniform1f("turbulence", std::clamp(double(turbulence), 0.0, 2.0));
+ cloud_program.uniform1f("ribbons", std::clamp(double(ribbons), 0.0, 2.0));
+ cloud_program.uniform1f("glow", std::clamp(double(glow), 0.0, 2.0));
+ cloud_program.uniform1f("brightness", std::clamp(double(brightness), 0.0, 2.0));
+ cloud_program.uniform1f("energy", 1 + boost * double(surge) * 0.20);
+ cloud_program.uniform3f("tint", color.r, color.g, color.b);
+ cloud_program.uniform1i("detail", level);
+ cloud_program.attrib_pointer("position", 2, 0, quad);
+ wf::gles::for_each_scissor_rect(cloud_target, box, [&] { GL_CALL(glDrawArrays(GL_TRIANGLES,0,6)); });
+ cloud_program.deactivate();
+ cloud_dirty = false;
+ }
+ wf::render_target_t backdrop_target{backdrop_buffer};
+ backdrop_target.geometry = box; backdrop_target.scale = target.scale;
+ auto draw_stars = [&] (bool distant)
+ {
+ const int count = distant ? far_count : near_count;
+ if (!count) return;
+ star_program.use(wf::TEXTURE_TYPE_RGBA);
+ star_program.uniformMatrix4f("mvp", wf::gles::render_target_orthographic_projection(backdrop_target));
+ star_program.uniform2f("resolution", width, height);
+ star_program.uniform1f("travel", travel); star_program.uniform1f("speed", rendered_speed);
+ star_program.uniform1f("drift", drift_phase);
+ star_program.uniform1f("brightness", std::clamp(double(brightness), 0.0, 2.0));
+ star_program.uniform1f("coloured_stars", std::clamp(double(coloured), 0.0, 1.0));
+ star_program.uniform1f("glow", std::clamp(double(glow), 0.0, 2.0));
+ star_program.uniform1f("backdrop_opacity", 1.0);
+ star_program.uniform1i("distant", distant ? 1 : 0);
+ GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, star_buffer));
+ star_program.attrib_pointer("seed",4,sizeof(hyperspace_star_t),reinterpret_cast<void*>(offsetof(hyperspace_star_t,seed)));
+ star_program.attrib_pointer("corner",2,sizeof(hyperspace_star_t),reinterpret_cast<void*>(offsetof(hyperspace_star_t,corner)));
+ GL_CALL(glEnable(GL_BLEND)); GL_CALL(glBlendFunc(GL_ONE,GL_ONE));
+ wf::gles::for_each_scissor_rect(backdrop_target,box,[&]
+ { GL_CALL(glDrawArrays(GL_TRIANGLES,distant ? 0 : far_count * 6,count * 6)); });
+ GL_CALL(glDisable(GL_BLEND)); star_program.deactivate(); GL_CALL(glBindBuffer(GL_ARRAY_BUFFER,0));
+ };
+ if (backdrop_dirty)
+ {
+ wf::gles::bind_render_buffer(backdrop_target);
+ wf::gles::for_each_scissor_rect(backdrop_target,box,[&] { OpenGL::clear({0,0,0,1}); });
+ draw_stars(true);
+ auto clouds = wf::gles_texture_t::from_aux(cloud_buffer);
+ wf::gles::for_each_scissor_rect(backdrop_target,box,[&]
+ { OpenGL::render_texture(clouds,backdrop_target,box); });
+ GL_CALL(glDisable(GL_BLEND));
+ draw_stars(false);
+ backdrop_dirty = false;
+ }
+ // Composite once so 50% opacity really is half of the complete effect,
+ // including the stars behind the absorbing clouds. Reuse frozen frames.
+ wf::gles::bind_render_buffer(target);
+ auto texture = wf::gles_texture_t::from_aux(backdrop_buffer);
+ wf::gles::for_each_scissor_rect(target, damage, [&]
+ {
+ OpenGL::render_texture(texture,target,box,glm::vec4(1,1,1,opacity));
+ });
+ GL_CALL(glDisable(GL_BLEND));
+}
--- /dev/null
+++ b/plugins/cube/hyperspace-background.hpp
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <wayfire/option-wrapper.hpp>
+#include <wayfire/opengl.hpp>
+#include <chrono>
+#include <functional>
+
+// A self-contained procedural backdrop: reduced-resolution cloud shells,
+// slowly drifting distant stars and full-resolution foreground trails.
+class __attribute__((visibility("hidden"))) wf_cube_hyperspace_background
+{
+ wf::option_wrapper_t<double> speed{"cube/hyperspace_speed"};
+ wf::option_wrapper_t<double> clouds{"cube/hyperspace_cloud_density"};
+ wf::option_wrapper_t<double> turbulence{"cube/hyperspace_turbulence"};
+ wf::option_wrapper_t<double> ribbons{"cube/hyperspace_ribbon_strength"};
+ wf::option_wrapper_t<double> glow{"cube/hyperspace_glow"};
+ wf::option_wrapper_t<double> brightness{"cube/hyperspace_brightness"};
+ wf::option_wrapper_t<double> surge{"cube/hyperspace_surge"};
+ wf::option_wrapper_t<double> density{"cube/hyperspace_star_density"};
+ wf::option_wrapper_t<double> coloured{"cube/hyperspace_coloured_stars"};
+ wf::option_wrapper_t<double> distant_density{"cube/hyperspace_distant_stars"};
+ wf::option_wrapper_t<double> distant_drift{"cube/hyperspace_distant_drift"};
+ wf::option_wrapper_t<wf::color_t> tint{"cube/hyperspace_color"};
+ wf::option_wrapper_t<int> quality{"cube/hyperspace_quality"};
+ wf::option_wrapper_t<int> fps{"cube/hyperspace_fps"};
+ OpenGL::program_t cloud_program, star_program;
+ wf::auxilliary_buffer_t cloud_buffer, backdrop_buffer;
+ GLuint star_buffer = 0;
+ int near_count = -1, far_count = -1;
+ bool active = false, transition = false, cloud_dirty = true, backdrop_dirty = true;
+ double travel = 0, cloud_phase = 0, drift_phase = 0, boost = 0;
+ double rendered_speed = 0;
+ std::chrono::steady_clock::time_point last_frame;
+
+ void load_programs();
+ void update_particles();
+
+ public:
+ explicit wf_cube_hyperspace_background(std::function<void()> changed);
+ ~wf_cube_hyperspace_background();
+ void set_active(bool enabled);
+ void set_transition(bool moving);
+ bool animated() const;
+ unsigned frame_interval() const;
+ void render(const wf::render_target_t& target, const wf::regionf_t& damage,
+ wf::dimensions_t resolution, float opacity = 1.0f);
+};
--- /dev/null
+++ b/plugins/cube/hyperspace-shaders.tpp
@@ -0,0 +1,142 @@
+static const char *hyperspace_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 *hyperspace_cloud_fragment = R"(
+#version 100
+precision highp float;
+uniform vec2 resolution;
+uniform vec3 tint;
+uniform float phase, cloud_density, turbulence, ribbons, glow, brightness, energy;
+uniform int detail;
+varying vec2 uv;
+
+float hash3(vec3 p)
+{
+ // Repeat every 64 cells, including octave-scaled coordinates. The CPU
+ // clock can wrap without a seam or lost precision after hours of travel.
+ p = mod(p,64.0);
+ p = fract(p * vec3(0.1031,0.1030,0.0973));
+ p += dot(p,p.yxz + 33.33);
+ return fract((p.x + p.y) * p.z);
+}
+float noise3(vec3 p)
+{
+ vec3 c = floor(p), f = fract(p); f = f*f*(3.0-2.0*f);
+ return mix(mix(mix(hash3(c),hash3(c+vec3(1,0,0)),f.x),
+ mix(hash3(c+vec3(0,1,0)),hash3(c+vec3(1,1,0)),f.x),f.y),
+ mix(mix(hash3(c+vec3(0,0,1)),hash3(c+vec3(1,0,1)),f.x),
+ mix(hash3(c+vec3(0,1,1)),hash3(c+vec3(1,1,1)),f.x),f.y),f.z);
+}
+float fbm(vec3 p)
+{
+ float result=0.0, amplitude=0.55;
+ for (int i=0;i<5;i++)
+ {
+ if (i < detail+3) result += noise3(p)*amplitude;
+ p=p*2.0+vec3(7,13,19); amplitude*=0.5;
+ }
+ return result;
+}
+void main()
+{
+ vec2 p=(uv-0.5)*vec2(resolution.x/resolution.y,1.0)*2.0;
+ float r=length(p), angle=atan(p.y,p.x);
+ float depth=2.6/max(r,0.085);
+ vec2 cylinder=vec2(cos(angle),sin(angle));
+ vec3 shell=vec3(cylinder*2.4,depth*0.55+phase);
+ float bend=(noise3(vec3(shell.xy*0.5,shell.z))*2.0-1.0)*turbulence;
+ float mist=fbm(shell+vec3(cylinder*bend,bend));
+ float inner=fbm(vec3(cylinder*3.8,depth*0.85+phase*2.0)+vec3(11,23,7));
+ float centre=smoothstep(0.045,0.35,r);
+ float edge=1.0/(1.0+r*r*0.08);
+ float clouds=smoothstep(0.27,0.76,mist)*cloud_density;
+ float veils=smoothstep(0.34,0.86,inner)*cloud_density;
+ float ribbon_angle=angle*9.0+depth*0.075+bend*1.6;
+ float ribbon=pow(max(0.0,0.5+0.5*cos(ribbon_angle)),24.0);
+ ribbon*=0.15+0.85*smoothstep(0.24,0.84,inner);
+ vec3 ice=mix(tint,vec3(0.72,0.88,1.0),0.22);
+ vec3 violet=mix(tint,vec3(0.34,0.22,0.60),0.20);
+ vec3 color=(tint*clouds*0.16+violet*veils*0.085+ice*ribbon*ribbons*0.20)*centre*edge;
+ // Soft destination light and a broad halo, without a flashing jump cut.
+ float halo=exp(-r*r*2.8), core=exp(-r*r*140.0);
+ color+=(ice*halo*0.055+vec3(0.86,0.94,1.0)*core*0.40)*glow;
+ color*=brightness*energy;
+ color=vec3(1.0)-exp(-color);
+ float absorption=clamp((clouds*0.36+veils*0.16)*centre*edge,0.0,0.85);
+ gl_FragColor=vec4(color,absorption);
+}
+)";
+
+static const char *hyperspace_star_vertex = R"(
+#version 100
+precision highp float;
+attribute vec4 seed;
+attribute vec2 corner;
+uniform mat4 mvp;
+uniform vec2 resolution;
+uniform float travel, speed, drift, brightness, coloured_stars;
+uniform int distant;
+varying vec2 local;
+varying float trail_length, radius, luminosity;
+varying vec3 star_color;
+void main()
+{
+ vec2 head,tail;
+ float pixel_scale=clamp(resolution.y/1080.0,0.65,2.0);
+ if (distant==1)
+ {
+ vec2 offset=vec2(sin(drift),cos(drift)-1.0)*resolution.y*0.07;
+ head=mod((seed.xy*0.5+0.5)*resolution+offset,resolution)-resolution*0.5;
+ tail=head;
+ radius=(0.65+1.0*seed.w*seed.w)*pixel_scale;
+ luminosity=brightness*(0.18+0.72*pow(seed.w,3.0))*(0.94+0.06*sin(drift*8.0+seed.z*50.0));
+ } else
+ {
+ float z=mod(seed.z*12.0-travel,12.0)+0.45;
+ vec2 world=seed.xy*vec2(resolution.x/resolution.y,1.0)*6.0;
+ head=world/z*resolution.y*0.5;
+ tail=world/(z+speed*0.42)*resolution.y*0.5;
+ radius=(1.0+2.0*pow(seed.w,3.0))*pixel_scale*(0.7+1.0/(z+0.5));
+ float fade=smoothstep(0.45,0.9,z)*(1.0-smoothstep(11.0,12.45,z));
+ luminosity=brightness*fade*(0.35+1.25*pow(seed.w,4.0));
+ }
+ vec2 direction=normalize(head-tail+vec2(0.00001)), normal=vec2(-direction.y,direction.x);
+ trail_length=min(length(head-tail),resolution.y*0.35);
+ tail=head-direction*trail_length;
+ 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 chance=fract(seed.w*31.37), spectral=fract(seed.w*17.0);
+ star_color=vec3(1.0);
+ if (chance<coloured_stars)
+ star_color=spectral<0.12 ? vec3(1.0,0.50,0.32) :
+ (spectral<0.40 ? vec3(1.0,0.86,0.62) : vec3(0.60,0.78,1.0));
+}
+)";
+
+static const char *hyperspace_star_fragment = R"(
+#version 100
+precision highp float;
+uniform float glow,backdrop_opacity;
+varying vec2 local;
+varying float trail_length,radius,luminosity;
+varying vec3 star_color;
+void main()
+{
+ vec2 head=vec2(local.x-trail_length,local.y)/radius;
+ float along=clamp(local.x/max(trail_length,0.01),0.0,1.0);
+ float end=max(max(-local.x,local.x-trail_length),0.0);
+ float d=(local.y*local.y+end*end)/(radius*radius);
+ float core=exp(-dot(head,head)*18.0);
+ float trail=exp(-d*15.0)*(0.10+0.65*along);
+ float halo=exp(-d*4.0)*0.16*glow;
+ float edge=1.0-smoothstep(0.75,1.0,d);
+ gl_FragColor=vec4(star_color*luminosity*(core+trail+halo)*edge*backdrop_opacity,0.0);
+}
+)";
--- 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', 'warp-background.cpp'],
+ ['cube.cpp', 'cubemap.cpp', 'skydome.cpp', 'simple-background.cpp', 'warp-background.cpp', 'hyperspace-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/plugins/cube/warp-background.cpp
+++ b/plugins/cube/warp-background.cpp
@@ -29,6 +29,7 @@
{
speed.set_callback(changed);
density.set_callback(changed);
+ coloured.set_callback(changed);
streaks.set_callback(changed);
glow.set_callback(changed);
brightness.set_callback(changed);
@@ -154,6 +155,7 @@
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));
+ star_program.uniform1f("coloured_stars", std::clamp(double(coloured), 0.0, 1.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)));
--- a/plugins/cube/warp-background.hpp
+++ b/plugins/cube/warp-background.hpp
@@ -11,6 +11,7 @@
{
wf::option_wrapper_t<double> speed{"cube/warp_speed"};
wf::option_wrapper_t<double> density{"cube/warp_density"};
+ wf::option_wrapper_t<double> coloured{"cube/warp_coloured_stars"};
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"};
--- a/plugins/cube/warp-shaders.tpp
+++ b/plugins/cube/warp-shaders.tpp
@@ -63,7 +63,7 @@
attribute vec2 corner;
uniform mat4 mvp;
uniform vec2 resolution;
-uniform float travel, speed, streaks, brightness, twist, orientation, twinkle;
+uniform float travel, speed, streaks, brightness, twist, orientation, twinkle, coloured_stars;
uniform vec3 tint;
varying vec2 local;
varying float trail_length, radius, luminosity;
@@ -92,7 +92,7 @@
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);
+ star_color = fract(seed.w * 31.37) < coloured_stars ? mix(natural, tint, 0.14) : vec3(1.0);
}
)";
|