micugl 0.0.4 → 0.0.8
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/README.md +98 -1
- package/dist/MarbleScene.d.ts +27 -0
- package/dist/RippleScene.d.ts +20 -0
- package/dist/examples/Marble/MarbleScene.d.ts +20 -0
- package/dist/examples/Marble/MarbleScene.js +1 -0
- package/dist/examples/Marble/MarbleScene.mjs +71 -0
- package/dist/examples/Marble/marbleShaders.d.ts +2 -0
- package/dist/{MarbleScene-B1gMFEHc.js → examples/Marble/marbleShaders.js} +3 -3
- package/dist/{MarbleScene-DmZt4s6L.mjs → examples/Marble/marbleShaders.mjs} +5 -70
- package/dist/examples/Ripple/RippleScene.d.ts +13 -0
- package/dist/examples/Ripple/RippleScene.js +1 -0
- package/dist/examples/Ripple/RippleScene.mjs +109 -0
- package/dist/examples/Ripple/rippleShaders.d.ts +3 -0
- package/dist/examples/Ripple/rippleShaders.js +80 -0
- package/dist/examples/Ripple/rippleShaders.mjs +94 -0
- package/dist/examples/index.d.ts +4 -4
- package/dist/examples/index.js +1 -1
- package/dist/examples/index.mjs +9 -7
- package/dist/index.d.ts +35 -9
- package/dist/index.js +1 -1
- package/dist/index.mjs +35 -146
- package/dist/marbleShaders.d.ts +5 -0
- package/dist/rippleShaders.d.ts +7 -0
- package/dist/src/core/lib/createShaderConfig.js +1 -0
- package/dist/src/core/lib/createShaderConfig.mjs +34 -0
- package/dist/src/core/lib/vectorUtils.js +1 -0
- package/dist/src/core/lib/vectorUtils.mjs +36 -0
- package/dist/src/core/managers/FBOManager.js +1 -0
- package/dist/src/core/managers/FBOManager.mjs +120 -0
- package/dist/src/core/managers/WebGLManager.js +1 -0
- package/dist/src/core/managers/WebGLManager.mjs +273 -0
- package/dist/src/core/systems/Passes.js +1 -0
- package/dist/src/core/systems/Passes.mjs +78 -0
- package/dist/src/core/systems/Postprocessing.js +1 -0
- package/dist/src/core/systems/Postprocessing.mjs +128 -0
- package/dist/src/react/components/base/BasePingPongShaderComponent.js +1 -0
- package/dist/src/react/components/base/BasePingPongShaderComponent.mjs +48 -0
- package/dist/src/react/components/base/BaseShaderComponent.js +1 -0
- package/dist/src/react/components/base/BaseShaderComponent.mjs +34 -0
- package/dist/src/react/components/engine/PingPongShaderEngine.js +1 -0
- package/dist/src/react/components/engine/PingPongShaderEngine.mjs +68 -0
- package/dist/src/react/components/engine/ShaderEngine.js +1 -0
- package/dist/src/react/components/engine/ShaderEngine.mjs +106 -0
- package/dist/src/react/hooks/useDarkMode.js +1 -0
- package/dist/src/react/hooks/useDarkMode.mjs +22 -0
- package/dist/src/react/hooks/usePingPongPasses.js +1 -0
- package/dist/src/react/hooks/usePingPongPasses.mjs +93 -0
- package/dist/src/react/hooks/useUniformUpdaters.js +1 -0
- package/dist/src/react/hooks/useUniformUpdaters.mjs +12 -0
- package/dist/src/react/lib/createUniformUpdater.js +1 -0
- package/dist/src/react/lib/createUniformUpdater.mjs +28 -0
- package/dist/types.d.ts +204 -0
- package/dist/types.js +1 -0
- package/dist/types.mjs +1 -0
- package/package.json +46 -10
- package/dist/BasePingPongShaderComponent-BvRm7-g5.js +0 -1
- package/dist/BasePingPongShaderComponent-FY62Kl02.mjs +0 -273
- package/dist/BaseShaderComponent-BSBIvn4B.js +0 -1
- package/dist/BaseShaderComponent-Be_evz2F.mjs +0 -151
- package/dist/SimpleRippleScene--B1BrlxP.js +0 -80
- package/dist/SimpleRippleScene-Ba-EPdTJ.mjs +0 -197
- package/dist/examples/Marble/index.d.ts +0 -3
- package/dist/examples/Marble/index.js +0 -1
- package/dist/examples/Marble/index.mjs +0 -6
- package/dist/examples/SimpleRipple/index.d.ts +0 -3
- package/dist/examples/SimpleRipple/index.js +0 -1
- package/dist/examples/SimpleRipple/index.mjs +0 -7
- package/dist/useUniformUpdaters-D5WtqZpp.mjs +0 -456
- package/dist/useUniformUpdaters-DGX0mf9g.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -0,0 +1,273 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),E=require("../engine/PingPongShaderEngine.js"),b=require("../../hooks/usePingPongPasses.js"),j={clear:!0,clearColor:[0,0,0,1]},p=({programId:e,shaderConfig:r,secondaryProgramId:t,secondaryShaderConfig:n,iterations:P=1,uniforms:a,secondaryUniforms:g,framebufferOptions:i,className:c="",style:u,customPasses:l,renderOptions:d=j})=>{const s=t??`${e}-secondary`,o={[e]:r};n&&(o[s]=n);const{passes:m,framebuffers:S}=b.usePingPongPasses({programId:e,secondaryProgramId:n?s:void 0,iterations:P,uniforms:a,secondaryUniforms:g,framebufferOptions:i,renderOptions:d,customPasses:l});return f.jsx(E.PingPongShaderEngine,{programConfigs:o,passes:m,framebuffers:S,className:c,style:u})};exports.BasePingPongShaderComponent=p;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as E } from "react/jsx-runtime";
|
|
2
|
+
import { PingPongShaderEngine as d } from "../engine/PingPongShaderEngine.mjs";
|
|
3
|
+
import { usePingPongPasses as x } from "../../hooks/usePingPongPasses.mjs";
|
|
4
|
+
const N = {
|
|
5
|
+
clear: !0,
|
|
6
|
+
clearColor: [0, 0, 0, 1]
|
|
7
|
+
}, b = ({
|
|
8
|
+
programId: o,
|
|
9
|
+
shaderConfig: e,
|
|
10
|
+
secondaryProgramId: t,
|
|
11
|
+
secondaryShaderConfig: r,
|
|
12
|
+
iterations: a = 1,
|
|
13
|
+
uniforms: P,
|
|
14
|
+
secondaryUniforms: c,
|
|
15
|
+
framebufferOptions: m,
|
|
16
|
+
className: i = "",
|
|
17
|
+
style: g,
|
|
18
|
+
customPasses: f,
|
|
19
|
+
renderOptions: p = N
|
|
20
|
+
}) => {
|
|
21
|
+
const n = t ?? `${o}-secondary`, s = {
|
|
22
|
+
[o]: e
|
|
23
|
+
};
|
|
24
|
+
r && (s[n] = r);
|
|
25
|
+
const { passes: u, framebuffers: l } = x({
|
|
26
|
+
programId: o,
|
|
27
|
+
secondaryProgramId: r ? n : void 0,
|
|
28
|
+
iterations: a,
|
|
29
|
+
uniforms: P,
|
|
30
|
+
secondaryUniforms: c,
|
|
31
|
+
framebufferOptions: m,
|
|
32
|
+
renderOptions: p,
|
|
33
|
+
customPasses: f
|
|
34
|
+
});
|
|
35
|
+
return /* @__PURE__ */ E(
|
|
36
|
+
d,
|
|
37
|
+
{
|
|
38
|
+
programConfigs: s,
|
|
39
|
+
passes: u,
|
|
40
|
+
framebuffers: l,
|
|
41
|
+
className: i,
|
|
42
|
+
style: g
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
b as BasePingPongShaderComponent
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime");require("react");const m=require("../../hooks/useUniformUpdaters.js"),S=require("../engine/ShaderEngine.js"),l={clear:!0,clearColor:[0,0,0,1]},p=({programId:e,shaderConfig:t,uniforms:n,className:s="",style:o,renderOptions:a=l})=>{const u={[e]:t},i=m.useUniformUpdaters(e,n),c=(f,h,r)=>{r.drawArrays(r.TRIANGLE_STRIP,0,4)};return d.jsx(S.ShaderEngine,{programConfigs:u,renderCallback:c,uniformUpdaters:i,className:s,style:o,useFastPath:!0,renderOptions:a})};exports.BaseShaderComponent=p;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { useUniformUpdaters as p } from "../../hooks/useUniformUpdaters.mjs";
|
|
4
|
+
import { ShaderEngine as u } from "../engine/ShaderEngine.mjs";
|
|
5
|
+
const d = {
|
|
6
|
+
clear: !0,
|
|
7
|
+
clearColor: [0, 0, 0, 1]
|
|
8
|
+
}, h = ({
|
|
9
|
+
programId: r,
|
|
10
|
+
shaderConfig: o,
|
|
11
|
+
uniforms: t,
|
|
12
|
+
className: s = "",
|
|
13
|
+
style: a,
|
|
14
|
+
renderOptions: n = d
|
|
15
|
+
}) => {
|
|
16
|
+
const m = { [r]: o }, c = p(r, t);
|
|
17
|
+
return /* @__PURE__ */ i(
|
|
18
|
+
u,
|
|
19
|
+
{
|
|
20
|
+
programConfigs: m,
|
|
21
|
+
renderCallback: (l, C, e) => {
|
|
22
|
+
e.drawArrays(e.TRIANGLE_STRIP, 0, 4);
|
|
23
|
+
},
|
|
24
|
+
uniformUpdaters: c,
|
|
25
|
+
className: s,
|
|
26
|
+
style: a,
|
|
27
|
+
useFastPath: !0,
|
|
28
|
+
renderOptions: n
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
h as BaseShaderComponent
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),t=require("react"),P=require("../../../core/managers/WebGLManager.js"),F=require("../../../core/systems/Passes.js"),z="",A={},v=({programConfigs:l,passes:i,framebuffers:a,className:E=z,style:R=A,useDevicePixelRatio:h=!0})=>{const o=t.useRef(null),s=t.useRef(null),d=t.useRef(null),u=t.useRef(null),m=t.useRef(0),g=t.useRef(e=>{const n=s.current,r=d.current;if(!n||!r)return;const c=e-m.current;r.execute(c),u.current=requestAnimationFrame(g.current)}),f=t.useCallback(()=>{if(!o.current||!s.current)return;const e=window.innerWidth,n=window.innerHeight;s.current.setSize(e,n,h);const r=s.current,c=r.context.canvas;Object.entries(a??[]).forEach(([b,w])=>{const S=w.width||c.width,y=w.height||c.height;r.fbo.resizeFramebuffer(b,S,y)})},[a,h]);return t.useEffect(()=>{if(o.current)try{const e=new P.WebGLManager(o.current);s.current=e,Object.entries(l).forEach(([r,c])=>{e.createProgram(r,c)}),Object.entries(a??[]).forEach(([r,c])=>{e.fbo.createFramebuffer(r,c)});const n=new F.Passes(e);return d.current=n,i.forEach(r=>{n.addPass(r)}),n.initializeResources(),f(),m.current=performance.now(),u.current=requestAnimationFrame(g.current),window.addEventListener("resize",f),()=>{window.removeEventListener("resize",f),u.current&&cancelAnimationFrame(u.current),s.current&&s.current.destroyAll()}}catch(e){return console.error("Failed to initialize WebGL:",e),()=>{}}},[l,i,a,f]),t.useEffect(()=>{const e=d.current;e&&(e.clearPasses(),i.forEach(n=>{e.addPass(n)}),e.initializeResources())},[i]),L.jsx("canvas",{ref:o,className:E,style:{width:"100%",height:"100%",display:"block",...R}})};exports.PingPongShaderEngine=v;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as p } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as i, useCallback as y, useEffect as E } from "react";
|
|
3
|
+
import { WebGLManager as z } from "../../../core/managers/WebGLManager.mjs";
|
|
4
|
+
import { Passes as A } from "../../../core/systems/Passes.mjs";
|
|
5
|
+
const v = "", P = {}, O = ({
|
|
6
|
+
programConfigs: h,
|
|
7
|
+
passes: s,
|
|
8
|
+
framebuffers: o,
|
|
9
|
+
className: b = v,
|
|
10
|
+
style: F = P,
|
|
11
|
+
useDevicePixelRatio: d = !0
|
|
12
|
+
}) => {
|
|
13
|
+
const a = i(null), c = i(null), f = i(null), u = i(null), l = i(0), w = i((e) => {
|
|
14
|
+
const t = c.current, r = f.current;
|
|
15
|
+
if (!t || !r) return;
|
|
16
|
+
const n = e - l.current;
|
|
17
|
+
r.execute(n), u.current = requestAnimationFrame(w.current);
|
|
18
|
+
}), m = y(() => {
|
|
19
|
+
if (!a.current || !c.current) return;
|
|
20
|
+
const e = window.innerWidth, t = window.innerHeight;
|
|
21
|
+
c.current.setSize(e, t, d);
|
|
22
|
+
const r = c.current, n = r.context.canvas;
|
|
23
|
+
Object.entries(o ?? []).forEach(([L, g]) => {
|
|
24
|
+
const R = g.width || n.width, S = g.height || n.height;
|
|
25
|
+
r.fbo.resizeFramebuffer(L, R, S);
|
|
26
|
+
});
|
|
27
|
+
}, [o, d]);
|
|
28
|
+
return E(() => {
|
|
29
|
+
if (a.current)
|
|
30
|
+
try {
|
|
31
|
+
const e = new z(a.current);
|
|
32
|
+
c.current = e, Object.entries(h).forEach(([r, n]) => {
|
|
33
|
+
e.createProgram(r, n);
|
|
34
|
+
}), Object.entries(o ?? []).forEach(([r, n]) => {
|
|
35
|
+
e.fbo.createFramebuffer(r, n);
|
|
36
|
+
});
|
|
37
|
+
const t = new A(e);
|
|
38
|
+
return f.current = t, s.forEach((r) => {
|
|
39
|
+
t.addPass(r);
|
|
40
|
+
}), t.initializeResources(), m(), l.current = performance.now(), u.current = requestAnimationFrame(w.current), window.addEventListener("resize", m), () => {
|
|
41
|
+
window.removeEventListener("resize", m), u.current && cancelAnimationFrame(u.current), c.current && c.current.destroyAll();
|
|
42
|
+
};
|
|
43
|
+
} catch (e) {
|
|
44
|
+
return console.error("Failed to initialize WebGL:", e), () => {
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}, [h, s, o, m]), E(() => {
|
|
48
|
+
const e = f.current;
|
|
49
|
+
e && (e.clearPasses(), s.forEach((t) => {
|
|
50
|
+
e.addPass(t);
|
|
51
|
+
}), e.initializeResources());
|
|
52
|
+
}, [s]), /* @__PURE__ */ p(
|
|
53
|
+
"canvas",
|
|
54
|
+
{
|
|
55
|
+
ref: a,
|
|
56
|
+
className: b,
|
|
57
|
+
style: {
|
|
58
|
+
width: "100%",
|
|
59
|
+
height: "100%",
|
|
60
|
+
display: "block",
|
|
61
|
+
...F
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
export {
|
|
67
|
+
O as PingPongShaderEngine
|
|
68
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react/jsx-runtime"),c=require("react"),_=require("../../../core/managers/WebGLManager.js"),b={},h="",y={},I={},U=({programConfigs:E,renderCallback:T,renderOptions:i=b,className:p=h,style:F=y,uniformUpdaters:L=I,useFastPath:d=!1,useDevicePixelRatio:w=!0})=>{const f=c.useRef(null),o=c.useRef(null),g=c.useRef(null),u=c.useRef(null),R=c.useRef(0),l=c.useRef(n=>{const e=o.current,r=g.current;if(!e||!r)return;const a=n-R.current,t=e.context;if(d)e.fastRender(r,a,i.clear),t.drawArrays(t.TRIANGLE_STRIP,0,4);else{const s=e.resources.get(r);if(!s)return;e.prepareRender(r,i),A(a,s,t)}u.current=requestAnimationFrame(l.current)}),A=c.useCallback((n,e,r)=>{T(n,e,r)},[T]);c.useEffect(()=>{l.current=n=>{const e=o.current,r=g.current;if(!e||!r)return;const a=n-R.current,t=e.context;if(d)e.fastRender(r,a,i.clear),t.drawArrays(t.TRIANGLE_STRIP,0,4);else{const s=e.resources.get(r);if(!s)return;e.prepareRender(r,i),A(a,s,t)}u.current=requestAnimationFrame(l.current)}},[i,d,A]);const m=c.useCallback(()=>{if(!f.current||!o.current)return;const n=window.innerWidth,e=window.innerHeight;o.current.setSize(n,e,w)},[w]);return c.useEffect(()=>{if(f.current)try{const n=new _.WebGLManager(f.current);o.current=n,m();const e=Object.entries(E);if(e.length>0){const[r,a]=e[0];n.createProgram(r,a),n.createBuffer(r,"a_position",new Float32Array([-1,-1,1,-1,-1,1,1,1])),g.current=r,n.setAttributeOnce(r,"a_position",{name:"a_position",size:2,type:"FLOAT",normalized:!1,stride:0,offset:0});const t=L[r];t&&t.forEach(s=>{n.registerUniformUpdater(r,s.name,s.type,s.updateFn)})}return R.current=performance.now(),u.current=requestAnimationFrame(l.current),window.addEventListener("resize",m),()=>{window.removeEventListener("resize",m),u.current&&cancelAnimationFrame(u.current),o.current&&o.current.destroyAll()}}catch(n){return console.error("Failed to initialize WebGL:",n),()=>{}}},[E,L,m]),S.jsx("canvas",{ref:f,className:p,style:F})};exports.ShaderEngine=U;
|