micugl 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/index.d.ts +7 -0
- package/dist/core/lib/createShaderConfig.d.ts +16 -0
- package/dist/core/lib/vectorUtils.d.ts +8 -0
- package/dist/core/managers/FBOManager.d.ts +21 -0
- package/dist/core/managers/FBOManager.js +1 -0
- package/dist/core/managers/FBOManager.mjs +127 -0
- package/dist/core/managers/WebGLManager.d.ts +35 -0
- package/dist/core/managers/WebGLManager.js +1 -0
- package/dist/core/managers/WebGLManager.mjs +281 -0
- package/dist/core/systems/Passes.d.ts +11 -0
- package/dist/core/systems/Passes.js +1 -0
- package/dist/core/systems/Passes.mjs +84 -0
- package/dist/core/systems/Postprocessing.d.ts +31 -0
- package/dist/core/systems/Postprocessing.js +1 -0
- package/dist/core/systems/Postprocessing.mjs +135 -0
- package/dist/core.js +1 -0
- package/dist/core.mjs +20 -0
- package/dist/index.d.ts +3 -49
- package/dist/index.js +1 -1
- package/dist/index.mjs +14 -14
- package/dist/react/components/base/BasePingPongShaderComponent.d.ts +21 -0
- package/dist/react/components/base/BaseShaderComponent.d.ts +15 -0
- package/dist/react/components/engine/PingPongShaderEngine.d.ts +12 -0
- package/dist/react/components/engine/ShaderEngine.d.ts +18 -0
- package/dist/react/components/index.d.ts +0 -0
- package/dist/react/hooks/index.d.ts +3 -0
- package/dist/react/hooks/useDarkMode.d.ts +1 -0
- package/dist/react/hooks/usePingPongPasses.d.ts +21 -0
- package/dist/react/hooks/useUniformUpdaters.d.ts +4 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/lib/createUniformUpdater.d.ts +8 -0
- package/dist/react.js +1 -0
- package/dist/react.mjs +20 -0
- package/dist/types.d.ts +164 -204
- package/package.json +10 -40
- package/dist/MarbleScene.d.ts +0 -27
- package/dist/RippleScene.d.ts +0 -20
- package/dist/examples/Marble/MarbleScene.d.ts +0 -20
- package/dist/examples/Marble/MarbleScene.js +0 -1
- package/dist/examples/Marble/MarbleScene.mjs +0 -71
- package/dist/examples/Marble/marbleShaders.d.ts +0 -2
- package/dist/examples/Marble/marbleShaders.js +0 -129
- package/dist/examples/Marble/marbleShaders.mjs +0 -139
- package/dist/examples/Ripple/RippleScene.d.ts +0 -13
- package/dist/examples/Ripple/RippleScene.js +0 -1
- package/dist/examples/Ripple/RippleScene.mjs +0 -109
- package/dist/examples/Ripple/rippleShaders.d.ts +0 -3
- package/dist/examples/Ripple/rippleShaders.js +0 -80
- package/dist/examples/Ripple/rippleShaders.mjs +0 -94
- package/dist/examples/index.d.ts +0 -4
- package/dist/examples/index.js +0 -1
- package/dist/examples/index.mjs +0 -13
- package/dist/marbleShaders.d.ts +0 -5
- package/dist/rippleShaders.d.ts +0 -7
- package/dist/src/core/managers/FBOManager.js +0 -1
- package/dist/src/core/managers/FBOManager.mjs +0 -120
- package/dist/src/core/managers/WebGLManager.js +0 -1
- package/dist/src/core/managers/WebGLManager.mjs +0 -273
- package/dist/src/core/systems/Passes.js +0 -1
- package/dist/src/core/systems/Passes.mjs +0 -78
- package/dist/src/core/systems/Postprocessing.js +0 -1
- package/dist/src/core/systems/Postprocessing.mjs +0 -128
- package/dist/types.js +0 -1
- package/dist/types.mjs +0 -1
- /package/dist/{src/core → core}/lib/createShaderConfig.js +0 -0
- /package/dist/{src/core → core}/lib/createShaderConfig.mjs +0 -0
- /package/dist/{src/core → core}/lib/vectorUtils.js +0 -0
- /package/dist/{src/core → core}/lib/vectorUtils.mjs +0 -0
- /package/dist/{src/react → react}/components/base/BasePingPongShaderComponent.js +0 -0
- /package/dist/{src/react → react}/components/base/BasePingPongShaderComponent.mjs +0 -0
- /package/dist/{src/react → react}/components/base/BaseShaderComponent.js +0 -0
- /package/dist/{src/react → react}/components/base/BaseShaderComponent.mjs +0 -0
- /package/dist/{src/react → react}/components/engine/PingPongShaderEngine.js +0 -0
- /package/dist/{src/react → react}/components/engine/PingPongShaderEngine.mjs +0 -0
- /package/dist/{src/react → react}/components/engine/ShaderEngine.js +0 -0
- /package/dist/{src/react → react}/components/engine/ShaderEngine.mjs +0 -0
- /package/dist/{src/react → react}/hooks/useDarkMode.js +0 -0
- /package/dist/{src/react → react}/hooks/useDarkMode.mjs +0 -0
- /package/dist/{src/react → react}/hooks/usePingPongPasses.js +0 -0
- /package/dist/{src/react → react}/hooks/usePingPongPasses.mjs +0 -0
- /package/dist/{src/react → react}/hooks/useUniformUpdaters.js +0 -0
- /package/dist/{src/react → react}/hooks/useUniformUpdaters.mjs +0 -0
- /package/dist/{src/react → react}/lib/createUniformUpdater.js +0 -0
- /package/dist/{src/react → react}/lib/createUniformUpdater.mjs +0 -0
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
class h {
|
|
2
|
-
constructor(t) {
|
|
3
|
-
this.resources = /* @__PURE__ */ new Map(), this.floatTextureExtension = null, this.gl = t, this.floatTextureExtension = t.getExtension("OES_texture_float"), this.floatTexturesSupported = !!this.floatTextureExtension, t.getExtension("OES_texture_float_linear");
|
|
4
|
-
}
|
|
5
|
-
createFramebuffer(t, e) {
|
|
6
|
-
const r = this.gl, { width: s, height: u, textureCount: o = 2, textureOptions: a = {} } = e, n = [];
|
|
7
|
-
for (let f = 0; f < o; f++) {
|
|
8
|
-
const T = this.createTexture({
|
|
9
|
-
width: s,
|
|
10
|
-
height: u,
|
|
11
|
-
...a
|
|
12
|
-
});
|
|
13
|
-
n.push(T);
|
|
14
|
-
}
|
|
15
|
-
const i = r.createFramebuffer();
|
|
16
|
-
if (!i)
|
|
17
|
-
throw new Error("Failed to create framebuffer");
|
|
18
|
-
const E = {
|
|
19
|
-
framebuffer: i,
|
|
20
|
-
textures: n,
|
|
21
|
-
currentTextureIndex: 0,
|
|
22
|
-
width: s,
|
|
23
|
-
height: u
|
|
24
|
-
};
|
|
25
|
-
return this.resources.set(t, E), E;
|
|
26
|
-
}
|
|
27
|
-
createTexture(t) {
|
|
28
|
-
const e = this.gl, {
|
|
29
|
-
width: r,
|
|
30
|
-
height: s,
|
|
31
|
-
internalFormat: u = e.RGBA,
|
|
32
|
-
format: o = e.RGBA,
|
|
33
|
-
type: a = this.floatTexturesSupported ? e.FLOAT : e.UNSIGNED_BYTE,
|
|
34
|
-
minFilter: n = e.NEAREST,
|
|
35
|
-
magFilter: i = e.NEAREST,
|
|
36
|
-
wrapS: E = e.CLAMP_TO_EDGE,
|
|
37
|
-
wrapT: f = e.CLAMP_TO_EDGE,
|
|
38
|
-
generateMipmap: T = !1
|
|
39
|
-
} = t, c = e.createTexture();
|
|
40
|
-
if (!c)
|
|
41
|
-
throw new Error("Failed to create texture");
|
|
42
|
-
return e.bindTexture(e.TEXTURE_2D, c), e.texImage2D(e.TEXTURE_2D, 0, u, r, s, 0, o, a, null), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MIN_FILTER, n), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MAG_FILTER, i), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_S, E), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_T, f), T && e.generateMipmap(e.TEXTURE_2D), c;
|
|
43
|
-
}
|
|
44
|
-
bindFramebuffer(t, e) {
|
|
45
|
-
const r = this.gl;
|
|
46
|
-
if (t === null) {
|
|
47
|
-
r.bindFramebuffer(r.FRAMEBUFFER, null);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const s = this.resources.get(t);
|
|
51
|
-
if (!s)
|
|
52
|
-
throw new Error(`Framebuffer with id ${t} not found`);
|
|
53
|
-
const u = e ?? s.currentTextureIndex;
|
|
54
|
-
r.bindFramebuffer(r.FRAMEBUFFER, s.framebuffer), r.framebufferTexture2D(
|
|
55
|
-
r.FRAMEBUFFER,
|
|
56
|
-
r.COLOR_ATTACHMENT0,
|
|
57
|
-
r.TEXTURE_2D,
|
|
58
|
-
s.textures[u],
|
|
59
|
-
0
|
|
60
|
-
);
|
|
61
|
-
const o = r.checkFramebufferStatus(r.FRAMEBUFFER);
|
|
62
|
-
if (o !== r.FRAMEBUFFER_COMPLETE)
|
|
63
|
-
throw new Error(`Framebuffer is not complete: ${o}`);
|
|
64
|
-
}
|
|
65
|
-
bindTexture(t, e, r) {
|
|
66
|
-
const s = this.gl, u = this.resources.get(t);
|
|
67
|
-
if (!u)
|
|
68
|
-
throw new Error(`Framebuffer with id ${t} not found`);
|
|
69
|
-
const o = r ?? u.currentTextureIndex;
|
|
70
|
-
s.activeTexture(s.TEXTURE0 + e), s.bindTexture(s.TEXTURE_2D, u.textures[o]);
|
|
71
|
-
}
|
|
72
|
-
swapTextures(t) {
|
|
73
|
-
const e = this.resources.get(t);
|
|
74
|
-
if (!e)
|
|
75
|
-
throw new Error(`Framebuffer with id ${t} not found`);
|
|
76
|
-
e.currentTextureIndex = (e.currentTextureIndex + 1) % e.textures.length;
|
|
77
|
-
}
|
|
78
|
-
getPingPongIndices(t) {
|
|
79
|
-
const e = this.resources.get(t);
|
|
80
|
-
if (!e)
|
|
81
|
-
throw new Error(`Framebuffer with id ${t} not found`);
|
|
82
|
-
const r = e.currentTextureIndex, s = (r + 1) % e.textures.length;
|
|
83
|
-
return { read: r, write: s };
|
|
84
|
-
}
|
|
85
|
-
resizeFramebuffer(t, e, r) {
|
|
86
|
-
const s = this.gl, u = this.resources.get(t);
|
|
87
|
-
if (!u)
|
|
88
|
-
throw new Error(`Framebuffer with id ${t} not found`);
|
|
89
|
-
u.width === e && u.height === r || (u.textures.forEach((o) => {
|
|
90
|
-
s.bindTexture(s.TEXTURE_2D, o), s.texImage2D(
|
|
91
|
-
s.TEXTURE_2D,
|
|
92
|
-
0,
|
|
93
|
-
s.RGBA,
|
|
94
|
-
e,
|
|
95
|
-
r,
|
|
96
|
-
0,
|
|
97
|
-
s.RGBA,
|
|
98
|
-
this.floatTexturesSupported ? s.FLOAT : s.UNSIGNED_BYTE,
|
|
99
|
-
null
|
|
100
|
-
);
|
|
101
|
-
}), u.width = e, u.height = r);
|
|
102
|
-
}
|
|
103
|
-
destroy(t) {
|
|
104
|
-
const e = this.gl, r = this.resources.get(t);
|
|
105
|
-
r && (r.textures.forEach((s) => {
|
|
106
|
-
e.deleteTexture(s);
|
|
107
|
-
}), e.deleteFramebuffer(r.framebuffer), this.resources.delete(t));
|
|
108
|
-
}
|
|
109
|
-
destroyAll() {
|
|
110
|
-
Array.from(this.resources.keys()).forEach((t) => {
|
|
111
|
-
this.destroy(t);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
isFloatTexturesSupported() {
|
|
115
|
-
return this.floatTexturesSupported;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
export {
|
|
119
|
-
h as FBOManager
|
|
120
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./FBOManager.js");class m{constructor(t,n){this.resources=new Map,this.compileCache=new Map,this.uniformUpdateFns=new Map,this.extensions=new Map;const r={alpha:!1,depth:!1,stencil:!1,antialias:!1,powerPreference:"low-power",preserveDrawingBuffer:!1},e=t.getContext("webgl",{...r,...n});if(!e)throw new Error("WebGL not supported");this.gl=e,this.fboManager=new d.FBOManager(e),this.getExtension("OES_texture_float"),this.getExtension("OES_texture_float_linear"),this.getExtension("OES_vertex_array_object"),this.getExtension("ANGLE_instanced_arrays")}getExtension(t){if(this.extensions.has(t))return this.extensions.get(t);const n=this.gl.getExtension(t);return this.extensions.set(t,n),n}createProgram(t,n){const{vertexShader:r,fragmentShader:e,uniforms:o,attributes:i}=n,s=this.gl,h=this.getOrCompileShader("vertex:"+r,s.VERTEX_SHADER,r),l=this.getOrCompileShader("fragment:"+e,s.FRAGMENT_SHADER,e),f=s.createProgram();if(!f)throw new Error("Failed to create WebGL program");if(s.attachShader(f,h),s.attachShader(f,l),s.linkProgram(f),!s.getProgramParameter(f,s.LINK_STATUS)){const g=s.getProgramInfoLog(f);throw s.deleteProgram(f),new Error(`Could not link shader program: ${g}`)}const c={};for(const g of o)c[g.name]=s.getUniformLocation(f,g.name);const u={};if(i)for(const g of i)u[g.name]=s.getAttribLocation(f,g.name);const a={program:f,uniforms:c,attributes:u,buffers:{}};return this.resources.set(t,a),this.uniformUpdateFns.set(t,new Map),a}getOrCompileShader(t,n,r){if(this.compileCache.has(t)){const o=this.compileCache.get(t);if(o)return o}const e=this.compileShader(n,r);return this.compileCache.set(t,e),e}compileShader(t,n){const r=this.gl,e=r.createShader(t);if(!e)throw new Error("Failed to create shader");if(r.shaderSource(e,n),r.compileShader(e),!r.getShaderParameter(e,r.COMPILE_STATUS)){const o=r.getShaderInfoLog(e);throw r.deleteShader(e),new Error(`Shader compilation failed: ${o}`)}return e}createBuffer(t,n,r){const e=this.gl,o=this.resources.get(t);if(!o)throw new Error(`Program with id ${t} not found`);const i=e.createBuffer();if(!i)throw new Error("Failed to create buffer");return e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW),o.buffers[n]={buffer:i,data:r},i}updateBuffer(t,n,r){const e=this.gl,o=this.resources.get(t);if(!o)throw new Error(`Program with id ${t} not found`);const i=o.buffers[n];if(!i)throw new Error(`Buffer for attribute ${n} not found`);e.bindBuffer(e.ARRAY_BUFFER,i.buffer),e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW),i.data=r}registerUniformUpdater(t,n,r,e){const o=this.resources.get(t);if(!o)throw new Error(`Program with id ${t} not found`);const i=this.uniformUpdateFns.get(t);if(!i)throw new Error(`Program uniforms for id ${t} not found`);const s=o.uniforms[n];if(s===null)return;const h=this.gl;let l;switch(r){case"int":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform1i(s,a),a};break;case"float":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform1f(s,a),a};break;case"sampler2D":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform1i(s,a),a};break;case"vec2":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform2fv(s,a),a};break;case"vec3":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform3fv(s,a),a};break;case"vec4":l=(f,c,u)=>{const a=e(f,c,u);return h.uniform4fv(s,a),a};break;case"mat2":l=(f,c,u)=>{const a=e(f,c,u);return h.uniformMatrix2fv(s,!1,a),a};break;case"mat3":l=(f,c,u)=>{const a=e(f,c,u);return h.uniformMatrix3fv(s,!1,a),a};break;case"mat4":l=(f,c,u)=>{const a=e(f,c,u);return h.uniformMatrix4fv(s,!1,a),a};break;default:throw new Error(`Unsupported uniform type: ${r}`)}i.set(n,l)}updateUniforms(t,n){const r=this.uniformUpdateFns.get(t);if(!r)return;const e=this.gl.canvas,o=e.width,i=e.height;r.forEach(s=>{s(n,o,i)})}setSize(t,n,r=!0){const e=this.gl.canvas,o=r&&window.devicePixelRatio||1,i=Math.floor(t*o),s=Math.floor(n*o);(e.width!==i||e.height!==s)&&(e.width=i,e.height=s,e.style.width=`${t}px`,e.style.height=`${n}px`,this.gl.viewport(0,0,i,s))}prepareRender(t,n={}){const{clear:r=!0,clearColor:e=[0,0,0,1]}=n,o=this.gl,i=this.resources.get(t);if(!i)throw new Error(`Program with id ${t} not found`);o.useProgram(i.program),r&&(o.clearColor(...e),o.clear(o.COLOR_BUFFER_BIT))}fastRender(t,n,r=!0){const e=this.gl,o=this.resources.get(t);if(!o)throw new Error(`Program with id ${t} not found`);e.useProgram(o.program),r&&e.clear(e.COLOR_BUFFER_BIT),this.updateUniforms(t,n)}setUniform(t,n,r,e){const o=this.gl,i=this.resources.get(t);if(!i)throw new Error(`Program with id ${t} not found`);const s=i.uniforms[n];if(s!==null)switch(o.useProgram(i.program),e){case"float":o.uniform1f(s,r);break;case"vec2":o.uniform2fv(s,r);break;case"vec3":o.uniform3fv(s,r);break;case"vec4":o.uniform4fv(s,r);break;case"int":o.uniform1i(s,r);break;case"mat2":o.uniformMatrix2fv(s,!1,r);break;case"mat3":o.uniformMatrix3fv(s,!1,r);break;case"mat4":o.uniformMatrix4fv(s,!1,r);break;case"sampler2D":o.uniform1i(s,r);break;default:throw new Error(`Unsupported uniform type: ${e}`)}}setAttributeOnce(t,n,r){const e=this.gl,o=this.resources.get(t);if(!o)throw new Error(`Program with id ${t} not found`);const i=o.attributes[n];if(i===-1){console.warn(`Attribute ${n} not found or is unused`);return}const s=o.buffers[n];if(!s)throw new Error(`Buffer for attribute ${n} not found`);if(e.bindBuffer(e.ARRAY_BUFFER,s.buffer),e.enableVertexAttribArray(i),e.vertexAttribPointer(i,r.size,e[r.type],r.normalized,r.stride,r.offset),r.instanced){const h=this.getExtension("ANGLE_instanced_arrays");if(h!=null&&h.vertexAttribDivisorANGLE)h.vertexAttribDivisorANGLE(i,1);else if(e.vertexAttribDivisor)e.vertexAttribDivisor(i,1);else throw new Error("Instanced rendering not supported")}}drawArrays(t,n,r){this.gl.drawArrays(t,n,r)}drawElements(t,n,r,e){this.gl.drawElements(t,n,r,e)}destroy(t){const n=this.gl,r=this.resources.get(t);r&&(Object.values(r.buffers).forEach(({buffer:e})=>{n.deleteBuffer(e)}),n.deleteProgram(r.program),this.resources.delete(t),this.uniformUpdateFns.delete(t))}destroyAll(){for(const t of Array.from(this.resources.keys()))this.destroy(t);this.compileCache.clear(),this.fboManager.destroyAll()}get context(){return this.gl}get fbo(){return this.fboManager}}exports.WebGLManager=m;
|
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import { FBOManager as d } from "./FBOManager.mjs";
|
|
2
|
-
class b {
|
|
3
|
-
constructor(t, n) {
|
|
4
|
-
this.resources = /* @__PURE__ */ new Map(), this.compileCache = /* @__PURE__ */ new Map(), this.uniformUpdateFns = /* @__PURE__ */ new Map(), this.extensions = /* @__PURE__ */ new Map();
|
|
5
|
-
const e = {
|
|
6
|
-
alpha: !1,
|
|
7
|
-
depth: !1,
|
|
8
|
-
stencil: !1,
|
|
9
|
-
antialias: !1,
|
|
10
|
-
powerPreference: "low-power",
|
|
11
|
-
preserveDrawingBuffer: !1
|
|
12
|
-
}, r = t.getContext("webgl", { ...e, ...n });
|
|
13
|
-
if (!r)
|
|
14
|
-
throw new Error("WebGL not supported");
|
|
15
|
-
this.gl = r, this.fboManager = new d(r), this.getExtension("OES_texture_float"), this.getExtension("OES_texture_float_linear"), this.getExtension("OES_vertex_array_object"), this.getExtension("ANGLE_instanced_arrays");
|
|
16
|
-
}
|
|
17
|
-
getExtension(t) {
|
|
18
|
-
if (this.extensions.has(t))
|
|
19
|
-
return this.extensions.get(t);
|
|
20
|
-
const n = this.gl.getExtension(t);
|
|
21
|
-
return this.extensions.set(t, n), n;
|
|
22
|
-
}
|
|
23
|
-
createProgram(t, n) {
|
|
24
|
-
const { vertexShader: e, fragmentShader: r, uniforms: o, attributes: i } = n, s = this.gl, u = this.getOrCompileShader("vertex:" + e, s.VERTEX_SHADER, e), l = this.getOrCompileShader("fragment:" + r, s.FRAGMENT_SHADER, r), f = s.createProgram();
|
|
25
|
-
if (!f)
|
|
26
|
-
throw new Error("Failed to create WebGL program");
|
|
27
|
-
if (s.attachShader(f, u), s.attachShader(f, l), s.linkProgram(f), !s.getProgramParameter(f, s.LINK_STATUS)) {
|
|
28
|
-
const g = s.getProgramInfoLog(f);
|
|
29
|
-
throw s.deleteProgram(f), new Error(`Could not link shader program: ${g}`);
|
|
30
|
-
}
|
|
31
|
-
const c = {};
|
|
32
|
-
for (const g of o)
|
|
33
|
-
c[g.name] = s.getUniformLocation(f, g.name);
|
|
34
|
-
const h = {};
|
|
35
|
-
if (i)
|
|
36
|
-
for (const g of i)
|
|
37
|
-
h[g.name] = s.getAttribLocation(f, g.name);
|
|
38
|
-
const a = {
|
|
39
|
-
program: f,
|
|
40
|
-
uniforms: c,
|
|
41
|
-
attributes: h,
|
|
42
|
-
buffers: {}
|
|
43
|
-
};
|
|
44
|
-
return this.resources.set(t, a), this.uniformUpdateFns.set(t, /* @__PURE__ */ new Map()), a;
|
|
45
|
-
}
|
|
46
|
-
getOrCompileShader(t, n, e) {
|
|
47
|
-
if (this.compileCache.has(t)) {
|
|
48
|
-
const o = this.compileCache.get(t);
|
|
49
|
-
if (o)
|
|
50
|
-
return o;
|
|
51
|
-
}
|
|
52
|
-
const r = this.compileShader(n, e);
|
|
53
|
-
return this.compileCache.set(t, r), r;
|
|
54
|
-
}
|
|
55
|
-
compileShader(t, n) {
|
|
56
|
-
const e = this.gl, r = e.createShader(t);
|
|
57
|
-
if (!r)
|
|
58
|
-
throw new Error("Failed to create shader");
|
|
59
|
-
if (e.shaderSource(r, n), e.compileShader(r), !e.getShaderParameter(r, e.COMPILE_STATUS)) {
|
|
60
|
-
const o = e.getShaderInfoLog(r);
|
|
61
|
-
throw e.deleteShader(r), new Error(`Shader compilation failed: ${o}`);
|
|
62
|
-
}
|
|
63
|
-
return r;
|
|
64
|
-
}
|
|
65
|
-
createBuffer(t, n, e) {
|
|
66
|
-
const r = this.gl, o = this.resources.get(t);
|
|
67
|
-
if (!o)
|
|
68
|
-
throw new Error(`Program with id ${t} not found`);
|
|
69
|
-
const i = r.createBuffer();
|
|
70
|
-
if (!i)
|
|
71
|
-
throw new Error("Failed to create buffer");
|
|
72
|
-
return r.bindBuffer(r.ARRAY_BUFFER, i), r.bufferData(r.ARRAY_BUFFER, e, r.STATIC_DRAW), o.buffers[n] = { buffer: i, data: e }, i;
|
|
73
|
-
}
|
|
74
|
-
updateBuffer(t, n, e) {
|
|
75
|
-
const r = this.gl, o = this.resources.get(t);
|
|
76
|
-
if (!o)
|
|
77
|
-
throw new Error(`Program with id ${t} not found`);
|
|
78
|
-
const i = o.buffers[n];
|
|
79
|
-
if (!i)
|
|
80
|
-
throw new Error(`Buffer for attribute ${n} not found`);
|
|
81
|
-
r.bindBuffer(r.ARRAY_BUFFER, i.buffer), r.bufferData(r.ARRAY_BUFFER, e, r.STATIC_DRAW), i.data = e;
|
|
82
|
-
}
|
|
83
|
-
registerUniformUpdater(t, n, e, r) {
|
|
84
|
-
const o = this.resources.get(t);
|
|
85
|
-
if (!o)
|
|
86
|
-
throw new Error(`Program with id ${t} not found`);
|
|
87
|
-
const i = this.uniformUpdateFns.get(t);
|
|
88
|
-
if (!i)
|
|
89
|
-
throw new Error(`Program uniforms for id ${t} not found`);
|
|
90
|
-
const s = o.uniforms[n];
|
|
91
|
-
if (s === null)
|
|
92
|
-
return;
|
|
93
|
-
const u = this.gl;
|
|
94
|
-
let l;
|
|
95
|
-
switch (e) {
|
|
96
|
-
case "int":
|
|
97
|
-
l = (f, c, h) => {
|
|
98
|
-
const a = r(f, c, h);
|
|
99
|
-
return u.uniform1i(s, a), a;
|
|
100
|
-
};
|
|
101
|
-
break;
|
|
102
|
-
case "float":
|
|
103
|
-
l = (f, c, h) => {
|
|
104
|
-
const a = r(f, c, h);
|
|
105
|
-
return u.uniform1f(s, a), a;
|
|
106
|
-
};
|
|
107
|
-
break;
|
|
108
|
-
case "sampler2D":
|
|
109
|
-
l = (f, c, h) => {
|
|
110
|
-
const a = r(f, c, h);
|
|
111
|
-
return u.uniform1i(s, a), a;
|
|
112
|
-
};
|
|
113
|
-
break;
|
|
114
|
-
case "vec2":
|
|
115
|
-
l = (f, c, h) => {
|
|
116
|
-
const a = r(f, c, h);
|
|
117
|
-
return u.uniform2fv(s, a), a;
|
|
118
|
-
};
|
|
119
|
-
break;
|
|
120
|
-
case "vec3":
|
|
121
|
-
l = (f, c, h) => {
|
|
122
|
-
const a = r(f, c, h);
|
|
123
|
-
return u.uniform3fv(s, a), a;
|
|
124
|
-
};
|
|
125
|
-
break;
|
|
126
|
-
case "vec4":
|
|
127
|
-
l = (f, c, h) => {
|
|
128
|
-
const a = r(f, c, h);
|
|
129
|
-
return u.uniform4fv(s, a), a;
|
|
130
|
-
};
|
|
131
|
-
break;
|
|
132
|
-
case "mat2":
|
|
133
|
-
l = (f, c, h) => {
|
|
134
|
-
const a = r(f, c, h);
|
|
135
|
-
return u.uniformMatrix2fv(s, !1, a), a;
|
|
136
|
-
};
|
|
137
|
-
break;
|
|
138
|
-
case "mat3":
|
|
139
|
-
l = (f, c, h) => {
|
|
140
|
-
const a = r(f, c, h);
|
|
141
|
-
return u.uniformMatrix3fv(s, !1, a), a;
|
|
142
|
-
};
|
|
143
|
-
break;
|
|
144
|
-
case "mat4":
|
|
145
|
-
l = (f, c, h) => {
|
|
146
|
-
const a = r(f, c, h);
|
|
147
|
-
return u.uniformMatrix4fv(s, !1, a), a;
|
|
148
|
-
};
|
|
149
|
-
break;
|
|
150
|
-
default:
|
|
151
|
-
throw new Error(`Unsupported uniform type: ${e}`);
|
|
152
|
-
}
|
|
153
|
-
i.set(n, l);
|
|
154
|
-
}
|
|
155
|
-
updateUniforms(t, n) {
|
|
156
|
-
const e = this.uniformUpdateFns.get(t);
|
|
157
|
-
if (!e)
|
|
158
|
-
return;
|
|
159
|
-
const r = this.gl.canvas, o = r.width, i = r.height;
|
|
160
|
-
e.forEach((s) => {
|
|
161
|
-
s(n, o, i);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
setSize(t, n, e = !0) {
|
|
165
|
-
const r = this.gl.canvas, o = e && window.devicePixelRatio || 1, i = Math.floor(t * o), s = Math.floor(n * o);
|
|
166
|
-
(r.width !== i || r.height !== s) && (r.width = i, r.height = s, r.style.width = `${t}px`, r.style.height = `${n}px`, this.gl.viewport(0, 0, i, s));
|
|
167
|
-
}
|
|
168
|
-
prepareRender(t, n = {}) {
|
|
169
|
-
const { clear: e = !0, clearColor: r = [0, 0, 0, 1] } = n, o = this.gl, i = this.resources.get(t);
|
|
170
|
-
if (!i)
|
|
171
|
-
throw new Error(`Program with id ${t} not found`);
|
|
172
|
-
o.useProgram(i.program), e && (o.clearColor(...r), o.clear(o.COLOR_BUFFER_BIT));
|
|
173
|
-
}
|
|
174
|
-
fastRender(t, n, e = !0) {
|
|
175
|
-
const r = this.gl, o = this.resources.get(t);
|
|
176
|
-
if (!o)
|
|
177
|
-
throw new Error(`Program with id ${t} not found`);
|
|
178
|
-
r.useProgram(o.program), e && r.clear(r.COLOR_BUFFER_BIT), this.updateUniforms(t, n);
|
|
179
|
-
}
|
|
180
|
-
setUniform(t, n, e, r) {
|
|
181
|
-
const o = this.gl, i = this.resources.get(t);
|
|
182
|
-
if (!i)
|
|
183
|
-
throw new Error(`Program with id ${t} not found`);
|
|
184
|
-
const s = i.uniforms[n];
|
|
185
|
-
if (s !== null)
|
|
186
|
-
switch (o.useProgram(i.program), r) {
|
|
187
|
-
case "float":
|
|
188
|
-
o.uniform1f(s, e);
|
|
189
|
-
break;
|
|
190
|
-
case "vec2":
|
|
191
|
-
o.uniform2fv(s, e);
|
|
192
|
-
break;
|
|
193
|
-
case "vec3":
|
|
194
|
-
o.uniform3fv(s, e);
|
|
195
|
-
break;
|
|
196
|
-
case "vec4":
|
|
197
|
-
o.uniform4fv(s, e);
|
|
198
|
-
break;
|
|
199
|
-
case "int":
|
|
200
|
-
o.uniform1i(s, e);
|
|
201
|
-
break;
|
|
202
|
-
case "mat2":
|
|
203
|
-
o.uniformMatrix2fv(s, !1, e);
|
|
204
|
-
break;
|
|
205
|
-
case "mat3":
|
|
206
|
-
o.uniformMatrix3fv(s, !1, e);
|
|
207
|
-
break;
|
|
208
|
-
case "mat4":
|
|
209
|
-
o.uniformMatrix4fv(s, !1, e);
|
|
210
|
-
break;
|
|
211
|
-
case "sampler2D":
|
|
212
|
-
o.uniform1i(s, e);
|
|
213
|
-
break;
|
|
214
|
-
default:
|
|
215
|
-
throw new Error(`Unsupported uniform type: ${r}`);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
setAttributeOnce(t, n, e) {
|
|
219
|
-
const r = this.gl, o = this.resources.get(t);
|
|
220
|
-
if (!o)
|
|
221
|
-
throw new Error(`Program with id ${t} not found`);
|
|
222
|
-
const i = o.attributes[n];
|
|
223
|
-
if (i === -1) {
|
|
224
|
-
console.warn(`Attribute ${n} not found or is unused`);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
const s = o.buffers[n];
|
|
228
|
-
if (!s)
|
|
229
|
-
throw new Error(`Buffer for attribute ${n} not found`);
|
|
230
|
-
if (r.bindBuffer(r.ARRAY_BUFFER, s.buffer), r.enableVertexAttribArray(i), r.vertexAttribPointer(
|
|
231
|
-
i,
|
|
232
|
-
e.size,
|
|
233
|
-
r[e.type],
|
|
234
|
-
e.normalized,
|
|
235
|
-
e.stride,
|
|
236
|
-
e.offset
|
|
237
|
-
), e.instanced) {
|
|
238
|
-
const u = this.getExtension("ANGLE_instanced_arrays");
|
|
239
|
-
if (u != null && u.vertexAttribDivisorANGLE)
|
|
240
|
-
u.vertexAttribDivisorANGLE(i, 1);
|
|
241
|
-
else if (r.vertexAttribDivisor)
|
|
242
|
-
r.vertexAttribDivisor(i, 1);
|
|
243
|
-
else
|
|
244
|
-
throw new Error("Instanced rendering not supported");
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
drawArrays(t, n, e) {
|
|
248
|
-
this.gl.drawArrays(t, n, e);
|
|
249
|
-
}
|
|
250
|
-
drawElements(t, n, e, r) {
|
|
251
|
-
this.gl.drawElements(t, n, e, r);
|
|
252
|
-
}
|
|
253
|
-
destroy(t) {
|
|
254
|
-
const n = this.gl, e = this.resources.get(t);
|
|
255
|
-
e && (Object.values(e.buffers).forEach(({ buffer: r }) => {
|
|
256
|
-
n.deleteBuffer(r);
|
|
257
|
-
}), n.deleteProgram(e.program), this.resources.delete(t), this.uniformUpdateFns.delete(t));
|
|
258
|
-
}
|
|
259
|
-
destroyAll() {
|
|
260
|
-
for (const t of Array.from(this.resources.keys()))
|
|
261
|
-
this.destroy(t);
|
|
262
|
-
this.compileCache.clear(), this.fboManager.destroyAll();
|
|
263
|
-
}
|
|
264
|
-
get context() {
|
|
265
|
-
return this.gl;
|
|
266
|
-
}
|
|
267
|
-
get fbo() {
|
|
268
|
-
return this.fboManager;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
export {
|
|
272
|
-
b as WebGLManager
|
|
273
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class g{constructor(i){this.passes=[],this.pingPongIds=new Set,this.webglManager=i}addPass(i){this.passes.push(i),i.outputFramebuffer&&this.pingPongIds.add(i.outputFramebuffer),i.inputTextures.forEach(r=>{r.bindingType==="readwrite"&&this.pingPongIds.add(r.id)})}clearPasses(){this.passes=[],this.pingPongIds.clear()}execute(i){const r=this.webglManager.context,a=this.webglManager.fbo;for(const e of this.passes){if(e.outputFramebuffer)if(this.pingPongIds.has(e.outputFramebuffer)){const{write:s}=a.getPingPongIndices(e.outputFramebuffer);a.bindFramebuffer(e.outputFramebuffer,s)}else a.bindFramebuffer(e.outputFramebuffer);else a.bindFramebuffer(null);this.webglManager.prepareRender(e.programId,e.renderOptions),e.inputTextures.forEach(s=>{let t=s.bindingType==="read"?0:1;if(this.pingPongIds.has(s.id)){const{read:n,write:o}=a.getPingPongIndices(s.id);t=s.bindingType==="read"||s.bindingType==="readwrite"?n:o}a.bindTexture(s.id,s.textureUnit,t),this.webglManager.setUniform(e.programId,`u_${s.id}`,s.textureUnit,"sampler2D")}),this.webglManager.updateUniforms(e.programId,i),e.uniforms&&Object.entries(e.uniforms).forEach(([s,t])=>{const n=typeof t.value=="function"?t.value(i,r.canvas.width,r.canvas.height):t.value;this.webglManager.setUniform(e.programId,s,n,t.type)}),r.drawArrays(r.TRIANGLE_STRIP,0,4),e.outputFramebuffer&&this.pingPongIds.has(e.outputFramebuffer)&&a.swapTextures(e.outputFramebuffer),e.inputTextures.forEach(s=>{s.bindingType==="readwrite"&&this.pingPongIds.has(s.id)&&a.swapTextures(s.id)})}}initializeResources(){for(const i of this.passes){const r=this.webglManager.resources.get(i.programId);r&&!r.buffers.a_position&&(this.webglManager.createBuffer(i.programId,"a_position",new Float32Array([-1,-1,1,-1,-1,1,1,1])),this.webglManager.setAttributeOnce(i.programId,"a_position",{name:"a_position",size:2,type:"FLOAT",normalized:!1,stride:0,offset:0}))}}}exports.Passes=g;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
class f {
|
|
2
|
-
constructor(i) {
|
|
3
|
-
this.passes = [], this.pingPongIds = /* @__PURE__ */ new Set(), this.webglManager = i;
|
|
4
|
-
}
|
|
5
|
-
addPass(i) {
|
|
6
|
-
this.passes.push(i), i.outputFramebuffer && this.pingPongIds.add(i.outputFramebuffer), i.inputTextures.forEach((r) => {
|
|
7
|
-
r.bindingType === "readwrite" && this.pingPongIds.add(r.id);
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
clearPasses() {
|
|
11
|
-
this.passes = [], this.pingPongIds.clear();
|
|
12
|
-
}
|
|
13
|
-
execute(i) {
|
|
14
|
-
const r = this.webglManager.context, a = this.webglManager.fbo;
|
|
15
|
-
for (const e of this.passes) {
|
|
16
|
-
if (e.outputFramebuffer)
|
|
17
|
-
if (this.pingPongIds.has(e.outputFramebuffer)) {
|
|
18
|
-
const { write: s } = a.getPingPongIndices(e.outputFramebuffer);
|
|
19
|
-
a.bindFramebuffer(e.outputFramebuffer, s);
|
|
20
|
-
} else
|
|
21
|
-
a.bindFramebuffer(e.outputFramebuffer);
|
|
22
|
-
else
|
|
23
|
-
a.bindFramebuffer(null);
|
|
24
|
-
this.webglManager.prepareRender(e.programId, e.renderOptions), e.inputTextures.forEach((s) => {
|
|
25
|
-
let t = s.bindingType === "read" ? 0 : 1;
|
|
26
|
-
if (this.pingPongIds.has(s.id)) {
|
|
27
|
-
const { read: n, write: o } = a.getPingPongIndices(s.id);
|
|
28
|
-
t = s.bindingType === "read" || s.bindingType === "readwrite" ? n : o;
|
|
29
|
-
}
|
|
30
|
-
a.bindTexture(s.id, s.textureUnit, t), this.webglManager.setUniform(
|
|
31
|
-
e.programId,
|
|
32
|
-
`u_${s.id}`,
|
|
33
|
-
s.textureUnit,
|
|
34
|
-
"sampler2D"
|
|
35
|
-
);
|
|
36
|
-
}), this.webglManager.updateUniforms(e.programId, i), e.uniforms && Object.entries(e.uniforms).forEach(([s, t]) => {
|
|
37
|
-
const n = typeof t.value == "function" ? t.value(i, r.canvas.width, r.canvas.height) : t.value;
|
|
38
|
-
this.webglManager.setUniform(
|
|
39
|
-
e.programId,
|
|
40
|
-
s,
|
|
41
|
-
n,
|
|
42
|
-
t.type
|
|
43
|
-
);
|
|
44
|
-
}), r.drawArrays(r.TRIANGLE_STRIP, 0, 4), e.outputFramebuffer && this.pingPongIds.has(e.outputFramebuffer) && a.swapTextures(e.outputFramebuffer), e.inputTextures.forEach((s) => {
|
|
45
|
-
s.bindingType === "readwrite" && this.pingPongIds.has(s.id) && a.swapTextures(s.id);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
initializeResources() {
|
|
50
|
-
for (const i of this.passes) {
|
|
51
|
-
const r = this.webglManager.resources.get(i.programId);
|
|
52
|
-
r && !r.buffers.a_position && (this.webglManager.createBuffer(
|
|
53
|
-
i.programId,
|
|
54
|
-
"a_position",
|
|
55
|
-
new Float32Array([
|
|
56
|
-
-1,
|
|
57
|
-
-1,
|
|
58
|
-
1,
|
|
59
|
-
-1,
|
|
60
|
-
-1,
|
|
61
|
-
1,
|
|
62
|
-
1,
|
|
63
|
-
1
|
|
64
|
-
])
|
|
65
|
-
), this.webglManager.setAttributeOnce(i.programId, "a_position", {
|
|
66
|
-
name: "a_position",
|
|
67
|
-
size: 2,
|
|
68
|
-
type: "FLOAT",
|
|
69
|
-
normalized: !1,
|
|
70
|
-
stride: 0,
|
|
71
|
-
offset: 0
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export {
|
|
77
|
-
f as Passes
|
|
78
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class l{constructor(e){this.effects=new Map,this.chains=new Map,this.defaultFramebufferOptions={width:0,height:0,textureCount:2,textureOptions:{minFilter:WebGLRenderingContext.LINEAR,magFilter:WebGLRenderingContext.LINEAR}},this.webglManager=e}registerEffect(e){this.effects.has(e.id)&&console.warn(`Effect with id ${e.id} already exists, overwriting`),this.webglManager.resources.has(e.programId)||this.webglManager.createProgram(e.programId,e.shaderConfig),this.effects.set(e.id,e)}removeEffect(e){if(!this.effects.has(e)){console.warn(`Effect with id ${e} not found`);return}this.effects.delete(e)}createChain(e,i,t,r=null,n=this.defaultFramebufferOptions){this.chains.has(e)&&console.warn(`Chain with id ${e} already exists, overwriting`);const s=[];for(const o of i){const f=this.effects.get(o);if(!f)throw new Error(`Effect with id ${o} not found`);s.push(f)}const a=[];for(let o=0;o<s.length-1;o++){const f=`${e}-intermediate-${o}`;this.webglManager.fbo.createFramebuffer(f,n),a.push(f)}this.chains.set(e,{id:e,effects:s,inputFramebufferId:t,outputFramebufferId:r,intermediateFramebufferIds:a})}removeChain(e){const i=this.chains.get(e);if(!i){console.warn(`Chain with id ${e} not found`);return}i.intermediateFramebufferIds.forEach(t=>{this.webglManager.fbo.destroy(t)}),this.chains.delete(e)}generatePasses(e,i){const t=this.chains.get(e);if(!t)throw new Error(`Chain with id ${e} not found`);const r=[],n=t.effects.filter(s=>s.enabled);return n.length===0?[{programId:"copy-shader",inputTextures:[{id:t.inputFramebufferId,textureUnit:0,bindingType:"read"}],outputFramebuffer:t.outputFramebufferId,renderOptions:{clear:!0}}]:(n.forEach((s,a)=>{const o=a===0,f=a===n.length-1,d=o?t.inputFramebufferId:t.intermediateFramebufferIds[a-1],g=f?t.outputFramebufferId:t.intermediateFramebufferIds[a],h={};Object.entries(s.uniforms).forEach(([u,c])=>{const b=u.startsWith("u_")?u:`u_${u}`;h[b]={type:c.type,value:c.value}}),r.push({programId:s.programId,inputTextures:[{id:d,textureUnit:0,bindingType:"read"}],outputFramebuffer:g,uniforms:h,renderOptions:{clear:!0}})}),r)}process(e,i){const t=this.generatePasses(e,i);for(const r of t)r.outputFramebuffer?this.webglManager.fbo.bindFramebuffer(r.outputFramebuffer):this.webglManager.fbo.bindFramebuffer(null),this.webglManager.prepareRender(r.programId,r.renderOptions),r.inputTextures.forEach(n=>{this.webglManager.fbo.bindTexture(n.id,n.textureUnit),this.webglManager.setUniform(r.programId,`u_texture${n.textureUnit}`,n.textureUnit,"sampler2D")}),r.uniforms&&Object.entries(r.uniforms).forEach(([n,s])=>{const a=typeof s.value=="function"?s.value(i,this.webglManager.context.canvas.width,this.webglManager.context.canvas.height):s.value;this.webglManager.setUniform(r.programId,n,a,s.type)}),this.webglManager.context.drawArrays(this.webglManager.context.TRIANGLE_STRIP,0,4)}resizeFramebuffers(e,i){for(const t of this.chains.values())for(const r of t.intermediateFramebufferIds)this.webglManager.fbo.resizeFramebuffer(r,e,i)}destroyAll(){for(const e of this.chains.values())for(const i of e.intermediateFramebufferIds)this.webglManager.fbo.destroy(i);this.chains.clear(),this.effects.clear()}}exports.Postprocessing=l;
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
class p {
|
|
2
|
-
constructor(e) {
|
|
3
|
-
this.effects = /* @__PURE__ */ new Map(), this.chains = /* @__PURE__ */ new Map(), this.defaultFramebufferOptions = {
|
|
4
|
-
width: 0,
|
|
5
|
-
height: 0,
|
|
6
|
-
textureCount: 2,
|
|
7
|
-
textureOptions: {
|
|
8
|
-
minFilter: WebGLRenderingContext.LINEAR,
|
|
9
|
-
magFilter: WebGLRenderingContext.LINEAR
|
|
10
|
-
}
|
|
11
|
-
}, this.webglManager = e;
|
|
12
|
-
}
|
|
13
|
-
registerEffect(e) {
|
|
14
|
-
this.effects.has(e.id) && console.warn(`Effect with id ${e.id} already exists, overwriting`), this.webglManager.resources.has(e.programId) || this.webglManager.createProgram(e.programId, e.shaderConfig), this.effects.set(e.id, e);
|
|
15
|
-
}
|
|
16
|
-
removeEffect(e) {
|
|
17
|
-
if (!this.effects.has(e)) {
|
|
18
|
-
console.warn(`Effect with id ${e} not found`);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
this.effects.delete(e);
|
|
22
|
-
}
|
|
23
|
-
createChain(e, i, t, r = null, a = this.defaultFramebufferOptions) {
|
|
24
|
-
this.chains.has(e) && console.warn(`Chain with id ${e} already exists, overwriting`);
|
|
25
|
-
const s = [];
|
|
26
|
-
for (const o of i) {
|
|
27
|
-
const f = this.effects.get(o);
|
|
28
|
-
if (!f)
|
|
29
|
-
throw new Error(`Effect with id ${o} not found`);
|
|
30
|
-
s.push(f);
|
|
31
|
-
}
|
|
32
|
-
const n = [];
|
|
33
|
-
for (let o = 0; o < s.length - 1; o++) {
|
|
34
|
-
const f = `${e}-intermediate-${o}`;
|
|
35
|
-
this.webglManager.fbo.createFramebuffer(f, a), n.push(f);
|
|
36
|
-
}
|
|
37
|
-
this.chains.set(e, {
|
|
38
|
-
id: e,
|
|
39
|
-
effects: s,
|
|
40
|
-
inputFramebufferId: t,
|
|
41
|
-
outputFramebufferId: r,
|
|
42
|
-
intermediateFramebufferIds: n
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
removeChain(e) {
|
|
46
|
-
const i = this.chains.get(e);
|
|
47
|
-
if (!i) {
|
|
48
|
-
console.warn(`Chain with id ${e} not found`);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
i.intermediateFramebufferIds.forEach((t) => {
|
|
52
|
-
this.webglManager.fbo.destroy(t);
|
|
53
|
-
}), this.chains.delete(e);
|
|
54
|
-
}
|
|
55
|
-
generatePasses(e, i) {
|
|
56
|
-
const t = this.chains.get(e);
|
|
57
|
-
if (!t)
|
|
58
|
-
throw new Error(`Chain with id ${e} not found`);
|
|
59
|
-
const r = [], a = t.effects.filter((s) => s.enabled);
|
|
60
|
-
return a.length === 0 ? [{
|
|
61
|
-
programId: "copy-shader",
|
|
62
|
-
inputTextures: [{
|
|
63
|
-
id: t.inputFramebufferId,
|
|
64
|
-
textureUnit: 0,
|
|
65
|
-
bindingType: "read"
|
|
66
|
-
}],
|
|
67
|
-
outputFramebuffer: t.outputFramebufferId,
|
|
68
|
-
renderOptions: { clear: !0 }
|
|
69
|
-
}] : (a.forEach((s, n) => {
|
|
70
|
-
const o = n === 0, f = n === a.length - 1, d = o ? t.inputFramebufferId : t.intermediateFramebufferIds[n - 1], g = f ? t.outputFramebufferId : t.intermediateFramebufferIds[n], h = {};
|
|
71
|
-
Object.entries(s.uniforms).forEach(([u, c]) => {
|
|
72
|
-
const b = u.startsWith("u_") ? u : `u_${u}`;
|
|
73
|
-
h[b] = {
|
|
74
|
-
type: c.type,
|
|
75
|
-
value: c.value
|
|
76
|
-
};
|
|
77
|
-
}), r.push({
|
|
78
|
-
programId: s.programId,
|
|
79
|
-
inputTextures: [{
|
|
80
|
-
id: d,
|
|
81
|
-
textureUnit: 0,
|
|
82
|
-
bindingType: "read"
|
|
83
|
-
}],
|
|
84
|
-
outputFramebuffer: g,
|
|
85
|
-
uniforms: h,
|
|
86
|
-
renderOptions: { clear: !0 }
|
|
87
|
-
});
|
|
88
|
-
}), r);
|
|
89
|
-
}
|
|
90
|
-
process(e, i) {
|
|
91
|
-
const t = this.generatePasses(e, i);
|
|
92
|
-
for (const r of t)
|
|
93
|
-
r.outputFramebuffer ? this.webglManager.fbo.bindFramebuffer(r.outputFramebuffer) : this.webglManager.fbo.bindFramebuffer(null), this.webglManager.prepareRender(r.programId, r.renderOptions), r.inputTextures.forEach((a) => {
|
|
94
|
-
this.webglManager.fbo.bindTexture(a.id, a.textureUnit), this.webglManager.setUniform(
|
|
95
|
-
r.programId,
|
|
96
|
-
`u_texture${a.textureUnit}`,
|
|
97
|
-
a.textureUnit,
|
|
98
|
-
"sampler2D"
|
|
99
|
-
);
|
|
100
|
-
}), r.uniforms && Object.entries(r.uniforms).forEach(([a, s]) => {
|
|
101
|
-
const n = typeof s.value == "function" ? s.value(i, this.webglManager.context.canvas.width, this.webglManager.context.canvas.height) : s.value;
|
|
102
|
-
this.webglManager.setUniform(
|
|
103
|
-
r.programId,
|
|
104
|
-
a,
|
|
105
|
-
n,
|
|
106
|
-
s.type
|
|
107
|
-
);
|
|
108
|
-
}), this.webglManager.context.drawArrays(
|
|
109
|
-
this.webglManager.context.TRIANGLE_STRIP,
|
|
110
|
-
0,
|
|
111
|
-
4
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
resizeFramebuffers(e, i) {
|
|
115
|
-
for (const t of this.chains.values())
|
|
116
|
-
for (const r of t.intermediateFramebufferIds)
|
|
117
|
-
this.webglManager.fbo.resizeFramebuffer(r, e, i);
|
|
118
|
-
}
|
|
119
|
-
destroyAll() {
|
|
120
|
-
for (const e of this.chains.values())
|
|
121
|
-
for (const i of e.intermediateFramebufferIds)
|
|
122
|
-
this.webglManager.fbo.destroy(i);
|
|
123
|
-
this.chains.clear(), this.effects.clear();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
export {
|
|
127
|
-
p as Postprocessing
|
|
128
|
-
};
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/types.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|