forked from Rezmason/matrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmirrorPass.js
More file actions
62 lines (57 loc) · 1.61 KB
/
Copy pathmirrorPass.js
File metadata and controls
62 lines (57 loc) · 1.61 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
import { fullscreenQuadReglBase, loadText, makePassFBO, makePass, requireShaderString } from "./utils.js";
export default ({ regl, canvas, config, cameraTex, cameraAspectRatio }, inputs) => {
let start;
const numClicks = 5;
const clicks = Array(numClicks)
.fill()
.map((_) => [0, 0, -Infinity]);
let aspectRatio = 1;
let index = 0;
canvas.onmousedown = (e) => {
const rect = e.srcElement.getBoundingClientRect();
clicks[index][0] = 0 + (e.clientX - rect.x) / rect.width;
clicks[index][1] = 1 - (e.clientY - rect.y) / rect.height;
clicks[index][2] = (performance.now() - start) / 1000;
index = (index + 1) % numClicks;
};
const output = makePassFBO(regl, config.useHalfFloat);
const mirrorPassFrag = loadText("shaders/glsl/mirrorPass.frag.glsl");
let render;
const programsReady = mirrorPassFrag.loaded.then(() => {
render = regl({
...fullscreenQuadReglBase,
frag: requireShaderString("mirrorPass.frag", () => mirrorPassFrag.text()),
uniforms: {
time: regl.context("time"),
tex: inputs.primary,
bloomTex: inputs.bloom,
cameraTex,
// REGL bug can misinterpret array uniforms
["clicks[0]"]: () => clicks[0],
["clicks[1]"]: () => clicks[1],
["clicks[2]"]: () => clicks[2],
["clicks[3]"]: () => clicks[3],
["clicks[4]"]: () => clicks[4],
aspectRatio: () => aspectRatio,
cameraAspectRatio,
},
framebuffer: output,
});
});
start = performance.now();
return makePass(
{
primary: output,
},
programsReady,
(w, h) => {
output.resize(w, h);
aspectRatio = w / h;
},
(shouldRender) => {
if (shouldRender) {
render({});
}
},
);
};