@@ -3,6 +3,7 @@ uniform vec2 mouse;
33uniform vec2 mouseDelta;
44uniform float time;
55uniform int color_id;
6+ uniform int shader_id;
67/* uniform vec4 colors[23] = {
78 vec4(.2, .6, .1,1.) // land
89 ,vec4(.0, .5, .0,1.0)
@@ -29,26 +30,166 @@ uniform int color_id;
2930 ,vec4(.8, .0, .0,.6) // 21 not used
3031 ,vec4(.0, .6, .0,1.)
3132};*/
33+
34+ // shadertoy emulation
35+ #define iTime time
36+ #define iResolution resolution
37+
38+ // --------[ Original ShaderToy begins here ]---------- //
39+ #define EPS 0.001
40+ #define MAX_STEPS 32
41+ #define ITR 8
42+
43+ mat2 rot(float a){
44+ float s= sin (a);
45+ float c= cos (a);
46+ return mat2 (c,s,- s,c);
47+ }
48+
49+ float scale;
50+
51+ float map(vec3 p){
52+ p+= vec3 (1.0 ,1.0 ,iTime* 0.2 );
53+ p.xy*= rot(iTime* 0.05 );
54+ p.yz*= rot(iTime* 0.05 );
55+ float s= 3.0 ;
56+ for (int i= 0 ;i< ITR;i++ ){
57+ p= mod (p- 1.0 ,2.0 )- 1.0 ;
58+ float r= 1.53 / dot (p,p);
59+ p*= r;
60+ s*= r;
61+ }
62+ scale= s;
63+ return dot (abs (p),normalize (vec3 (0.0 ,1.0 ,1.0 )))/ s;
64+ }
65+
66+ vec3 GetNormal(vec3 p){
67+ float d= map(p);
68+ vec2 e= vec2 (EPS,0.0 );
69+
70+ vec3 n= d- vec3 (
71+ map(p- e.xyy),
72+ map(p- e.yxy),
73+ map(p- e.yyx));
74+ return normalize (n);
75+ }
76+
77+ float circle(vec2 center, vec2 position, float radius) {
78+ vec2 d = center - position;
79+ d.x = mod (d.x+ 0.5 , 1.0 )- 0.5 ;
80+ d.y = mod (d.y+ 0.5 , 1.0 )- 0.5 ;
81+ return clamp ((radius - length (d)) * resolution.y, 0.0 , 1.0 );
82+ }
83+
84+ float rnd(int seed) {
85+ return fract (sin (1.34232 + pow (float (seed), 1.014 ) * 89.72342433 ) * 328.2653653 );
86+ }
87+
88+ #define VEL 1.5
89+ #define PI 3.14159265359
90+
91+
3292void main() {
3393 // gl_FragColor = colors[color_id];
3494 if (color_id == 0 )
3595 {
36- const float Pi = 3.14159 ;
37- const int complexity = 47 ; // More points of color.
38- const float mouse_factor = 56.0 ; // Makes it more/less jumpy.
39- const float mouse_offset = 0.0 ; // Drives complexity in the amount of curls/cuves. Zero is a single whirlpool.
40- const float fluid_speed = 54.0 ; // Drives speed, higher number will make it slower.
41- const float color_intensity = 0.8 ;
42- vec2 p= (2.0 * (gl_FragCoord .xy - mouseDelta.xy)- resolution)/ max (resolution.x,resolution.y);
43- for (int i= 1 ;i< complexity;i++ )
96+ if (shader_id == 1 )
97+ {
98+ const float Pi = 3.14159 ;
99+ const int complexity = 47 ; // More points of color.
100+ const float mouse_factor = 56.0 ; // Makes it more/less jumpy.
101+ const float mouse_offset = 0.0 ; // Drives complexity in the amount of curls/cuves. Zero is a single whirlpool.
102+ const float fluid_speed = 27.0 ; // Drives speed, higher number will make it slower.
103+ const float color_intensity = 0.8 ;
104+ vec2 p= (2.0 * (gl_FragCoord .xy - mouseDelta.xy)- resolution)/ max (resolution.x,resolution.y);
105+ for (int i= 1 ;i< complexity;i++ )
106+ {
107+ vec2 newp= p + time* 0.001 ;
108+ newp.x+= 0.6 / float (i)* sin (float (i)* p.y+ time/ fluid_speed+ 0.3 * float (i)) + 0.5 ; // + mouse.y/mouse_factor+mouse_offset;
109+ newp.y+= 0.6 / float (i)* sin (float (i)* p.x+ time/ fluid_speed+ 0.3 * float (i+ 10 )) - 0.5 ; // - mouse.x/mouse_factor+mouse_offset;
110+ p= newp;
111+ }
112+ vec3 col= vec3 (color_intensity* sin (3.0 * p.x)+ color_intensity,color_intensity* sin (3.0 * p.y)+ color_intensity,color_intensity* sin (p.x+ p.y)+ color_intensity);
113+ gl_FragColor = vec4 (col, 1 );
114+ }
115+ else if (shader_id == 2 )
116+ {
117+ float v = VEL * abs (cos (time/ 5.0 )) * PI* 0.01 ;
118+ vec3 rColor = vec3 (1.0 , 0.3 , 1.0 );
119+ rColor = vec3 (0.6 , 0.5 , 10.0 * mouse.x);
120+
121+ vec2 p = ((gl_FragCoord .xy - mouseDelta.xy) * 2.0 - resolution);
122+ p /= min (resolution.x, resolution.y);
123+ p*= 1.1 ;
124+
125+ float m = cos (time* 0.1 );
126+
127+ float d = cos (VEL* time* 1.0 - p.x* 4.0 * m + 0.0 * 2 .*PI/ 3 .);
128+ float e = cos (- VEL* time* 1.1 - p.x* 4.0 * m/ 4.0 + 1.0 * 2 .*PI/ 3 .);
129+ float f = cos (VEL* time* 1.2 - p.x* 4.0 * m/ 2.0 + 2.0 * 2 .*PI/ 3 .);
130+
131+ float r = 1.09 / abs (p.x + d);
132+ float g = 0.09 / abs (p.y + e);
133+ float b = 0.09 / abs (p.y + f);
134+
135+
136+ vec3 destColor = rColor* vec3 (r, g, b);
137+ gl_FragColor = vec4 (destColor, 1.0 );
138+ }
139+ else if (shader_id == 3 )
140+ {
141+ vec3 c = vec3 (0 .);
142+ vec4 o = vec4 (0 .);
143+ float t = iTime*.1 ,d;
144+ for (float i= 0 .; i< 1 .; i+=.06 )
145+ {
146+ d = fract (i+.1 * t);
147+ o = vec4 ( (gl_FragCoord .xy - mouseDelta.xy - iResolution.xy*.5 )/ iResolution.y* (1 .-d) ,- i,0 )* 28 .;
148+ for (int i= 0 ; i< 19 ;++ i) o.xzyw = abs ( o/ dot (o,o) - vec4 ( 1 .-.03 * sin (t) , .9 , .1 , .15 -.14 * cos (t* 1.3 )) );
149+ c+= o.xyz* o.yzw* (d- d* d);
150+ }
151+ o.rgb = c;
152+ gl_FragColor = vec4 (o.xyz, 1.0 );
153+ }
154+ else if (shader_id == 4 )
155+ {
156+ vec2 uv= (2.0 * (gl_FragCoord .xy- mouseDelta.xy)- resolution.xy)/ resolution.y;
157+ vec3 col= vec3 (0.0 );
158+ vec3 rd= normalize (vec3 (uv,1.0 ));
159+ vec3 p= vec3 (0.0 ,0.0 ,iTime* 0.05 );
160+ float d;
161+ float emission= 0.0 ;
162+
163+ for (int i= 0 ;i< MAX_STEPS;i++ ){
164+ d= map(p);
165+ p+= rd* d;
166+ // normal=GetNormal(p);
167+ emission+= exp (d*-0.4 );
168+ if (d< EPS)break ;
169+ }
170+
171+ vec4 color= 0.02 * emission* vec4 (sin (iTime),1.0 ,sin (iTime),1.0 );
172+ gl_FragColor = vec4 (color.xyz, 1.0 );
173+ }
174+ else if (shader_id == 5 )
175+ {
176+ vec2 position = ( (gl_FragCoord .xy - mouseDelta.xy) / resolution.xy );
177+ position -= 0.5 ;
178+ position.x *= resolution.x / resolution.y;
179+ vec3 o = vec3 (0.0 , 0.0 , 0.0 );
180+
181+ for (int i= 0 ; i< 300 ; i+= 10 ) {
182+ vec2 center = vec2 (rnd(i+ 0 ), rnd(i+ 1 )) + time * 0.1 * vec2 (rnd(i+ 2 ), rnd(i+ 3 ));
183+ float radius = 0.03 + 0.25 * rnd(i+ 4 );
184+ vec3 color = vec3 (rnd(i+ 5 ), rnd(i+ 6 ), rnd(i+ 7 ));
185+ o += circle(center, position, radius) * 0.5 * color;
186+ }
187+ gl_FragColor = vec4 (o.xyz, 1.0 );
188+ }
189+ else
44190 {
45- vec2 newp= p + time* 0.001 ;
46- newp.x+= 0.6 / float (i)* sin (float (i)* p.y+ time/ fluid_speed+ 0.3 * float (i)) + 0.5 ; // + mouse.y/mouse_factor+mouse_offset;
47- newp.y+= 0.6 / float (i)* sin (float (i)* p.x+ time/ fluid_speed+ 0.3 * float (i+ 10 )) - 0.5 ; // - mouse.x/mouse_factor+mouse_offset;
48- p= newp;
191+ gl_FragColor = vec4 (.0 , .6 , .0 ,1 .);
49192 }
50- vec3 col= vec3 (color_intensity* sin (3.0 * p.x)+ color_intensity,color_intensity* sin (3.0 * p.y)+ color_intensity,color_intensity* sin (p.x+ p.y)+ color_intensity);
51- gl_FragColor = vec4 (col, 1 );
52193 }
53194 else if (color_id == 1 )
54195 gl_FragColor = vec4 (.0 , .5 , .0 ,1.0 );
0 commit comments