-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
445 lines (386 loc) · 13.7 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<html>
<head>
<title>Islands</title>
<style>
canvas {
width: 100%;
height: 100%;
display: block;
}
body {
font-family: "Lucida Console", Monaco, monospace;
margin: 0;
display: flex;
flex-direction: row;
background-color: #F8F5EC;
}
.column {
display: flex;
overflow: hidden;
}
.sidebar {
position: absolute;
white-space: nowrap;
right: 0;
top: 0;
bottom: 0;
}
.box {
display: flex;
flex-grow: 1;
border: 1.5px solid black;
margin: .5rem;
background-color: #f6d55ccf;
/*#F6D55C;*/
flex-direction: column;
position: relative;
max-width: 350px;
transition: all .2s;
max-height: calc(100% - 1rem);
}
.box.closed {
max-width: 10px;
overflow: hidden;
}
.box>* {
opacity: 1;
transition: all .2s ease-out;
}
.box.closed>* {
opacity: 0;
}
.subtitle {
margin-top: .25rem;
display: flex;
padding: .5rem;
margin-left: .5rem;
}
.title {
margin-top: .25rem;
display: flex;
align-self: center;
padding: .5rem;
font-size: larger;
}
.title::before {
content: "\2014";
}
.title::after {
content: "\2014";
}
.rangewrapper {
margin-left: 1rem;
margin-right: 1rem;
margin-bottom: 1rem;
}
.button {
cursor: pointer;
display: flex;
background-color: #F8F5EC;
border: 1.5px solid black;
align-self: center;
padding: .25rem;
margin-bottom: 1rem;
}
.button:hover {
color: white;
box-shadow: inset 6.5em 0 0 0 #000;
}
.checkbox {
cursor: pointer;
margin: .5rem;
display: inline-block;
width: 1.5rem;
height: 1.5rem;
background-color: #F8F5EC;
border: 1.5px solid black;
}
.checkbox:hover {
background-color: rgb(238, 234, 234);
}
.checkbox::before {
display: none;
}
.checkbox.checked::before {
content: "";
display: block;
background-color: black;
width: 1rem;
height: 1rem;
margin: .25rem;
}
.checkboxwrapper {
display: flex;
flex-direction: row;
}
.checkboxlabel {
align-self: center;
margin-left: 1rem;
margin-right: 1rem;
}
.textinput {
font-family: inherit;
background-color: #F8F5EC;
border: 2px solid black;
font-size: 1rem;
padding: 7px 7px;
margin: 1rem;
outline: none;
}
.textinput:focus {
color: white;
box-shadow: inset 26.5em 0 0 0 #000;
}
.textinput:focus::placeholder {
color: rgb(204, 204, 204);
opacity: 1;
}
.bottom {
margin-top: auto;
}
.setting-group {
display: flex;
font-size: 80%;
}
#images {
display: flex;
overflow-x: auto;
margin: auto 1rem 1rem 1rem;
max-width: 298px;
}
#images canvas {
margin: 2px 1px 2px 1px;
cursor: pointer;
position: relative;
}
#toggle {
position: absolute;
left: 0;
width: 7px;
top: 0;
bottom: 0;
z-index: 1;
cursor: pointer;
}
</style>
<link rel="stylesheet" href="dist/slider.css">
<script id="vertexShader" type="x-shader/x-vertex">
#include <fog_pars_vertex>
varying vec2 vUv;
varying vec3 vPosition;
void main() {
vUv = uv;
#include <begin_vertex>
#include <project_vertex>
#include <fog_vertex>
vPosition = (modelMatrix * vec4(position, 1.0)).xyz;
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
#include <common>
#include <packing>
#include <fog_pars_fragment>
varying vec2 vUv;
varying vec3 vPosition;
uniform sampler2D tDepth;
uniform float size;
uniform float water_height;
uniform sampler2D tHeight;
uniform sampler2D tDudv;
uniform vec3 waterColor;
uniform vec3 foamColor;
uniform float cameraNear;
uniform float cameraFar;
uniform float time;
uniform float threshold;
uniform vec2 resolution;
float getDepth( const in vec2 screenPosition ) {
#if DEPTH_PACKING == 1
return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );
#else
return texture2D( tDepth, screenPosition ).x;
#endif
}
float getViewZ( const in float depth ) {
#if ORTHOGRAPHIC_CAMERA == 1
return orthographicDepthToViewZ( depth, cameraNear, cameraFar );
#else
return perspectiveDepthToViewZ( depth, cameraNear, cameraFar );
#endif
}
// psrdnoise (c) Stefan Gustavson and Ian McEwan,
// ver. 2021-12-02, published under the MIT license:
// https://github.com/stegu/psrdnoise/
vec2 psrdnoise(vec2 x, vec2 period, float alpha)
{
vec2 uv = vec2(x.x+x.y*0.5, x.y);
vec2 i0 = floor(uv), f0 = fract(uv);
float cmp = step(f0.y, f0.x);
vec2 o1 = vec2(cmp, 1.0-cmp);
vec2 i1 = i0 + o1, i2 = i0 + 1.0;
vec2 v0 = vec2(i0.x - i0.y*0.5, i0.y);
vec2 v1 = vec2(v0.x + o1.x - o1.y*0.5, v0.y + o1.y);
vec2 v2 = vec2(v0.x + 0.5, v0.y + 1.0);
vec2 x0 = x - v0, x1 = x - v1, x2 = x - v2;
vec3 iu, iv, xw, yw;
if(any(greaterThan(period, vec2(0.0)))) {
xw = vec3(v0.x, v1.x, v2.x);
yw = vec3(v0.y, v1.y, v2.y);
if(period.x > 0.0)
xw = mod(vec3(v0.x, v1.x, v2.x), period.x);
if(period.y > 0.0)
yw = mod(vec3(v0.y, v1.y, v2.y), period.y);
iu = floor(xw + 0.5*yw + 0.5); iv = floor(yw + 0.5);
} else {
iu = vec3(i0.x, i1.x, i2.x); iv = vec3(i0.y, i1.y, i2.y);
}
vec3 hash = mod(iu, 289.0);
hash = mod((hash*51.0 + 2.0)*hash + iv, 289.0);
hash = mod((hash*34.0 + 10.0)*hash, 289.0);
vec3 psi = hash*0.07482 + alpha;
vec3 gx = cos(psi); vec3 gy = sin(psi);
vec2 g0 = vec2(gx.x, gy.x);
vec2 g1 = vec2(gx.y, gy.y);
vec2 g2 = vec2(gx.z, gy.z);
vec3 w = 0.8 - vec3(dot(x0, x0), dot(x1, x1), dot(x2, x2));
w = max(w, 0.0); vec3 w2 = w*w; vec3 w4 = w2*w2;
vec3 gdotx = vec3(dot(g0, x0), dot(g1, x1), dot(g2, x2));
float n = dot(w4, gdotx);
vec3 w3 = w2*w; vec3 dw = -8.0*w3*gdotx;
vec2 dn0 = w4.x*g0 + dw.x*x0;
vec2 dn1 = w4.y*g1 + dw.y*x1;
vec2 dn2 = w4.z*g2 + dw.z*x2;
vec2 gradient = 10.9*(dn0 + dn1 + dn2);
return gradient;
}
float sampleHeight(vec2 loc){
vec2 one = vec2(1.0,1.0) / size;
return (texture2D(tHeight, loc + one*vec2(0.0, 0.0)).x+
texture2D(tHeight, loc + one*vec2(-1.0, -1.0)).x+
texture2D(tHeight, loc + one*vec2(1.0, -1.0)).x+
texture2D(tHeight, loc + one*vec2(-1.0, 1.0)).x+
texture2D(tHeight, loc + one*vec2(1.0, 1.0)).x) / 5.0;
}
void main() {
//vec2 screenUV = gl_FragCoord.xy / resolution;
//float fragmentLinearEyeDepth = getViewZ( gl_FragCoord.z );
//float linearEyeDepth = getViewZ( getDepth( screenUV ) );
//float diff = saturate( fragmentLinearEyeDepth - linearEyeDepth );
//vec2 displacement = texture2D( tDudv, ( vUv * 2.0 ) - time * 0.05 ).rg;
//displacement = ( ( displacement * 2.0 ) - 1.0 ) * 1.0;
//diff += displacement.x;
vec2 sLoc = (vPosition.xy / size) - vec2(.5, .5);
float height = sampleHeight(-sLoc);
// hieght 0 outside box
vec2 fixPos = (vPosition.xy / size);
height *= step(fixPos.x, .5) * step(-.5, fixPos.x) * step(fixPos.y, .5) * step( -.5, fixPos.y);
float hdiff = height - water_height;
float foam = step(-.1, hdiff);
foam = 1.0;
foam *= max(sin(height * 100.0 - time / 1000.0),0.0) * (hdiff + .3) * 4.0;
foam = pow(foam, 2.0) * 2.0;
foam += step(.9, foam);
foam = max(0.0, foam - .5);
foam *= max(0.0, psrdnoise(vPosition.xy / 10.0 + vec2(1.0,1.0) * time / 1000000.0, vec2(1.0,1.0) * 20000.0, 100.0).x);
//float width = 1.0;
//foam = pow(max(sin(height * 100.0 - time / 1000.0), 0.0), width);
//foam = foam - min(foam, .9);
//foam = pow(foam, .2);
gl_FragColor.rgb = mix(waterColor, foamColor, foam);
gl_FragColor.a = mix(.7, 1.0, foam);
#include <tonemapping_fragment>
#include <encodings_fragment>
#include <fog_fragment>
}
</script>
</head>
<body>
<div class="column" id="renderer-target">
</div>
<div class="column sidebar">
<div class="box">
<div id="toggle" onclick="document.getElementsByClassName('box')[0].classList.toggle('closed')"></div>
<div class="title"> settings </div>
<!-- <div class="checkboxwrapper">
<div class="checkbox checked" id="enablegrouping"></div>
<div class="checkboxlabel">
enable grouping
</div>
</div>
<div class="checkboxwrapper">
<div class="checkbox checked" id="enablesidelines"></div>
<div class="checkboxlabel">
enable sidelines
</div>
</div>
<div class="checkboxwrapper">
<div class="checkbox checked" id="enablemulti"></div>
<div class="checkboxlabel">
enable multi cuts
</div>
</div> -->
<div class="subtitle">Size</div>
<div class="rangewrapper">
<input type="range" min="3" max="500" value="32" class="parameter-control" key="size"></input>
</div>
<div class="subtitle">Layers</div>
<div class="rangewrapper">
<input type="range" min="2" max="100" value="30" class="parameter-control" key="layer_count"></input>
</div>
<div class="setting-group">
<div class="setting">
<div class="subtitle">Angle scale</div>
<div class="rangewrapper">
<input type="range" min="1" max="400" value="32" class="parameter-control"
key="angle.scale"></input>
</div>
</div>
<div class="setting">
<div class="subtitle">Angle octaves</div>
<div class="rangewrapper">
<input type="range" min="1" max="10" value="3" class="parameter-control"
key="angle.octaves"></input>
</div>
</div>
</div>
<div class="setting-group">
<div class="setting">
<div class="subtitle">Roughness scale</div>
<div class="rangewrapper">
<input type="range" min="1" max="400" value="32" class="parameter-control"
key="roughness.scale"></input>
</div>
</div>
<div class="setting">
<div class="subtitle">Roughness octaves</div>
<div class="rangewrapper">
<input type="range" min="1" max="10" value="3" class="parameter-control"
key="roughness.octaves"></input>
</div>
</div>
</div>
<div class="setting-group">
<div class="setting">
<div class="subtitle">Base scale</div>
<div class="rangewrapper">
<input type="range" min="1" max="400" value="32" class="parameter-control"
key="base.scale"></input>
</div>
</div>
<div class="setting">
<div class="subtitle">Base octaves</div>
<div class="rangewrapper">
<input type="range" min="1" max="10" value="3" class="parameter-control"
key="base.octaves"></input>
</div>
</div>
</div>
<input type="text" class="textinput" id="seed" placeholder="seed"></input>
<div class="button" id="generate">generate</div>
<!-- <div class="button" id="download">download</div> -->
<div id="images"></div>
</div>
</div>
</body>
<script src="dist/pack.js"></script>
</html>