Debian Codegraph @

screensaver.shadertoy/resources/shaders/realityplasma.frag.glsl

raw
1 // from https://www.shadertoy.com/view/MdBGzK
2
3 #define DPII (3.1415926535*2.0)
4 // The original code had a "pompota" function that would toggle the VGA horizontal scroll offset each frame between
5 // values of 0 and 4, as well as toggle the vertical start position between 60 and 61. This effect doesn't seem to
6 // work that well now, so it has been disabled.
7 #define POMPOTA 0
8
9 int GetPerPlasmaTime(int t)
10 {
11 // Get the time since this plasma started using the total time.
12 // Times for each plasma are (from the timetable array): 723, 1491, 1875, 2259, 2278.
13 // (64 is added to each time because it takes 64 frames to drop the current plasma offscreen
14 // before switching to the new one.)
15
16 if (t < 723 + 64)
17 {
18 }
19 else if (t < 1491 + 64)
20 {
21 t -= 723 + 64;
22 }
23 else if (t < 1875 + 64)
24 {
25 t -= 1491 + 64;
26 }
27 else if (t < 2259 + 64)
28 {
29 t -= 1875 + 64;
30 }
31 else if (t < 2278 + 64)
32 {
33 t -= 2259 + 64;
34 }
35 else
36 {
37 t = 0;
38 }
39
40 return t;
41 }
42
43 int GetPlasmaIndex(int t)
44 {
45 int nPlasmaIndex = 0;
46
47 if (t < 723 + 64)
48 {
49 nPlasmaIndex = 0;
50 }
51 else if (t < 1491 + 64)
52 {
53 nPlasmaIndex = 1;
54 }
55 else if (t < 1875 + 64)
56 {
57 nPlasmaIndex = 2;
58 }
59 else if (t < 2259 + 64)
60 {
61 nPlasmaIndex = 3;
62 }
63 else if (t < 2278 + 64)
64 {
65 nPlasmaIndex = 4;
66 }
67 else
68 {
69 nPlasmaIndex = 5;
70 }
71
72 return nPlasmaIndex;
73 }
74
75 int GetXOffset(int t)
76 {
77 #if POMPOTA == 1
78 int nResult = 4;
79 float fT = float(t);
80 int nMod = int(mod(fT, 2.0));
81 if (nMod != 0)
82 {
83 nResult = 0;
84 }
85 return nResult;
86 #else //POMPOTA == 1
87 return 0;
88 #endif //POMPOTA == 1
89 }
90
91 int GetYOffset(int t)
92 {
93 int nResult = 60;
94 bool bDrop = false;
95
96 if ((t >= 723) && (t < (723 + 64)))
97 {
98 t -= 723;
99 bDrop = true;
100 }
101 else if ((t >= 1491) && (t < (1491 + 64)))
102 {
103 t -= 1491;
104 bDrop = true;
105 }
106 else if ((t >= 1875) && (t < (1875 + 64)))
107 {
108 t -= 1875;
109 bDrop = true;
110 }
111 else if ((t >= 2259) && (t < (2259 + 64)))
112 {
113 t -= 2259;
114 bDrop = true;
115 }
116
117 if (bDrop)
118 {
119 nResult = t * t / 4 * 43 / 128 + 60;
120 }
121 #if POMPOTA == 1
122 else
123 {
124 float fT = float(t);
125 int nMod = int(mod(fT, 2.0));
126 if (nMod != 0)
127 {
128 nResult = 61;
129 }
130 }
131 #endif //POMPOTA == 1
132
133 return nResult;
134 }
135
136 float FadeColourComponent(float c, int t)
137 {
138 float fResult = c;
139 float fProportion = 0.0;
140
141 if ((t >= 0) && (t < 128))
142 {
143 // For plasma 1, fade from white to the palette.
144 fProportion = float(t) / 127.0;
145 fResult = (fProportion * c) + ((1.0 - fProportion) * 1.0);
146 }
147 else if ((t >= (723 + 64)) && (t < (723 + 64 + 32)))
148 {
149 // For plasma 2, fade from black to the palette.
150 fProportion = float(t - 723 - 64) / 31.0;
151 fResult = (fProportion * c) + ((1.0 - fProportion) * 0.0);
152 }
153 else if ((t >= (1491 + 64)) && (t < (1491 + 64 + 32)))
154 {
155 // For plasma 3, fade from black to the palette.
156 fProportion = float(t - 1491 - 64) / 31.0;
157 fResult = (fProportion * c) + ((1.0 - fProportion) * 0.0);
158 }
159 else if ((t >= (1875 + 64)) && (t < (1875 + 64 + 32)))
160 {
161 // For plasma 4, fade from black to the palette.
162 fProportion = float(t - 1875 - 64) / 31.0;
163 fResult = (fProportion * c) + ((1.0 - fProportion) * 0.0);
164 }
165
166 return fResult;
167 }
168
169 int GetInitialL1(int nPlasmaIndex)
170 {
171 if (nPlasmaIndex == 0)
172 {
173 return 1000;
174 }
175 else if (nPlasmaIndex == 1)
176 {
177 return 1000;
178 }
179 else if (nPlasmaIndex == 2)
180 {
181 return 3500;
182 }
183 else if (nPlasmaIndex == 3)
184 {
185 return 1000;
186 }
187 else if (nPlasmaIndex == 4)
188 {
189 return 1000;
190 }
191 else
192 {
193 return 1000;
194 }
195 }
196 int GetInitialL2(int nPlasmaIndex)
197 {
198 if (nPlasmaIndex == 0)
199 {
200 return 2000;
201 }
202 else if (nPlasmaIndex == 1)
203 {
204 return 2000;
205 }
206 else if (nPlasmaIndex == 2)
207 {
208 return 1000;
209 }
210 else if (nPlasmaIndex == 3)
211 {
212 return 2000;
213 }
214 else if (nPlasmaIndex == 4)
215 {
216 return 2000;
217 }
218 else
219 {
220 return 2000;
221 }
222 }
223 int GetInitialL3(int nPlasmaIndex)
224 {
225 if (nPlasmaIndex == 0)
226 {
227 return 3000;
228 }
229 else if (nPlasmaIndex == 1)
230 {
231 return 4000;
232 }
233 else if (nPlasmaIndex == 2)
234 {
235 return 3000;
236 }
237 else if (nPlasmaIndex == 3)
238 {
239 return 3000;
240 }
241 else if (nPlasmaIndex == 4)
242 {
243 return 3000;
244 }
245 else
246 {
247 return 3000;
248 }
249 }
250 int GetInitialL4(int nPlasmaIndex)
251 {
252 if (nPlasmaIndex == 0)
253 {
254 return 4000;
255 }
256 else if (nPlasmaIndex == 1)
257 {
258 return 4000;
259 }
260 else if (nPlasmaIndex == 2)
261 {
262 return 1000;
263 }
264 else if (nPlasmaIndex == 3)
265 {
266 return 4000;
267 }
268 else if (nPlasmaIndex == 4)
269 {
270 return 4000;
271 }
272 else
273 {
274 return 4000;
275 }
276 }
277 int GetInitialK1(int nPlasmaIndex)
278 {
279 if (nPlasmaIndex == 0)
280 {
281 return 3500;
282 }
283 else if (nPlasmaIndex == 1)
284 {
285 return 1500;
286 }
287 else if (nPlasmaIndex == 2)
288 {
289 return 3500;
290 }
291 else if (nPlasmaIndex == 3)
292 {
293 return 3500;
294 }
295 else if (nPlasmaIndex == 4)
296 {
297 return 3500;
298 }
299 else
300 {
301 return 3500;
302 }
303 }
304 int GetInitialK2(int nPlasmaIndex)
305 {
306 if (nPlasmaIndex == 0)
307 {
308 return 2300;
309 }
310 else if (nPlasmaIndex == 1)
311 {
312 return 2300;
313 }
314 else if (nPlasmaIndex == 2)
315 {
316 return 3300;
317 }
318 else if (nPlasmaIndex == 3)
319 {
320 return 2300;
321 }
322 else if (nPlasmaIndex == 4)
323 {
324 return 2300;
325 }
326 else
327 {
328 return 2300;
329 }
330 }
331 int GetInitialK3(int nPlasmaIndex)
332 {
333 if (nPlasmaIndex == 0)
334 {
335 return 3900;
336 }
337 else if (nPlasmaIndex == 1)
338 {
339 return 3900;
340 }
341 else if (nPlasmaIndex == 2)
342 {
343 return 2900;
344 }
345 else if (nPlasmaIndex == 3)
346 {
347 return 3900;
348 }
349 else if (nPlasmaIndex == 4)
350 {
351 return 3900;
352 }
353 else
354 {
355 return 3900;
356 }
357 }
358 int GetInitialK4(int nPlasmaIndex)
359 {
360 if (nPlasmaIndex == 0)
361 {
362 return 3670;
363 }
364 else if (nPlasmaIndex == 1)
365 {
366 return 1670;
367 }
368 else if (nPlasmaIndex == 2)
369 {
370 return 2670;
371 }
372 else if (nPlasmaIndex == 3)
373 {
374 return 3670;
375 }
376 else if (nPlasmaIndex == 4)
377 {
378 return 3670;
379 }
380 else
381 {
382 return 3670;
383 }
384 }
385
386 int GetC1(int nXOffset0or1, int t)
387 {
388 int nPlasmaIndex = GetPlasmaIndex(t);
389 t = GetPerPlasmaTime(t);
390
391 int nResult = 0;
392 if (nXOffset0or1 == 0)
393 {
394 nResult = GetInitialK1(nPlasmaIndex) + (-3 * t);
395 }
396 else
397 {
398 nResult = GetInitialL1(nPlasmaIndex) + (-1 * t);
399 }
400
401 float fResult = float(nResult);
402 fResult = mod(fResult, 4096.0);
403
404 if (fResult < 0.0)
405 {
406 fResult += 4096.0;
407 }
408 nResult = int(fResult);
409
410 return nResult;
411 }
412
413 int GetC2(int nXOffset0or1, int t)
414 {
415 int nPlasmaIndex = GetPlasmaIndex(t);
416 t = GetPerPlasmaTime(t);
417
418 int nResult = 0;
419 if (nXOffset0or1 == 0)
420 {
421 nResult = GetInitialK2(nPlasmaIndex) + (-2 * t);
422 }
423 else
424 {
425 nResult = GetInitialL2(nPlasmaIndex) + (-2 * t);
426 }
427
428 float fResult = float(nResult);
429 fResult = mod(fResult, 4096.0);
430
431 if (fResult < 0.0)
432 {
433 fResult += 4096.0;
434 }
435 nResult = int(fResult);
436
437 return nResult;
438 }
439
440 int GetC3(int nXOffset0or1, int t)
441 {
442 int nPlasmaIndex = GetPlasmaIndex(t);
443 t = GetPerPlasmaTime(t);
444
445 int nResult = 0;
446 if (nXOffset0or1 == 0)
447 {
448 nResult = GetInitialK3(nPlasmaIndex) + (1 * t);
449 }
450 else
451 {
452 nResult = GetInitialL3(nPlasmaIndex) + (2 * t);
453 }
454
455 float fResult = float(nResult);
456 fResult = mod(fResult, 4096.0);
457
458 if (fResult < 0.0)
459 {
460 fResult += 4096.0;
461 }
462 nResult = int(fResult);
463
464 return nResult;
465 }
466
467 int GetC4(int nXOffset0or1, int t)
468 {
469 int nPlasmaIndex = GetPlasmaIndex(t);
470 t = GetPerPlasmaTime(t);
471
472 int nResult = 0;
473 if (nXOffset0or1 == 0)
474 {
475 nResult = GetInitialK4(nPlasmaIndex) + (2 * t);
476 }
477 else
478 {
479 nResult = GetInitialL4(nPlasmaIndex) + (3 * t);
480 }
481
482 float fResult = float(nResult);
483 fResult = mod(fResult, 4096.0);
484
485 if (fResult < 0.0)
486 {
487 fResult += 4096.0;
488 }
489 nResult = int(fResult);
490
491 return nResult;
492 }
493
494 float Palette0_GetRed(int nIndex)
495 {
496 float a = 0.0;
497 if ((nIndex >= 0) && (nIndex < 64))
498 {
499 a = float(nIndex);
500 }
501 else if ((nIndex >= 64) && (nIndex < 128))
502 {
503 a = float(nIndex) - 64.0;
504 a = 63.0 - a;
505 }
506 else if ((nIndex >= 128) && (nIndex < 192))
507 {
508 a = 0.0;
509 }
510 else
511 {
512 a = float(nIndex) - 192.0;
513 }
514
515 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
516 fResult /= 63.0;
517
518 return fResult;
519 }
520 float Palette0_GetGreen(int nIndex)
521 {
522 float a = 0.0;
523 if ((nIndex >= 0) && (nIndex < 64))
524 {
525 a = 0.0;
526 }
527 else if ((nIndex >= 64) && (nIndex < 128))
528 {
529 a = 0.0;
530 }
531 else if ((nIndex >= 128) && (nIndex < 192))
532 {
533 a = 0.0;
534 }
535 else
536 {
537 a = 0.0;
538 }
539
540 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
541 fResult /= 63.0;
542
543 return fResult;
544 }
545 float Palette0_GetBlue(int nIndex)
546 {
547 float a = 0.0;
548 if ((nIndex >= 0) && (nIndex < 64))
549 {
550 a = 0.0;
551 }
552 else if ((nIndex >= 64) && (nIndex < 128))
553 {
554 a = 0.0;
555 }
556 else if ((nIndex >= 128) && (nIndex < 192))
557 {
558 a = float(nIndex) - 128.0;
559 }
560 else
561 {
562 a = float(nIndex) - 192.0;
563 a = 63.0 - a;
564 }
565
566 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
567 fResult /= 63.0;
568
569 return fResult;
570 }
571
572 float Palette1_GetRed(int nIndex)
573 {
574 float a = 0.0;
575 if ((nIndex >= 0) && (nIndex < 64))
576 {
577 a = float(nIndex);
578 }
579 else if ((nIndex >= 64) && (nIndex < 128))
580 {
581 a = float(nIndex) - 64.0;
582 a = 63.0 - a;
583 }
584 else if ((nIndex >= 128) && (nIndex < 192))
585 {
586 a = 0.0;
587 }
588 else
589 {
590 a = float(nIndex) - 192.0;
591 }
592
593 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
594 fResult /= 63.0;
595
596 return fResult;
597 }
598
599 float Palette1_GetGreen(int nIndex)
600 {
601 float a = 0.0;
602 if ((nIndex >= 0) && (nIndex < 64))
603 {
604 a = 0.0;
605 }
606 else if ((nIndex >= 64) && (nIndex < 128))
607 {
608 a = 0.0;
609 }
610 else if ((nIndex >= 128) && (nIndex < 192))
611 {
612 a = float(nIndex) - 128.0;
613 }
614 else
615 {
616 a = 63.0;
617 }
618
619 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
620 fResult /= 63.0;
621
622 return fResult;
623 }
624 float Palette1_GetBlue(int nIndex)
625 {
626 float a = 0.0;
627 if ((nIndex >= 0) && (nIndex < 64))
628 {
629 a = 0.0;
630 }
631 else if ((nIndex >= 64) && (nIndex < 128))
632 {
633 a = float(nIndex) - 64.0;
634 }
635 else if ((nIndex >= 128) && (nIndex < 192))
636 {
637 a = float(nIndex) - 128.0;
638 a = 63.0 - a;
639 }
640 else
641 {
642 a = float(nIndex) - 192.0;
643 }
644
645 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
646 fResult /= 63.0;
647
648 return fResult;
649 }
650
651 float Palette2_GetRed(int nIndex)
652 {
653 float a = 0.0;
654 if ((nIndex >= 0) && (nIndex < 64))
655 {
656 a = 0.0;
657 }
658 else if ((nIndex >= 64) && (nIndex < 128))
659 {
660 a = float(nIndex) - 64.0;
661 }
662 else if ((nIndex >= 128) && (nIndex < 192))
663 {
664 a = float(nIndex) - 128.0;
665 a = 63.0 - a;
666 }
667 else
668 {
669 a = 0.0;
670 }
671
672 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
673 fResult /= 2.0;
674 fResult /= 63.0;
675
676 return fResult;
677 }
678
679 float Palette2_GetGreen(int nIndex)
680 {
681 float a = 0.0;
682 if ((nIndex >= 0) && (nIndex < 64))
683 {
684 a = 0.0;
685 }
686 else if ((nIndex >= 64) && (nIndex < 128))
687 {
688 a = float(nIndex) - 64.0;
689 }
690 else if ((nIndex >= 128) && (nIndex < 192))
691 {
692 a = float(nIndex) - 128.0;
693 a = 63.0 - a;
694 }
695 else
696 {
697 a = 0.0;
698 }
699
700 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
701 fResult /= 2.0;
702 fResult /= 63.0;
703
704 return fResult;
705 }
706 float Palette2_GetBlue(int nIndex)
707 {
708 float a = 0.0;
709 if ((nIndex >= 0) && (nIndex < 64))
710 {
711 a = 0.0;
712 }
713 else if ((nIndex >= 64) && (nIndex < 128))
714 {
715 a = float(nIndex) - 64.0;
716 }
717 else if ((nIndex >= 128) && (nIndex < 192))
718 {
719 a = float(nIndex) - 128.0;
720 a = 63.0 - a;
721 }
722 else
723 {
724 a = 0.0;
725 }
726
727 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
728 fResult /= 2.0;
729 fResult /= 63.0;
730
731 return fResult;
732 }
733
734 float Palette3_GetRed(int nIndex)
735 {
736 float a = 0.0;
737 if ((nIndex >= 0) && (nIndex < 64))
738 {
739 a = float(nIndex);
740 }
741 else if ((nIndex >= 64) && (nIndex < 128))
742 {
743 a = 63.0;
744 }
745 else if ((nIndex >= 128) && (nIndex < 192))
746 {
747 a = float(nIndex) - 128.0;
748 a = 63.0 - a;
749 }
750 else
751 {
752 a = 0.0;
753 }
754
755 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
756 fResult /= 63.0;
757
758 return fResult;
759 }
760 float Palette3_GetGreen(int nIndex)
761 {
762 float a = 0.0;
763 if ((nIndex >= 0) && (nIndex < 64))
764 {
765 a = 0.0;
766 }
767 else if ((nIndex >= 64) && (nIndex < 128))
768 {
769 a = float(nIndex) - 64.0;
770 }
771 else if ((nIndex >= 128) && (nIndex < 192))
772 {
773 a = float(nIndex) - 128.0;
774 a = 63.0 - a;
775 }
776 else
777 {
778 a = 0.0;
779 }
780
781 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
782 fResult /= 63.0;
783
784 return fResult;
785 }
786 float Palette3_GetBlue(int nIndex)
787 {
788 float a = 0.0;
789 if ((nIndex >= 0) && (nIndex < 64))
790 {
791 a = 0.0;
792 }
793 else if ((nIndex >= 64) && (nIndex < 128))
794 {
795 a = float(nIndex) - 64.0;
796 }
797 else if ((nIndex >= 128) && (nIndex < 192))
798 {
799 a = 63.0;
800 }
801 else
802 {
803 a = 63.0;
804 }
805
806 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
807 fResult /= 63.0;
808
809 return fResult;
810 }
811
812 float Palette4_GetRed(int nIndex)
813 {
814 float a = 0.0;
815 if ((nIndex >= 0) && (nIndex < 75))
816 {
817 a = float(nIndex);
818 a = 63.0 - a * 64.0 / 75.0;
819 }
820 else if ((nIndex >= 75) && (nIndex < 181))
821 {
822 return 0.0;
823 }
824 else
825 {
826 a = float(nIndex) - 181.0;
827 a = (a * 64.0 / 75.0) * 8.0 / 10.0;
828 }
829
830 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
831 fResult /= 63.0;
832
833 return fResult;
834 }
835 float Palette4_GetGreen(int nIndex)
836 {
837 float a = 0.0;
838 if ((nIndex >= 0) && (nIndex < 75))
839 {
840 a = float(nIndex);
841 a = 63.0 - a * 64.0 / 75.0;
842 }
843 else if ((nIndex >= 75) && (nIndex < 181))
844 {
845 return 0.0;
846 }
847 else
848 {
849 a = float(nIndex) - 181.0;
850 a = (a * 64.0 / 75.0) * 9.0 / 10.0;
851 }
852
853 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
854 fResult /= 63.0;
855
856 return fResult;
857 }
858 float Palette4_GetBlue(int nIndex)
859 {
860 float a = 0.0;
861 if ((nIndex >= 0) && (nIndex < 75))
862 {
863 a = float(nIndex);
864 a = 63.0 - a * 64.0 / 75.0;
865 }
866 else if ((nIndex >= 75) && (nIndex < 181))
867 {
868 return 0.0;
869 }
870 else
871 {
872 a = float(nIndex) - 181.0;
873 a = (a * 64.0 / 75.0);
874 }
875
876 float fResult = cos(a*(3.1415926535*2.0) / 128.0 + 3.1415926535)*31.0 + 32.0;
877 fResult /= 63.0;
878
879 return fResult;
880 }
881
882 float Palette_GetRed(int nIndex, int t)
883 {
884 int nPlasmaIndex = GetPlasmaIndex(t);
885 t = GetPerPlasmaTime(t);
886 float fResult = 0.0;
887
888 if (nPlasmaIndex == 0)
889 {
890 fResult = Palette0_GetRed(nIndex);
891 }
892 else if (nPlasmaIndex == 1)
893 {
894 fResult = Palette1_GetRed(nIndex);
895 }
896 else if (nPlasmaIndex == 2)
897 {
898 fResult = Palette2_GetRed(nIndex);
899 }
900 else if (nPlasmaIndex == 3)
901 {
902 fResult = Palette3_GetRed(nIndex);
903 }
904 else if (nPlasmaIndex == 4)
905 {
906 fResult = Palette4_GetRed(nIndex);
907 }
908
909 return fResult;
910 }
911 float Palette_GetGreen(int nIndex, int t)
912 {
913 int nPlasmaIndex = GetPlasmaIndex(t);
914 t = GetPerPlasmaTime(t);
915 float fResult = 0.0;
916
917 if (nPlasmaIndex == 0)
918 {
919 fResult = Palette0_GetGreen(nIndex);
920 }
921 else if (nPlasmaIndex == 1)
922 {
923 fResult = Palette1_GetGreen(nIndex);
924 }
925 else if (nPlasmaIndex == 2)
926 {
927 fResult = Palette2_GetGreen(nIndex);
928 }
929 else if (nPlasmaIndex == 3)
930 {
931 fResult = Palette3_GetGreen(nIndex);
932 }
933 else if (nPlasmaIndex == 4)
934 {
935 fResult = Palette4_GetGreen(nIndex);
936 }
937
938 return fResult;
939 }
940 float Palette_GetBlue(int nIndex, int t)
941 {
942 int nPlasmaIndex = GetPlasmaIndex(t);
943 t = GetPerPlasmaTime(t);
944 float fResult = 0.0;
945
946 if (nPlasmaIndex == 0)
947 {
948 fResult = Palette0_GetBlue(nIndex);
949 }
950 else if (nPlasmaIndex == 1)
951 {
952 fResult = Palette1_GetBlue(nIndex);
953 }
954 else if (nPlasmaIndex == 2)
955 {
956 fResult = Palette2_GetBlue(nIndex);
957 }
958 else if (nPlasmaIndex == 3)
959 {
960 fResult = Palette3_GetBlue(nIndex);
961 }
962 else if (nPlasmaIndex == 4)
963 {
964 fResult = Palette4_GetBlue(nIndex);
965 }
966
967 return fResult;
968 }
969
970 void mainImage(out vec4 fragColor, in vec2 fragCoord)
971 {
972 // t is an integer frame count.
973 int t = int(iGlobalTime * 60.0);
974
975 // Wrap t when it exceeds 2323, so that the plasmas will repeat.
976 float fT = float(t);
977 t = int(mod(fT, 2323.0));
978
979 // fPlasmaX is a float from 0 to 319,
980 // fPlasmaY is a float from 0 to 399.
981 float fPlasmaX = (fragCoord.x / iResolution.x) * 319.0;
982 float fPlasmaY = (fragCoord.y / iResolution.y) * 399.0;
983 fPlasmaY = 399.0 - fPlasmaY;
984
985 fPlasmaY -= float(GetYOffset(t));
986 fPlasmaX += float(GetXOffset(t));
987
988 float fRed = 0.0;
989 float fGreen = 0.0;
990 float fBlue = 0.0;
991
992 if ((fPlasmaY >= 0.0) && (fPlasmaY < 280.0))
993 {
994 float fScreenX = fragCoord.x;
995 float fScreenY = fragCoord.y;
996 float ah = 0.0;
997 float ccc = fPlasmaX / 4.0;
998 float fOffset = 0.0;
999 float bx = 0.0;
1000
1001 int nXOffset0or1 = int(mod(fScreenX, 2.0));
1002 // On every odd row, toggle the x offset. This causes different plasma constants to be
1003 // read for these pixels, achieving a chequered overlay of two plasmas.
1004 int xor = int(mod(fScreenY, 2.0));
1005 if (xor == 1)
1006 {
1007 if (nXOffset0or1 == 0)
1008 {
1009 nXOffset0or1 = 1;
1010 }
1011 else
1012 {
1013 nXOffset0or1 = 0;
1014 }
1015 }
1016
1017 float c1 = float(GetC1(nXOffset0or1, t));
1018 float c2 = float(GetC2(nXOffset0or1, t));
1019 float c3 = float(GetC3(nXOffset0or1, t));
1020 float c4 = float(GetC4(nXOffset0or1, t));
1021
1022 fOffset = ((fPlasmaY * 2.0) + (c2 * 2.0) - (ccc * 8.0) + (80.0 * 8.0)) / 2.0;
1023 bx = ((sin(fOffset*DPII / 4096.0)*55.0 + sin(fOffset*DPII / 4096.0*4.0)*5.0 + sin(fOffset*DPII / 4096.0*17.0)*3.0 + 64.0)*16.0);
1024
1025 fOffset = bx + c1 + (ccc * 8.0);
1026 ah = (sin(fOffset*DPII / 4096.0)*55.0 + sin(fOffset*DPII / 4096.0*6.0)*5.0 + sin(fOffset*DPII / 4096.0*21.0)*4.0 + 64.0);
1027
1028 fOffset = ((fPlasmaY * 2.0) + (c4 * 2.0) + (ccc * 32.0)) / 2.0;
1029 bx = ((sin(fOffset*DPII / 4096.0)*55.0 + sin(fOffset*DPII / 4096.0*5.0)*8.0 + sin(fOffset*DPII / 4096.0*15.0)*2.0 + 64.0)*8.0);
1030
1031 fOffset = bx + (fPlasmaY * 2.0) + c3 - (ccc * 4.0) + (80.0 * 4.0);
1032 ah += (sin(fOffset*DPII / 4096.0)*55.0 + sin(fOffset*DPII / 4096.0*6.0)*5.0 + sin(fOffset*DPII / 4096.0*21.0)*4.0 + 64.0);
1033
1034 int nPaletteIndex = int(ah);
1035
1036 fRed = Palette_GetRed(nPaletteIndex, t);
1037 fGreen = Palette_GetGreen(nPaletteIndex, t);
1038 fBlue = Palette_GetBlue(nPaletteIndex, t);
1039 }
1040
1041 fRed = FadeColourComponent(fRed, t);
1042 fGreen = FadeColourComponent(fGreen, t);
1043 fBlue = FadeColourComponent(fBlue, t);
1044
1045 fragColor = vec4(fRed, fGreen, fBlue, 1.0);
1046 }