-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathraymarching_kado.html
712 lines (602 loc) · 18.7 KB
/
raymarching_kado.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
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
<!DOCTYPE html>
<!--
// Title: MandelBox inspired by "KADO: The Right Answer"
// Copyright (c) 2017 gam0022
// License: MIT
-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>three.js webgl - raymarching - carbon</title>
<style type="text/css">
body {
background-color: black;
margin: 0;
padding: 0;
}
a { color: skyblue }
canvas {
display: block;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
#info {
color: white;
font-size: 13px;
position: absolute;
bottom: 10px;
width: 100%;
text-align: center;
z-index: 100;
}
</style>
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - webgl raymarching demo - MandelBox inspired by <a href="http://seikaisuru-kado.com/">"KADO: The Right Answer"</a> by <a href="https://github.com/gam0022" target="_blank">gam0022</a><br>
<a href="http://gam0022.net/blog/2017/06/30/raymarching-kado/" target="_blank">正解するカドの「カド」をレイマーチングでリアルタイム描画する(article in Japanese)</a>
</div>
<script id="fragment_shader" type="x-shader/x-fragment">
#extension GL_EXT_shader_texture_lod : enable
precision highp float;
// uniforms
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
uniform samplerCube textureCube;
uniform sampler2D groundHeight;
uniform bool debugCamera;
uniform vec3 cameraPos;
uniform vec3 cameraDir;
// uniform float kadoScale;
float kadoScale;
// consts
const float INF = 1e+10;
const float EPS = 1e-2;
const float EPS_N = 1e-3;
const float OFFSET = EPS * 100.0;
const float PI = 3.14159265359;
const float PI2 = 6.28318530718;
const float PIH = 1.57079632679;
const float PIQ = 0.78539816339;
const float GROUND_BASE = 5.5;
// globals
const vec3 lightDir = vec3( -0.48666426339228763, 0.8111071056538127, -0.3244428422615251 );
float lTime;
// ray
struct Ray {
vec3 origin;
vec3 direction;
};
// camera
struct Camera {
vec3 eye, target;
vec3 forward, right, up;
float zoom;
};
Ray cameraShootRay(Camera c, vec2 uv) {
c.forward = normalize(c.target - c.eye);
c.right = normalize(cross(c.forward, c.up));
c.up = normalize(cross(c.right, c.forward));
Ray r;
r.origin = c.eye;
r.direction = normalize(uv.x * c.right + uv.y * c.up + c.zoom * c.forward);
return r;
}
// intersection
struct Intersection {
bool hit;
vec3 position;
float distance;
vec3 normal;
vec2 uv;
float count;
int material;
vec3 color;
float reflectance;
};
#define METAL_MATERIAL 0
#define GROUND_MATERIAL 1
// util
#define saturate(x) clamp(x, 0.0, 1.0)
// Distance Functions
float sdBox( vec3 p, vec3 b ) {
vec3 d = abs(p) - b;
return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));
}
#define WORK_TIME (60.0)
// http://blog.hvidtfeldts.net/index.php/2011/11/distance-estimated-3d-fractals-vi-the-mandelbox/
float minRadius2 = 0.5;
float fixedRadius2 = 1.0;
float foldingLimit = 1.0;
#define Iterations 8
void sphereFold(inout vec3 z, inout float dz) {
float r2 = dot(z,z);
if (r2 < minRadius2) {
// linear inner scaling
float temp = (fixedRadius2 / minRadius2);
z *= temp;
dz *= temp;
} else if (r2 < fixedRadius2) {
// this is the actual sphere inversion
float temp = fixedRadius2 / r2;
z *= temp;
dz *= temp;
}
}
void boxFold(inout vec3 z, inout float dz) {
z = clamp(z, -foldingLimit, foldingLimit) * 2.0 - z;
}
float dMbox(vec3 z) {
vec3 offset = z;
float dr = 1.0;
for (int n = 0; n < Iterations; n++) {
boxFold(z, dr); // Reflect
sphereFold(z, dr); // Sphere Inversion
z = kadoScale * z + offset; // Scale & Translate
dr = dr * abs(kadoScale) + 1.0;
}
float r = length(z);
return r / abs(dr);
}
float dScene(vec3 p) {
return dMbox(p);
}
// color functions
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, saturate(p - K.xxx), c.y);
}
#define calcNormal(p, dFunc) normalize(vec2(EPS_N, -EPS_N).xyy * dFunc(p + vec2(EPS_N, -EPS_N).xyy) + vec2(EPS_N, -EPS_N).yyx * dFunc(p + vec2(EPS_N, -EPS_N).yyx ) + vec2(EPS_N, -EPS_N).yxy * dFunc(p + vec2(EPS_N, -EPS_N).yxy) + vec2(EPS_N, -EPS_N).xxx * dFunc(p + vec2(EPS_N, -EPS_N).xxx))
float sdGround(in vec3 p) {
return p.y - texture2D(groundHeight, p.xz * 0.1).r + GROUND_BASE;
}
// 近くはレイマーチングによって正確に衝突判定し、遠くは平面として衝突判定を行う
void intersectGround(inout Intersection intersection, inout Ray ray) {
float d;
float distance = 0.0;
vec3 p = ray.origin;
for (float i = 0.0; i < 10.0; i++) {
d = sdGround(p);
distance += d;
p = ray.origin + distance * ray.direction;
intersection.count = i;
if (abs(d) < EPS) break;
}
if (abs(d) < EPS) {
intersection.distance = distance;
intersection.hit = true;
intersection.position = p;
intersection.normal = calcNormal(p, sdGround);
intersection.material = GROUND_MATERIAL;
} else {
float t = -(ray.origin.y + GROUND_BASE) / ray.direction.y;
if (t > 0.0) {
intersection.distance = t;
intersection.hit = true;
intersection.position = ray.origin + t * ray.direction;
intersection.normal = mix(calcNormal(intersection.position, sdGround), vec3(0.0, 1.0, 0.0), min(t * 0.01, 1.0) - ray.direction.y);
intersection.material = GROUND_MATERIAL;
}
}
}
void intersectObjects(inout Intersection intersection, inout Ray ray) {
float d;
float distance = 0.0;
vec3 p = ray.origin;
for (float i = 0.0; i < 100.0; i++) {
d = dScene(p);
distance += d;
p = ray.origin + distance * ray.direction;
intersection.count = i;
if (abs(d) < EPS || distance > 100.0) break;
}
if (abs(d) < EPS && distance < intersection.distance) {
intersection.distance = distance;
intersection.hit = true;
intersection.position = p;
intersection.normal = calcNormal(p, dScene);
intersection.material = METAL_MATERIAL;
}
}
void intersectScene(inout Intersection intersection, inout Ray ray) {
intersection.distance = INF;
intersectGround(intersection, ray);
intersectObjects(intersection, ray);
}
float calcAo(in vec3 p, in vec3 n){
float sca = 1.0, occ = 0.0;
for(float i=0.; i<5.; i++){
float hr = 0.05 + i * 0.08;
float dd = dScene(n * hr + p);
occ += (hr - dd) * sca;
sca *= 0.5;
}
return saturate(1.0 - occ);
}
float calcShadow(in vec3 p, in vec3 rd) {
float d;
float distance = OFFSET;
float bright = 1.0;
float shadowIntensity = 0.4;
float shadowSharpness = 10.0;
for (int i = 0; i < 30; i++) {
d = dScene(p + rd * distance);
if (d < EPS) return shadowIntensity;
bright = min(bright, shadowSharpness * d / distance);
distance += d;
}
return shadowIntensity + (1.0 - shadowIntensity) * bright;
}
void calcRadiance(inout Intersection intersection, inout Ray ray, int bounce) {
intersection.hit = false;
intersectScene(intersection, ray);
if ( intersection.hit ) {
float diffuse = clamp(dot(lightDir, intersection.normal), 0.2, 1.0) * 0.5 + 0.5;
float specular = pow(saturate(dot(reflect(lightDir, intersection.normal), ray.direction)), 10.0);
float ao = calcAo(intersection.position, intersection.normal);
float shadow = calcShadow(intersection.position, lightDir);
if (intersection.material == METAL_MATERIAL) {
vec3 metalBase = hsv2rgb(vec3(0.1 * intersection.count + sin(0.05 * PI2 * lTime), 0.7 * 0.5 + abs(0.05 * PI2 * sin(0.1 * lTime)), 0.9));
intersection.color = metalBase * diffuse * ao * shadow + 0.1 * specular;
intersection.reflectance = 0.7;
} else {
vec3 metalBase = vec3(0.17, 0.25, 0.28);
intersection.color = metalBase * diffuse * ao * shadow + 0.5 * specular;
float f0 = 0.7;
intersection.reflectance = f0 + (1.0 - f0) * pow(1.0 + ray.direction.y, 5.0);
}
} else {
intersection.color = textureCubeLodEXT(textureCube, ray.direction, 0.0).rgb;
}
}
void main(void) {
// set globals
lTime = mod(time, WORK_TIME);
kadoScale = 2.6 + 0.2 * cos(0.1 * PI2 * time);
// fragment position
vec2 uv = ( gl_FragCoord.xy * 2.0 - resolution ) / min( resolution.x, resolution.y );
// camera and ray
Camera camera;
camera.eye = cameraPos;
camera.target = cameraPos + cameraDir;
camera.up = vec3(0.0, 1.0, 0.0);// y-up
camera.zoom = 2.0;
Ray ray = cameraShootRay(camera, uv);
vec3 color = vec3(0.0);
float reflection = 1.0;
Intersection intersection;
for (int bounce = 0; bounce <= 2; bounce++) {
calcRadiance(intersection, ray, bounce);
color += reflection * intersection.color;
if (!intersection.hit) break;
reflection *= intersection.reflectance;
ray.origin = intersection.position + intersection.normal * OFFSET;
ray.direction = normalize(reflect(ray.direction, intersection.normal));
}
gl_FragColor = vec4(color, 1.0);
}
</script>
<script id="ground_fragment_shader" type="x-shader/x-vertex">
precision highp float;
uniform vec2 resolution;
uniform sampler2D random;
void main(void) {
vec2 uv = gl_FragCoord.xy / resolution;
float a = texture2D(random, uv).r;
vec3 color = vec3(pow(a, 2.0));
gl_FragColor = vec4(color, 1.0);
}
</script>
<script id="vertex_shader" type="x-shader/x-vertex">
attribute vec3 position;
void main(void) {
gl_Position = vec4(position, 1.0);
}
</script>
<script src="js/three.min.js"></script>
<script src="js/controls/OrbitControls.js"></script>
<script src="js/libs/stats.min.js"></script>
<script src="js/libs/dat.gui.min.js"></script>
<script src="js/common/noise.js"></script>
<script>
var camera, orbitControls, renderer;
var prevCameraMatrixWorld;
var textureScene, mainScene;
var mouse = new THREE.Vector2( 0.5, 0.5 );
var canvas;
var stats;
var textureCube, texture2Ds;
var clock = new THREE.Clock();
var config = {
saveImage: function() {
render(true);
window.open(canvas.toDataURL());
},
camera: 'Orbit',
resolution: 512,
aspectRatio: 1,
pixelRatio: 2.0,
time: 0,
pause: true,
animateWater: false,
// mandel box
kadoScale: 2.7,
};
init();
animate();
function createQuadScene(parameters) {
var scene = new THREE.Scene();
var geometry = new THREE.PlaneBufferGeometry(2.0, 2.0);
var material = new THREE.RawShaderMaterial({
uniforms: parameters.uniforms,
vertexShader: parameters.vertexShader,
fragmentShader: parameters.fragmentShader,
});
var plane = new THREE.Mesh(geometry, material);
plane.frustumCulled = false;
scene.add(plane);
return {
scene: scene,
geometry: geometry,
material: material,
};
}
function createTextureCube(cubeTextureLoader, rootPath, ext) {
var urls = [
rootPath + "px." + ext, rootPath + "nx." + ext,
rootPath + "py." + ext, rootPath + "ny." + ext,
rootPath + "pz." + ext, rootPath + "nz." + ext,
];
var textureCube = cubeTextureLoader.load(urls, function(texture) {
render(true);
});
textureCube.format = THREE.RGBFormat;
textureCube.mapping = THREE.CubeReflectionMapping;
//textureCube.generateMipmaps = false;
return textureCube;
}
function createRandomDataTexture(width, height) {
var data = new Float32Array(width * height * 4);
for (var k = 0, kl = data.length; k < kl; k += 4) {
data[k] = Math.random();
data[k + 1] = 0.0;
data[k + 2] = 0.0;
data[k + 3] = 1.0;
}
var texture = new THREE.DataTexture(
data,
width,
height,
THREE.RGBAFormat,
THREE.FloatType,
THREE.UVMapping,
THREE.RepeatWrapping,
THREE.RepeatWrapping,
THREE.LinearFilter,
THREE.LinearFilter,
);
texture.needsUpdate = true;
return texture;
}
function createPerlinNoiseTexture(width, height, z) {
var data = new Float32Array(width * height * 4);
var repeat = 4;
var perlin = new Perlin(repeat);
for (var y = 0.0; y < height; y++) {
for (var x = 0.0; x < width; x++) {
var k = (y * width + x) * 4;
var a = perlin.OctavePerlin(x / width * repeat, y / width * repeat, z, 8, 0.4);
data[k] = Math.pow(a, 3.0);
data[k + 1] = 0.0;
data[k + 2] = 0.0;
data[k + 3] = 1.0;
}
}
var texture = new THREE.DataTexture(
data,
width,
height,
THREE.RGBAFormat,
THREE.FloatType,
THREE.UVMapping,
THREE.RepeatWrapping,
THREE.RepeatWrapping,
THREE.LinearFilter,
THREE.LinearFilter,
);
texture.needsUpdate = true;
return texture;
}
/*
function createRenderTarget(width, height) {
return new THREE.WebGLRenderTarget(width, height, {
wrapS: THREE.RepeatWrapping,
wrapT: THREE.RepeatWrapping,
minFilter: THREE.LinearFilter,
magFilter: THREE.LinearFilter,
format: THREE.RGBAFormat,
type: THREE.FloatType,
stencilBuffer: false,
depthBuffer: false
});
}
function createGroundHeightTextureWithShader(renderer, camera, width, height) {
var randomTexture = createPerlinNoiseTexture(width, height);
var output = createRenderTarget(width, height);
var scene = createQuadScene({
uniforms: {
resolution: {type: 'v2', value: new THREE.Vector2(width, height)},
random: {type: 't', value: randomTexture},
},
vertexShader: document.getElementById('vertex_shader').textContent,
fragmentShader: document.getElementById('ground_fragment_shader').textContent
});
// renderer.render(scene.scene, camera);
renderer.render(scene.scene, camera, output);
return output;
}
function initTexture2D() {
var loader = new THREE.TextureLoader();
texture2Ds = {};
var createRepeatTexture = function(url) {
var texture = loader.load(url);
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
return texture;
}
texture2Ds.groundHeight = createRepeatTexture("textures/kaneta/RandomNoiseTexture5_DISP.png");
}*/
function initGUI() {
var gui = new dat.GUI();
gui.add(config, 'saveImage').name('Save as PNG');
//gui.add(config, 'camera', ['Auto', 'Orbit']).name('Camera');
gui.add(config, 'resolution', [256, 512, 800, 'full']).name('Resolution').onChange(function(value) {
onWindowResize();
render(true);
});
gui.add(config, 'aspectRatio', {'16:9': 16/9, '4:3' : 4/3, '2:1': 2, '1:1': 1.0}).name('Aspect Ratio').onChange(function(value) {
onWindowResize();
render(true);
});
gui.add(config, 'pixelRatio', {'1/4x': 0.25, '1/2x' : 0.5, '1x': 1.0, '2x': 2.0}).name('Pixel Ratio').onChange(function(value) {
onWindowResize();
render(true);
});
gui.add(config, 'time', 0, 60).step(0.1).name('time').listen();
gui.add(config, 'pause').name('Pause');
gui.add(config, 'animateWater').name('Animate Water');
//var kadoFolder = gui.addFolder("Kado");
//kadoFolder.add(config, 'kadoScale', -5, 5).name('Scale');
//kadoFolder.open();
stats = new Stats();
document.body.appendChild(stats.domElement);
}
function init() {
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio(config.pixelRatio);
renderer.setSize(config.resolution * config.aspectRatio, config.resolution);
if (!renderer.extensions.get("EXT_shader_texture_lod")) {
alert("EXT_shader_texture_lod is not supported.");
return;
}
camera = new THREE.PerspectiveCamera(35, 800/600);
camera.position.z = 16;
camera.lookAt(new THREE.Vector3(0.0, 0.0, 0.0));
var cubeTextureLoader = new THREE.CubeTextureLoader();
textureCube = createTextureCube(cubeTextureLoader, "textures/cube/ely_cloudtop/", "jpg");
texture2Ds = {};
texture2Ds.groundHeight = createPerlinNoiseTexture(256, 256, 0.5 * config.time);
mainScene = createQuadScene({
uniforms: {
resolution: {type: 'v2', value: new THREE.Vector2(config.resolution, config.resolution)},
mouse: {type: 'v2', value: mouse },
time: {type: 'f', value: 0.0 },
debugCamera: {type: 'i', value: config.camera !== 'Auto'},
cameraPos: {type: 'v3', value: camera.getWorldPosition()},
cameraDir: {type: 'v3', value: camera.getWorldDirection()},
kadoScale: {type: 'f', value: config.kadoScale},
textureCube: {type: 'tc', value: textureCube},
groundHeight: {type: 't', value: texture2Ds.groundHeight},
},
vertexShader: document.getElementById('vertex_shader').textContent,
fragmentShader: document.getElementById('fragment_shader').textContent
});
canvas = renderer.domElement;
canvas.addEventListener('mousemove', onMouseMove);
window.addEventListener('resize', onWindowResize);
document.body.appendChild(canvas);
orbitControls = new THREE.OrbitControls(camera, canvas);
orbitControls.enablePan = true;
//orbitControls.keyPanSpeed = 0.01;
orbitControls.enableDamping = false;
//orbitControls.dampingFactor = 0.015;
orbitControls.enableZoom = true;
//orbitControls.zoomSpeed = 0.001;
//orbitControls.rotateSpeed = 0.8;
orbitControls.autoRotate = false;
orbitControls.autoRotateSpeed = 0.0;
orbitControls.target = new THREE.Vector3(0.0, 0.0, 0.0);
initGUI();
onWindowResize();
}
function animate(timestamp) {
var delta = clock.getDelta();
if (!config.pause) {
config.time += delta;
}
stats.begin();
var needsUpdate = config.time !== mainScene.material.uniforms.time.value;
switch (config.camera) {
case 'Auto':
// none
break;
case 'Orbit':
orbitControls.update();
if (camera && prevCameraMatrixWorld && !camera.matrixWorld.equals(prevCameraMatrixWorld)) {
needsUpdate = true;
}
prevCameraMatrixWorld = camera.matrixWorld.clone();
break;
}
if (config.animateWater) {
texture2Ds.groundHeight = createPerlinNoiseTexture(256, 256, 0.5 * config.time);
mainScene.material.uniforms.groundHeight.value = texture2Ds.groundHeight;
}
render(needsUpdate);
stats.end();
requestAnimationFrame(animate);
}
function render(needsUpdate) {
mainScene.material.uniforms.resolution.value = new THREE.Vector2(canvas.width, canvas.height);
mainScene.material.uniforms.mouse.value = mouse;
mainScene.material.uniforms.debugCamera.value = config.camera !== 'Auto';
mainScene.material.uniforms.cameraPos.value = camera.getWorldPosition();
mainScene.material.uniforms.cameraDir.value = camera.getWorldDirection();
//mainScene.material.uniforms.kadoScale.value = config.kadoScale;
mainScene.material.uniforms.time.value = config.time;
if (needsUpdate) {
renderer.render(mainScene.scene, camera);
}
if (false) {
var pos = camera.getWorldPosition();
var dir = camera.getWorldDirection();
document.getElementById( 'info' ).innerHTML = ''
+ pos.x + ', ' + pos.y + ', ' + pos.z + '<br />'
+ dir.x + ', ' + dir.y + ', ' + dir.z + '<br />'
+ mainScene.material.uniforms.time.value;
}
}
function onMouseMove(e) {
mouse.x = e.offsetX / canvas.width;
mouse.y = e.offsetY / canvas.height;
}
function onWindowResize(e) {
if (config.resolution === 'full') {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
} else {
canvas.width = config.aspectRatio * config.resolution;
canvas.height = config.resolution;
}
renderer.setSize(canvas.width, canvas.height);
renderer.setPixelRatio(config.pixelRatio);
}
function outputTextToTab(text) {
var type = 'text/plain';
window.open('data:' + type + ';base64,' + window.btoa(text));
}
function outputShaderToTab(filter) {
var rawShader = document.getElementById('fragment_shader').textContent;
var text = filter(rawShader);
outputTextToTab(text);
}
</script>
</body>
</html>