Skip to content

Commit 7e50582

Browse files
committed
Episode 63
1 parent ad42719 commit 7e50582

File tree

5 files changed

+642
-0
lines changed

5 files changed

+642
-0
lines changed

codebasealpha.glsl

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
float dCircle(vec2 pos, float radius)
2+
{
3+
return length(pos) - radius;
4+
}
5+
6+
float dRoundBox(vec2 pos, float radius)
7+
{
8+
pos = pos*pos;
9+
pos = pos*pos;
10+
float d8 = dot(pos, pos);
11+
return pow(d8, 1.0/8.0) - radius;
12+
13+
}
14+
15+
float dBox(vec2 pos, vec2 siz)
16+
{
17+
pos = abs(pos);
18+
float dx = pos.x - siz.x;
19+
float dy = pos.y - siz.y;
20+
return max(dx, dy);
21+
}
22+
23+
vec2 toPolarCoords(vec2 rectCoords)
24+
{
25+
return vec2(length(rectCoords),atan(rectCoords.y, rectCoords.x));
26+
}
27+
28+
vec2 toRectCoords(vec2 polarCoords)
29+
{
30+
return vec2(polarCoords.x * cos(polarCoords.y), polarCoords.x * sin(polarCoords.y));
31+
}
32+
33+
#define PI 3.141592654
34+
#define TAU (2.0*PI)
35+
36+
// Repeat in two dimensions
37+
vec2 pMod2(inout vec2 p, vec2 size) {
38+
vec2 c = floor((p + size*0.5)/size);
39+
p = mod(p + size*0.5,size) - size*0.5;
40+
return c;
41+
}
42+
43+
float dF2(vec2 pos)
44+
{
45+
vec2 pp = toPolarCoords(pos);
46+
float a = TAU/30.0;
47+
float np = pp.y/a;
48+
pp.y = mod(pp.y, a);
49+
float m2 = mod(np, 2.0);
50+
if (m2 > 1.0)
51+
{
52+
pp.y = a - pp.y;
53+
}
54+
55+
pp.y += iTime;
56+
pos = toRectCoords(pp);
57+
58+
pMod2(pos, vec2(0.5));
59+
60+
float d1 = dCircle(pos, 0.1);
61+
62+
float d3 = dBox(pos - vec2(0.1), vec2(0.1, 0.1));
63+
float d = min(d1, d3);
64+
return d;
65+
}
66+
67+
float dF(vec2 pos)
68+
{
69+
//pos = abs(pos);
70+
vec2 pPos = toPolarCoords(pos);
71+
pPos.y = mod(pPos.y, TAU/7.0);
72+
pPos.y += iTime;
73+
74+
// pPos.x *= 1.0 + pos.y;
75+
pos = toRectCoords(pPos);
76+
pMod2(pos, vec2(0.5));
77+
78+
float d1 = dCircle(pos, 0.1);
79+
80+
float d3 = dBox(pos - vec2(0.1), vec2(0.1, 0.1));
81+
float d = min(d1, d3);
82+
return d;
83+
}
84+
85+
void rotate(inout vec2 pos, float angle)
86+
{
87+
float c = cos(angle);
88+
float s = sin(angle);
89+
pos = vec2(c*pos.x + s*pos.y, -s*pos.x + c*pos.y);
90+
91+
}
92+
93+
vec3 postProcess (vec3 col, vec2 pos)
94+
{
95+
rotate(pos, iTime);
96+
col = clamp(col, 0.0, 1.0);
97+
return pow(col, vec3(abs(pos.x), abs(pos.y), length(pos)));
98+
}
99+
100+
void mainImage( out vec4 fragColor, in vec2 fragCoord )
101+
{
102+
vec2 uv = fragCoord/iResolution.xy - vec2(0.5);
103+
uv.x *= iResolution.x/iResolution.y;
104+
105+
float d = dF2(uv);
106+
107+
108+
vec3 col = vec3(0);
109+
110+
float md = mod(d, 0.1);
111+
float nd = abs(d / 0.1);
112+
113+
if (abs(md) < 0.01)
114+
{
115+
if (d < 0.0)
116+
{
117+
col = vec3(1, 0.3 ,0.15)/ nd;
118+
}
119+
else
120+
{
121+
col = vec3(0.3, 1, 0.15) / nd;
122+
}
123+
}
124+
125+
if (abs(d) < 0.02)
126+
{
127+
col = vec3(1);
128+
}
129+
130+
fragColor = vec4(postProcess(col, uv),1.0);
131+
}

codebasealpha3.klproj

4.02 KB
Binary file not shown.

shadertoy/essenbee.png

24.2 KB
Loading

