-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglass-flame.html
More file actions
489 lines (421 loc) · 12.9 KB
/
Copy pathglass-flame.html
File metadata and controls
489 lines (421 loc) · 12.9 KB
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Glass Flame</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
background: #080508;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
padding: 16px;
gap: 14px;
overflow-y: auto;
}
canvas {
display: block;
border-radius: 8px;
width: min(calc(100vw - 32px), calc((100vh - 220px) * 16 / 9));
aspect-ratio: 16 / 9;
flex-shrink: 0;
}
.panel {
background: rgba(255,255,255,0.055);
border: 1px solid rgba(255,255,255,0.09);
border-radius: 14px;
padding: 13px 16px;
width: min(calc(100vw - 32px), 640px);
display: flex;
flex-direction: column;
gap: 9px;
}
.row {
display: flex;
align-items: center;
gap: 10px;
}
.lbl {
font-size: 11px;
color: rgba(255,255,255,0.35);
width: 72px;
flex-shrink: 0;
text-transform: uppercase;
letter-spacing: 0.05em;
}
input[type=range] {
flex: 1;
accent-color: rgba(255,255,255,0.55);
cursor: pointer;
height: 3px;
}
.val {
font-size: 11px;
color: rgba(255,255,255,0.45);
font-variant-numeric: tabular-nums;
min-width: 30px;
text-align: right;
}
.seg {
display: flex;
gap: 1px;
background: rgba(255,255,255,0.05);
border-radius: 8px;
padding: 3px;
}
.seg button {
background: none;
border: none;
color: rgba(255,255,255,0.35);
padding: 4px 10px;
border-radius: 6px;
font-size: 11px;
cursor: pointer;
font-family: inherit;
transition: all 0.12s;
white-space: nowrap;
}
.seg button.active {
background: rgba(255,255,255,0.13);
color: rgba(255,255,255,0.85);
}
.seg button:hover:not(.active) { color: rgba(255,255,255,0.6); }
.btns {
display: flex;
gap: 6px;
flex-wrap: wrap;
margin-top: 1px;
}
.btns button {
background: rgba(255,255,255,0.06);
border: 1px solid rgba(255,255,255,0.09);
color: rgba(255,255,255,0.65);
padding: 5px 13px;
border-radius: 7px;
font-size: 11px;
cursor: pointer;
font-family: inherit;
transition: all 0.12s;
}
.btns button:hover { background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.9); }
.btns button.rec { background: #ff3b30; border-color: #ff3b30; color: #fff; }
input[type=color] {
-webkit-appearance: none;
appearance: none;
width: 32px;
height: 32px;
border: none;
border-radius: 7px;
padding: 2px;
cursor: pointer;
background: none;
flex-shrink: 0;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch {
border: 1px solid rgba(255,255,255,0.18);
border-radius: 6px;
}
.top-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
flex-wrap: wrap;
}
.title {
font-size: 11px;
color: rgba(255,255,255,0.28);
letter-spacing: 0.08em;
text-transform: uppercase;
}
.hr { height: 1px; background: rgba(255,255,255,0.07); margin: 1px 0; }
</style>
</head>
<body>
<canvas id="c"></canvas>
<div class="panel">
<div class="top-row">
<span class="title">Glass Flame</span>
</div>
<div class="hr"></div>
<div class="row">
<span class="lbl">Shadow</span>
<input type="color" id="cShadow" value="#3d0808">
<span class="lbl" style="width:auto;padding-left:10px">Core</span>
<input type="color" id="cCore" value="#ff5800">
</div>
<div class="row">
<span class="lbl">Warp</span>
<input type="range" id="sWarp" min="0" max="2" value="1" step="0.05">
<span class="val" id="vWarp">1.00</span>
</div>
<div class="row">
<span class="lbl">Speed</span>
<input type="range" id="sSpeed" min="0" max="2" value="0.7" step="0.05">
<span class="val" id="vSpeed">0.70</span>
</div>
<div class="row">
<span class="lbl">Glass</span>
<input type="range" id="sGlass" min="0" max="1" value="0.55" step="0.02">
<span class="val" id="vGlass">0.55</span>
</div>
<div class="hr"></div>
<div class="btns">
<button id="btnPlay" onclick="togglePlay()">⏸ Pause</button>
<button onclick="savePng()">↓ PNG</button>
<button id="btnRec" onclick="toggleRecord()">⏺ Record</button>
</div>
</div>
<script>
const canvas = document.getElementById('c');
const gl = canvas.getContext('webgl2', { preserveDrawingBuffer: true });
if (!gl) {
document.body.innerHTML = '<p style="color:#fff;padding:40px;font-family:sans-serif">WebGL2 is required.</p>';
}
let playing = true, elapsed = 0, lastTs = null;
let mediaRecorder = null, recordChunks = [];
function hexToRgb(hex) {
return [
parseInt(hex.slice(1,3),16)/255,
parseInt(hex.slice(3,5),16)/255,
parseInt(hex.slice(5,7),16)/255
];
}
const DPR = Math.min(devicePixelRatio, 2);
canvas.width = 1280;
canvas.height = 720;
gl.viewport(0, 0, 1280, 720);
function resizeCanvas() {
const w = Math.round(canvas.clientWidth * DPR);
const h = Math.round(canvas.clientHeight * DPR);
if (w > 0 && h > 0 && (canvas.width !== w || canvas.height !== h)) {
canvas.width = w;
canvas.height = h;
gl.viewport(0, 0, w, h);
}
}
new ResizeObserver(resizeCanvas).observe(canvas);
resizeCanvas();
// ---- Shaders ----
const VS = `#version 300 es
in vec2 aPos;
void main() { gl_Position = vec4(aPos, 0.0, 1.0); }
`;
const FS = `#version 300 es
precision highp float;
out vec4 fragColor;
uniform vec2 uRes;
uniform float uTime;
uniform float uSpeed;
uniform float uWarp;
uniform float uGlass;
uniform vec3 uColorA; // shadow
uniform vec3 uColorB; // core / bright
// Value noise
float hash(vec2 p) {
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
}
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), f.x),
mix(hash(i + vec2(0,1)), hash(i + vec2(1.0, 1.0)), f.x), f.y);
}
// FBM — 5 octaves with slight rotation per layer
float fbm(vec2 p) {
float v = 0.0, a = 0.5;
for (int i = 0; i < 5; i++) {
v += a * noise(p);
// slight rotation + offset between octaves breaks axis-aligned artifacts
float px = p.x * 2.07 - p.y * 0.24 + 3.17;
float py = p.x * 0.24 + p.y * 2.07 + 1.93;
p = vec2(px, py);
a *= 0.48;
}
return v;
}
// Color gradient: black → shadow color → core color → white
// Tips always desaturate to near-white to sell the glowing/specular look
vec3 baseColor(float f) {
vec3 bright = mix(uColorB, vec3(1.0), 0.42); // core → white
vec3 c = vec3(0.0);
c = mix(c, uColorA * 0.7, smoothstep(0.12, 0.35, f));
c = mix(c, uColorA, smoothstep(0.28, 0.50, f));
c = mix(c, uColorB, smoothstep(0.42, 0.64, f));
c = mix(c, bright, smoothstep(0.58, 0.78, f));
c = mix(c, vec3(1.0), smoothstep(0.72, 0.88, f));
return c;
}
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main() {
vec2 uv = gl_FragCoord.xy / uRes;
float aspect = uRes.x / uRes.y;
vec2 p = vec2(uv.x * aspect, uv.y);
float t = uTime * uSpeed;
// --- Domain-warped FBM ---
// Base coordinate drifts upward over time (fire rises)
vec2 p0 = p * 2.5 - vec2(0.0, t * 0.30);
// First warp layer
vec2 q = vec2(
fbm(p0 ),
fbm(p0 + vec2(4.8, 2.2) )
);
// Second warp layer (slower, different direction)
vec2 r = vec2(
fbm(p0 + q * uWarp + vec2(1.7, 9.2)),
fbm(p0 + q * uWarp + vec2(8.3, 2.8))
);
// Final warped coordinate
vec2 fp = p0 + r * uWarp * 0.80;
float f = fbm(fp);
// --- Surface normal from FBM gradient ---
float ne = 0.014;
vec2 dn = vec2(
fbm(fp + vec2(ne, 0.0)) - fbm(fp - vec2(ne, 0.0)),
fbm(fp + vec2(0.0, ne)) - fbm(fp - vec2(0.0, ne))
) * (1.0 / (2.0 * ne));
vec3 N = normalize(vec3(dn * 1.8, 1.0));
// --- Base color from palette ---
// Subtle chromatic dispersion: R/B sample at slightly offset positions
float cd = uGlass * 0.016;
vec3 col = vec3(
baseColor(fbm(fp + dn * cd )).r,
baseColor(f ).g,
baseColor(fbm(fp - dn * cd )).b
);
// --- Specular highlights (two light sources) ---
vec3 L1 = normalize(vec3( 0.40, 0.85, 1.20));
vec3 L2 = normalize(vec3(-0.55, 0.50, 0.90));
vec3 V = vec3(0.0, 0.0, 1.0);
float spec1 = pow(max(0.0, dot(reflect(-L1, N), V)), 32.0) * 0.90;
float spec2 = pow(max(0.0, dot(reflect(-L2, N), V)), 14.0) * 0.50;
float spec = spec1 + spec2;
// --- Iridescent glass overlay ---
// Map surface angle + local FBM value to hue — creates soap-bubble / oil-film shimmer
float iridH = fract(f * 0.85 + dot(dn, vec2(0.42, 0.28)) * 0.35 + t * 0.022);
vec3 irid = hsv2rgb(vec3(iridH, 0.80, 0.95));
// Fresnel: edges of the surface catch more iridescent light
float fresnel = pow(1.0 - clamp(dot(N, V), 0.0, 1.0), 2.0);
// Blend iridescence at edges
col = mix(col, irid * (col * 0.4 + 0.6), fresnel * uGlass * 0.65);
// Add specular
col += vec3(spec) * (0.4 + uGlass * 0.7);
// --- Bloom: boost the very brightest areas ---
float lum = dot(col, vec3(0.30, 0.59, 0.11));
col += col * smoothstep(0.55, 1.0, lum) * 0.35;
// --- Tone map + gentle gamma ---
col = col / (col + vec3(0.80));
col = pow(max(col, vec3(0.0)), vec3(1.0 / 1.12));
fragColor = vec4(col, 1.0);
}
`;
function mkShader(type, src) {
const s = gl.createShader(type);
gl.shaderSource(s, src);
gl.compileShader(s);
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS))
console.error('Shader error:', gl.getShaderInfoLog(s));
return s;
}
const prog = gl.createProgram();
gl.attachShader(prog, mkShader(gl.VERTEX_SHADER, VS));
gl.attachShader(prog, mkShader(gl.FRAGMENT_SHADER, FS));
gl.linkProgram(prog);
if (!gl.getProgramParameter(prog, gl.LINK_STATUS))
console.error('Link error:', gl.getProgramInfoLog(prog));
gl.useProgram(prog);
const buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1,-1, 1,-1, -1,1, 1,1]), gl.STATIC_DRAW);
const aPos = gl.getAttribLocation(prog, 'aPos');
gl.enableVertexAttribArray(aPos);
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
const U = {
res: gl.getUniformLocation(prog, 'uRes'),
time: gl.getUniformLocation(prog, 'uTime'),
speed: gl.getUniformLocation(prog, 'uSpeed'),
warp: gl.getUniformLocation(prog, 'uWarp'),
glass: gl.getUniformLocation(prog, 'uGlass'),
colorA: gl.getUniformLocation(prog, 'uColorA'),
colorB: gl.getUniformLocation(prog, 'uColorB'),
};
function frame(ts) {
if (lastTs !== null && playing) elapsed += (ts - lastTs) / 1000;
lastTs = ts;
const ca = hexToRgb(document.getElementById('cShadow').value);
const cb = hexToRgb(document.getElementById('cCore').value);
gl.uniform2f(U.res, canvas.width, canvas.height);
gl.uniform1f(U.time, elapsed);
gl.uniform1f(U.speed, parseFloat(document.getElementById('sSpeed').value));
gl.uniform1f(U.warp, parseFloat(document.getElementById('sWarp').value));
gl.uniform1f(U.glass, parseFloat(document.getElementById('sGlass').value));
gl.uniform3f(U.colorA, ca[0], ca[1], ca[2]);
gl.uniform3f(U.colorB, cb[0], cb[1], cb[2]);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
// ---- Controls ----
[
['sWarp', 'vWarp', 2],
['sSpeed', 'vSpeed', 2],
['sGlass', 'vGlass', 2],
].forEach(([sid, vid, dp]) => {
document.getElementById(sid).addEventListener('input', () => {
document.getElementById(vid).textContent =
parseFloat(document.getElementById(sid).value).toFixed(dp);
});
});
function togglePlay() {
playing = !playing;
if (playing) lastTs = null;
document.getElementById('btnPlay').textContent = playing ? '⏸ Pause' : '▶ Play';
}
function savePng() {
const a = document.createElement('a');
a.download = 'glass-flame.png';
a.href = canvas.toDataURL('image/png');
a.click();
}
let mediaRecorder2 = null, recordChunks2 = [];
function toggleRecord() {
const btn = document.getElementById('btnRec');
if (!mediaRecorder2) {
const mimeType = ['video/webm;codecs=vp9','video/webm;codecs=vp8','video/webm']
.find(m => MediaRecorder.isTypeSupported(m));
const stream = canvas.captureStream(30);
mediaRecorder2 = new MediaRecorder(stream, { mimeType, videoBitsPerSecond: 8_000_000 });
recordChunks2 = [];
mediaRecorder2.ondataavailable = e => { if (e.data.size > 0) recordChunks2.push(e.data); };
mediaRecorder2.onstop = () => {
const blob = new Blob(recordChunks2, { type: mimeType });
const a = document.createElement('a');
a.download = 'glass-flame.webm';
a.href = URL.createObjectURL(blob);
a.click();
URL.revokeObjectURL(a.href);
mediaRecorder2 = null;
};
mediaRecorder2.start();
btn.textContent = '⏹ Stop';
btn.classList.add('rec');
if (!playing) togglePlay();
} else {
mediaRecorder2.stop();
btn.textContent = '⏺ Record';
btn.classList.remove('rec');
}
}
</script>
</body>
</html>