1 precision mediump float;
3 uniform vec3 iResolution; // viewport resolution (in pixels)
4 uniform float iGlobalTime; // shader playback time (in seconds)
6 #define PI 3.1415926535
9 int GetPerPlasmaTime(int t)
11 // Get the time since this plasma started using the total time.
12 // Times for each plasma are (from the timetable array): 723, 1491,
13 // 1875, 2259, 2278. (64 is added to each time because it takes 64
14 // frames to drop the current plasma offscreen before switching to
19 } else if (t < 1491+64) {
21 } else if (t < 1875+64) {
23 } else if (t < 2259+64) {
25 } else if (t < 2278+64) {
34 int GetPlasmaIndex(int t)
40 } else if (t < 1491+64) {
42 } else if (t < 1875+64) {
54 if ( (t >= 723) && (t < (723+64)) ) {
57 } else if ( (t >= 1491) && (t < (1491+64)) ) {
60 } else if ( (t >= 1875) && (t < (1875+64)) ) {
63 } else if ( (t >= 2259) && (t < (2259+64)) ) {
69 nResult = t * t / 4 * 43 / 128 + 60;
75 float FadeColourComponent(float c, int t)
78 float fProportion = 0.0;
80 if ((t >= 0) && (t < 128)) {
81 // For plasma 1, fade from white to the palette.
82 fProportion = float(t) / 127.0;
83 fResult = (fProportion * c) + ((1.0 - fProportion) * 1.0);
84 } else if ( (t >= (723+64)) && (t < (723+64+32)) ) {
85 // For plasma 2, fade from black to the palette.
86 fProportion = float(t-723-64) / 31.0;
87 fResult = (fProportion * c) + ((1.0 - fProportion) * 0.0);
88 } else if ( (t >= (1491+64)) && (t < (1491+64+32)) ) {
89 // For plasma 3, fade from black to the palette.
90 fProportion = float(t-1491-64) / 31.0;
91 fResult = (fProportion * c) + ((1.0 - fProportion) * 0.0);
97 int GetInitialL1(int nPlasmaIndex)
99 if (nPlasmaIndex == 0) {
101 } else if (nPlasmaIndex == 1) {
103 } else /* if (nPlasmaIndex == 2) */ {
107 int GetInitialL2(int nPlasmaIndex)
109 if (nPlasmaIndex == 0) {
111 } else if (nPlasmaIndex == 1) {
113 } else /* if (nPlasmaIndex == 2) */ {
118 int GetInitialL3(int nPlasmaIndex)
120 if (nPlasmaIndex == 0) {
122 } else if (nPlasmaIndex == 1) {
124 } else /* if (nPlasmaIndex == 2) */ {
129 int GetInitialL4(int nPlasmaIndex)
131 if (nPlasmaIndex == 0) {
133 } else if (nPlasmaIndex == 1) {
135 } else /* if (nPlasmaIndex == 2) */ {
140 int GetInitialK1(int nPlasmaIndex)
142 if (nPlasmaIndex == 0) {
144 } else if (nPlasmaIndex == 1) {
146 } else /* if (nPlasmaIndex == 2) */ {
151 int GetInitialK2(int nPlasmaIndex)
153 if (nPlasmaIndex == 0) {
155 } else if (nPlasmaIndex == 1) {
157 } else /* if (nPlasmaIndex == 2) */ {
162 int GetInitialK3(int nPlasmaIndex)
164 if (nPlasmaIndex == 0) {
166 } else if (nPlasmaIndex == 1) {
168 } else /* if (nPlasmaIndex == 2) */ {
173 int GetInitialK4(int nPlasmaIndex)
175 if (nPlasmaIndex == 0) {
177 } else if (nPlasmaIndex == 1) {
179 } else /* if (nPlasmaIndex == 2) */ {
184 int GetC1(int nXOffset0or1, int t)
186 int nPlasmaIndex = GetPlasmaIndex(t);
187 t = GetPerPlasmaTime(t);
190 if (nXOffset0or1 == 0) {
191 nResult = GetInitialK1(nPlasmaIndex) + (-3 * t);
193 nResult = GetInitialL1(nPlasmaIndex) + (-1 * t);
196 float fResult = float(nResult);
197 fResult = mod(fResult, 4096.0);
206 int GetC2(int nXOffset0or1, int t)
208 int nPlasmaIndex = GetPlasmaIndex(t);
209 t = GetPerPlasmaTime(t);
212 if (nXOffset0or1 == 0) {
213 nResult = GetInitialK2(nPlasmaIndex) + (-2 * t);
215 nResult = GetInitialL2(nPlasmaIndex) + (-2 * t);
218 float fResult = float(nResult);
219 fResult = mod(fResult, 4096.0);
228 int GetC3(int nXOffset0or1, int t)
230 int nPlasmaIndex = GetPlasmaIndex(t);
231 t = GetPerPlasmaTime(t);
234 if (nXOffset0or1 == 0) {
235 nResult = GetInitialK3(nPlasmaIndex) + (1 * t);
237 nResult = GetInitialL3(nPlasmaIndex) + (2 * t);
240 float fResult = float(nResult);
241 fResult = mod(fResult, 4096.0);
250 int GetC4(int nXOffset0or1, int t)
252 int nPlasmaIndex = GetPlasmaIndex(t);
253 t = GetPerPlasmaTime(t);
256 if (nXOffset0or1 == 0) {
257 nResult = GetInitialK4(nPlasmaIndex) + (2 * t);
259 nResult = GetInitialL4(nPlasmaIndex) + (3 * t);
262 float fResult = float(nResult);
263 fResult = mod(fResult, 4096.0);
272 float Palette0_GetRed(float nIndex)
276 if ((nIndex >= 0.0) && (nIndex < 64.0)) {
278 } else if ((nIndex >= 64.0) && (nIndex < 128.0)) {
279 a = 63.0 - (nIndex - 64.0);
280 } else if ((nIndex >= 128.0) && (nIndex < 192.0)) {
286 return (cos(a*DPII/128.0+PI)*31.0+32.0) / 63.0;
289 float Palette0_GetGreen(float nIndex)
294 float Palette0_GetBlue(float nIndex)
298 if ((nIndex >= 0.0) && (nIndex < 128.0)) {
300 } else if ((nIndex >= 128.0) && (nIndex < 192.0)) {
303 a = 63.0 - (nIndex - 192.0);
306 return (cos(a*DPII/128.0+PI)*31.0+32.0) / 63.0;
309 float Palette1_GetGreen(float nIndex)
313 if ((nIndex >= 0.0) && (nIndex < 128.0)) {
315 } else if ((nIndex >= 128.0) && (nIndex < 192.0)) {
321 return (cos(a*DPII/128.0+PI)*31.0+32.0) / 63.0;
324 float Palette1_GetBlue(float nIndex)
328 if ((nIndex >= 0.0) && (nIndex < 64.0)) {
330 } else if ((nIndex >= 64.0) && (nIndex < 128.0)) {
332 } else if ((nIndex >= 128.0) && (nIndex < 192.0)) {
333 a = 63.0 - (nIndex - 128.0);
338 return (cos(a*DPII/128.0+PI)*31.0+32.0) / 63.0;
341 float Palette2_GetRed(float nIndex)
345 if ((nIndex >= 0.0) && (nIndex < 64.0)) {
347 } else if ((nIndex >= 64.0) && (nIndex < 128.0)) {
349 } else if ((nIndex >= 128.0) && (nIndex < 192.0)) {
350 a = 63.0 - (nIndex - 128.0);
355 return (cos(a*DPII/128.0+PI)*31.0+32.0) / 63.0 / 2.0;
358 float Palette_GetRed(float nIndex, int t)
360 int nPlasmaIndex = GetPlasmaIndex(t);
361 t = GetPerPlasmaTime(t);
364 if (nPlasmaIndex == 0) {
365 fResult = Palette0_GetRed(nIndex);
366 } else if (nPlasmaIndex == 1) {
367 fResult = Palette0_GetRed(nIndex);
368 } else if (nPlasmaIndex == 2) {
369 fResult = Palette2_GetRed(nIndex);
375 float Palette_GetGreen(float nIndex, int t)
377 int nPlasmaIndex = GetPlasmaIndex(t);
378 t = GetPerPlasmaTime(t);
381 if (nPlasmaIndex == 0) {
382 fResult = Palette0_GetGreen(nIndex);
383 } else if (nPlasmaIndex == 1) {
384 fResult = Palette1_GetGreen(nIndex);
385 } else if (nPlasmaIndex == 2) {
386 fResult = Palette2_GetRed(nIndex);
392 float Palette_GetBlue(float nIndex, int t)
394 int nPlasmaIndex = GetPlasmaIndex(t);
395 t = GetPerPlasmaTime(t);
398 if (nPlasmaIndex == 0) {
399 fResult = Palette0_GetBlue(nIndex);
400 } else if (nPlasmaIndex == 1) {
401 fResult = Palette1_GetBlue(nIndex);
402 } else if (nPlasmaIndex == 2) {
403 fResult = Palette2_GetRed(nIndex);
411 // t is an integer frame count.
412 int t = int(iGlobalTime * 60.0);
414 // Wrap t when it exceeds 2323, so that the plasmas will repeat.
416 t = int(mod(fT, 1939.0));
418 // fPlasmaX is a float from 0 to 319,
419 // fPlasmaY is a float from 0 to 399.
420 float fPlasmaX = (gl_FragCoord.x / iResolution.x) * 319.0;
421 float fPlasmaY = (gl_FragCoord.y / iResolution.y) * 399.0;
422 fPlasmaY = 399.0 - fPlasmaY;
424 fPlasmaY -= float(GetYOffset(t));
425 /* fPlasmaX += float(GetXOffset(t)); */
431 if ( (fPlasmaY >= 0.0) && (fPlasmaY < 280.0) ) {
432 float fScreenX = gl_FragCoord.x;
433 float fScreenY = gl_FragCoord.y;
435 float ccc = fPlasmaX / 4.0;
439 int nXOffset0or1 = int(mod(fScreenX, 2.0));
441 // On every odd row, toggle the x offset. This causes different
442 // plasma constants to be read for these pixels, achieving a
443 // chequered overlay of two plasmas.
445 int xor = int(mod(fScreenY, 2.0));
447 if (nXOffset0or1 == 0) {
454 float c1 = float(GetC1(nXOffset0or1, t));
455 float c2 = float(GetC2(nXOffset0or1, t));
456 float c3 = float(GetC3(nXOffset0or1, t));
457 float c4 = float(GetC4(nXOffset0or1, t));
459 fOffset = ((fPlasmaY * 2.0) + (c2 * 2.0) - (ccc * 8.0) + (80.0 * 8.0)) / 2.0;
460 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);
462 fOffset = bx + c1 + (ccc * 8.0);
463 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);
465 fOffset = ((fPlasmaY * 2.0) + (c4 * 2.0) + (ccc * 32.0)) / 2.0;
466 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);
468 fOffset = bx + (fPlasmaY * 2.0) + c3 - (ccc * 4.0) + (80.0 * 4.0);
469 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);
471 fRed = Palette_GetRed(ah, t);
472 fGreen = Palette_GetGreen(ah, t);
473 fBlue = Palette_GetBlue(ah, t);
476 fRed = FadeColourComponent(fRed, t);
477 fGreen = FadeColourComponent(fGreen, t);
478 fBlue = FadeColourComponent(fBlue, t);
480 gl_FragColor = vec4(fRed, fGreen, fBlue, 1.0);