shadertoy/index.html

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<!--
2+
This program is free software: you can redistribute it and/or modify
3+
it under the terms of the GNU General Public License as published by
4+
the Free Software Foundation, either version 3 of the License, or
5+
(at your option) any later version.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program. If not, see <https://www.gnu.org/licenses/>.
14+
-->
15+
<!DOCTYPE html>
16+
<html>
17+
<head>
18+
<title>electric alfs</title>
19+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
20+
<script src="webgl-driver.js" type="text/javascript"></script>
21+
<link href='https://fonts.googleapis.com/css?family=Josefin Slab' rel='stylesheet'>
22+
<style>
23+
body {
24+
background-color: black;
25+
color: white;
26+
font-family: 'Josefin Slab';font-size: 32px;
27+
}
28+
canvas.gl {
29+
position:fixed;
30+
z-index:-1;
31+
left:0;
32+
top:0;
33+
width:100%;
34+
height:100%;
35+
}
36+
</style>
37+
<script id="shader-fs" type="x-shader/x-fragment">
38+
// -----------------------------------------------------------------------
39+
// BEGIN - Common prelude
40+
// -----------------------------------------------------------------------
41+
precision mediump float;
42+
43+
uniform vec2 iResolution;
44+
uniform float iTime;
45+
uniform sampler2D iChannel0;
46+
47+
varying highp vec2 vTextureCoord;
48+
49+
void mainImage(out vec4 fragColor, in vec2 fragCoord);
50+
51+
void main(void) {
52+
mainImage(gl_FragColor, vTextureCoord*iResolution);
53+
}
54+
// -----------------------------------------------------------------------
55+
// END - Common prelude
56+
// -----------------------------------------------------------------------
57+
58+
float dCircle(vec2 pos, float radius)
59+
{
60+
return length(pos) - radius;
61+
}
62+
63+
float dRoundBox(vec2 pos, float radius)
64+
{
65+
pos = pos*pos;
66+
pos = pos*pos;
67+
float d8 = dot(pos, pos);
68+
return pow(d8, 1.0/8.0) - radius;
69+
70+
}
71+
72+
float dBox(vec2 pos, vec2 siz)
73+
{
74+
pos = abs(pos);
75+
float dx = pos.x - siz.x;
76+
float dy = pos.y - siz.y;
77+
return max(dx, dy);
78+
}
79+
80+
vec2 toPolarCoords(vec2 rectCoords)
81+
{
82+
return vec2(length(rectCoords),atan(rectCoords.y, rectCoords.x));
83+
}
84+
85+
vec2 toRectCoords(vec2 polarCoords)
86+
{
87+
return vec2(polarCoords.x * cos(polarCoords.y), polarCoords.x * sin(polarCoords.y));
88+
}
89+
90+
#define PI 3.141592654
91+
#define TAU (2.0*PI)
92+
93+
// Repeat in two dimensions
94+
vec2 pMod2(inout vec2 p, vec2 size) {
95+
vec2 c = floor((p + size*0.5)/size);
96+
p = mod(p + size*0.5,size) - size*0.5;
97+
return c;
98+
}
99+
100+
float dF2(vec2 pos)
101+
{
102+
vec2 pp = toPolarCoords(pos);
103+
float a = TAU/30.0;
104+
float np = pp.y/a;
105+
pp.y = mod(pp.y, a);
106+
float m2 = mod(np, 2.0);
107+
if (m2 > 1.0)
108+
{
109+
pp.y = a - pp.y;
110+
}
111+
112+
pp.y += iTime;
113+
pos = toRectCoords(pp);
114+
115+
pMod2(pos, vec2(0.5));
116+
117+
float d1 = dCircle(pos, 0.1);
118+
119+
float d3 = dBox(pos - vec2(0.1), vec2(0.1, 0.1));
120+
float d = min(d1, d3);
121+
return d;
122+
}
123+
124+
float dF(vec2 pos)
125+
{
126+
//pos = abs(pos);
127+
vec2 pPos = toPolarCoords(pos);
128+
pPos.y = mod(pPos.y, TAU/7.0);
129+
pPos.y += iTime;
130+
131+
// pPos.x *= 1.0 + pos.y;
132+
pos = toRectCoords(pPos);
133+
pMod2(pos, vec2(0.5));
134+
135+
float d1 = dCircle(pos, 0.1);
136+
137+
float d3 = dBox(pos - vec2(0.1), vec2(0.1, 0.1));
138+
float d = min(d1, d3);
139+
return d;
140+
}
141+
142+
void rotate(inout vec2 pos, float angle)
143+
{
144+
float c = cos(angle);
145+
float s = sin(angle);
146+
pos = vec2(c*pos.x + s*pos.y, -s*pos.x + c*pos.y);
147+
148+
}
149+
150+
vec3 postProcess (vec3 col, vec2 pos)
151+
{
152+
rotate(pos, iTime);
153+
col = clamp(col, 0.0, 1.0);
154+
return pow(col, vec3(abs(pos.x), abs(pos.y), length(pos)));
155+
}
156+
157+
void mainImage( out vec4 fragColor, in vec2 fragCoord )
158+
{
159+
vec2 uv = fragCoord/iResolution.xy - vec2(0.5);
160+
uv.x *= iResolution.x/iResolution.y;
161+
162+
float d = dF2(uv);
163+
164+
165+
vec3 col = vec3(0);
166+
167+
float md = mod(d, 0.1);
168+
float nd = abs(d / 0.1);
169+
170+
if (abs(md) < 0.01)
171+
{
172+
if (d < 0.0)
173+
{
174+
col = vec3(1, 0.3 ,0.15)/ nd;
175+
}
176+
else
177+
{
178+
col = vec3(0.3, 1, 0.15) / nd;
179+
}
180+
}
181+
182+
if (abs(d) < 0.02)
183+
{
184+
col = vec3(1);
185+
}
186+
187+
fragColor = vec4(postProcess(col, uv),1.0);
188+
}
189+
190+
</script>
191+
192+
<script id="shader-vs" type="x-shader/x-vertex">
193+
attribute highp vec3 aVertexPosition;
194+
attribute highp vec3 aVertexNormal;
195+
attribute highp vec2 aTextureCoord;
196+
197+
varying highp vec2 vTextureCoord;
198+
varying highp vec3 vNormal;
199+
200+
void main(void) {
201+
gl_Position = vec4(aVertexPosition, 1.0);
202+
vNormal = aVertexNormal;
203+
vTextureCoord = aTextureCoord;
204+
}
205+
</script>
206+
</head>
207+
208+
<body onload="start()">
209+
<canvas id="glcanvas" class="gl">
210+
Your browser doesn't appear to support the HTML5 <code>&lt;canvas&gt;</code> element.
211+
</canvas>
212+
</body>
213+
</html>

0 commit comments

Comments
 (0)