-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
260 lines (203 loc) · 7.91 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Undulations</title>
<style>
body {
background: #333;
color: #fff;
font-family: sans-serif;
}
body,
html {
margin: 0;
overflow: hidden;
padding: 0;
}
canvas { width:100%; height: 100%; }
</style>
</head>
<body>
<script type="module" src="./pub/index.js"></script>
<script type="text/fragment" id="fragShader">#version 300 es
precision highp float;
uniform vec2 u_resolution;
uniform float u_time;
uniform vec2 u_mouse;
uniform sampler2D s_noise;
uniform sampler2D b_noise;
in vec2 v_uv;
in vec3 c;
in vec3 v_n;
in vec3 v_pos;
out vec4 colour;
vec2 getScreenSpace() {
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / min(u_resolution.y, u_resolution.x);
return uv;
}
float ndot(vec2 a, vec2 b ) { return a.x*b.x - a.y*b.y; }
float sdRhombus( in vec2 p, in vec2 b )
{
p = abs(p);
float h = clamp( ndot(b-2.0*p,b)/dot(b,b), -1.0, 1.0 );
float d = length( p-0.5*b*vec2(1.0-h,1.0+h) );
return d * sign( p.x*b.y + p.y*b.x - b.x*b.y );
}
void main() {
vec2 uv = getScreenSpace();
uv *= 1.;
// float m = abs(fract(min(v_uv.x, v_uv.y)*100. * uv.y - u_time * 5.) - .4) - .3;
float m = abs(fract(v_uv.y*100. * max(.2, smoothstep(.6, -.6, uv.y+uv.x)) - u_time * 5.) - .5) - .3;
vec2 vv_uv = v_uv * (u_resolution.y > u_resolution.x ? vec2((u_resolution.x / u_resolution.y), 1.) : vec2(1., (u_resolution.y / u_resolution.x)));
vv_uv = fract(vv_uv*20.) - .5;
m = length(vv_uv)-.4;
m = sdRhombus(vv_uv, vec2(.5));
vec3 U = dFdx(v_pos);
vec3 V = dFdy(v_pos);
vec3 n = normalize(cross(U, V));
float mask = smoothstep(fwidth(m), 0., m);
// n += normalize(abs(v_n));
float ls = dot(n, normalize(vec3(10, -10, 10)))+.5;
// ls = 1.;
colour = vec4(vec3(c*ls),1);
}
</script>
<script type="text/vertex" id="vertShader">#version 300 es
in vec3 position;
in vec2 uv;
in vec3 normal;
out vec2 v_uv;
out vec3 v_n;
out vec3 v_pos;
out vec3 c;
uniform float u_time;
uniform vec2 u_resolution;
uniform vec2 u_position;
uniform float u_zoom;
uniform float u_seed;
vec3 pal( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d )
{
return a + b*cos( 6.28318*(c*t+d) );
}
/* discontinuous pseudorandom uniformly distributed in [-0.5, +0.5]^3 */
vec3 random3(vec3 c) {
float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));
vec3 r;
r.z = fract(512.0*j);
j *= .125;
r.x = fract(512.0*j);
j *= .125;
r.y = fract(512.0*j);
return r-0.5;
}
/* skew constants for 3d simplex functions */
const float F3 = 0.3333333;
const float G3 = 0.1666667;
/* 3d simplex noise */
float simplex3d(vec3 p) {
/* 1. find current tetrahedron T and it's four vertices */
/* s, s+i1, s+i2, s+1.0 - absolute skewed (integer) coordinates of T vertices */
/* x, x1, x2, x3 - unskewed coordinates of p relative to each of T vertices*/
/* calculate s and x */
vec3 s = floor(p + dot(p, vec3(F3)));
vec3 x = p - s + dot(s, vec3(G3));
/* calculate i1 and i2 */
vec3 e = step(vec3(0.0), x - x.yzx);
vec3 i1 = e*(1.0 - e.zxy);
vec3 i2 = 1.0 - e.zxy*(1.0 - e);
/* x1, x2, x3 */
vec3 x1 = x - i1 + G3;
vec3 x2 = x - i2 + 2.0*G3;
vec3 x3 = x - 1.0 + 3.0*G3;
/* 2. find four surflets and store them in d */
vec4 w, d;
/* calculate surflet weights */
w.x = dot(x, x);
w.y = dot(x1, x1);
w.z = dot(x2, x2);
w.w = dot(x3, x3);
/* w fades from 0.6 at the center of the surflet to 0.0 at the margin */
w = max(0.6 - w, 0.0);
/* calculate surflet components */
d.x = dot(random3(s), x);
d.y = dot(random3(s + i1), x1);
d.z = dot(random3(s + i2), x2);
d.w = dot(random3(s + 1.0), x3);
/* multiply d by w^4 */
w *= w;
w *= w;
d *= w;
/* 3. return the sum of the four surflets */
return dot(d, vec4(52.0));
}
#define numOctaves 3
float fbm( in vec3 x, in float H ) {
float G = exp2(-H);
float f = 1.0;
float a = 1.0;
float t = 0.0;
for( int i=0; i<numOctaves; i++ )
{
t += a*simplex3d(f*x);
f *= 2.5;
a *= G;
}
return t;
}
vec2 getScreenSpace() {
vec2 uv = (position.xy * u_resolution.xy - 0.5 * u_resolution.xy) / min(u_resolution.y, u_resolution.x);
return uv;
}
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5*(a-b)/k, 0.0, 1.0);
return mix(a, b, h) - k*h*(1.0-h);
}
void main() {
// vec2 tuv = getScreenSpace()*.8*u_zoom+u_position*2.;
mat2 rot = mat2(1,0,0,1);
{
float a = 3.1415936 * .25;
float s = sin(a);
float c = cos(a);
// rot = mat2(c, -s, s, c);
}
vec2 tuv = position.xy * rot * u_zoom+u_position*2.;
// float tuvmodulo = (sin(tuv.y*5.) * .5 + .4) * 20.;
// // tuvmodulo = 10.;
// tuv = floor(tuv*tuvmodulo)/tuvmodulo;
float n = simplex3d(vec3(tuv*.5, -1000.+u_time));
// float n = fbm(vec3(tuv*.5, -1000.+u_time), .5);
float nc = n;
// n = ceil(n*2.)/2.;
n += simplex3d(vec3(tuv*2.*.3+4.7, -1000.+u_time*.5)*2.)*.8;
float ncol = simplex3d(vec3(100.+tuv*.1, -1000.+u_time*.5)*2.)*.8;
vec3 offset = vec3(
(nc*-.5)/u_zoom*.5*min(u_resolution.y, u_resolution.x)
// + sin(position.y*20.+position.x*5.) * (cos(position.x*5.) * 70. + 70.)
,
n/u_zoom*.5*min(u_resolution.y, u_resolution.x),
-(n*.5+.5)
);
vec3 pos = position;
pos *= vec3(u_resolution.xy, 1.);
// pos.z -= n*.5+.5;
// pos.y += n/u_zoom*.5*min(u_resolution.y, u_resolution.x);
// pos.x += (nc*-.5)/u_zoom*.5*min(u_resolution.y, u_resolution.x);
pos += offset;
pos /= vec3(u_resolution.xy, 1.);
pos.xy *= rot;
offset /= vec3(u_resolution.xy, 1.);
// c = pal( nc*%%rn%%+(pos.y+u_position.y/u_zoom)*.15+u_time, vec3(.7),vec3(.3),vec3(1.0,.95,.9),vec3(0.0,0.33,0.67) );
c = pal(nc*.5+u_seed, vec3(.7),vec3(.3),vec3(1.0,.95,.9),vec3(0.0,0.33,0.67));
// pos.z = clamp(pos.z, -1., 1.);
pos.z = smin(pos.z, -1., -0.2);
// pos.z = smin(pow(pos.z, -2.), -1., -0.2);
gl_Position = vec4(pos, 1.0);
v_uv = uv;
v_pos = pos.xyz;
v_n = offset;
}
</script>
</body>
</html>