micugl 0.0.7 → 0.0.9
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 +44 -9
- 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,106 @@
|
|
|
1
|
+
import { jsx as S } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as a, useCallback as L, useEffect as F } from "react";
|
|
3
|
+
import { WebGLManager as h } from "../../../core/managers/WebGLManager.mjs";
|
|
4
|
+
const U = {}, y = "", z = {}, b = {}, P = ({
|
|
5
|
+
programConfigs: E,
|
|
6
|
+
renderCallback: p,
|
|
7
|
+
renderOptions: i = U,
|
|
8
|
+
className: _ = y,
|
|
9
|
+
style: I = z,
|
|
10
|
+
uniformUpdaters: T = b,
|
|
11
|
+
useFastPath: d = !1,
|
|
12
|
+
useDevicePixelRatio: w = !0
|
|
13
|
+
}) => {
|
|
14
|
+
const f = a(null), o = a(null), g = a(null), u = a(null), A = a(0), m = a((n) => {
|
|
15
|
+
const r = o.current, e = g.current;
|
|
16
|
+
if (!r || !e) return;
|
|
17
|
+
const s = n - A.current, t = r.context;
|
|
18
|
+
if (d)
|
|
19
|
+
r.fastRender(e, s, i.clear), t.drawArrays(t.TRIANGLE_STRIP, 0, 4);
|
|
20
|
+
else {
|
|
21
|
+
const c = r.resources.get(e);
|
|
22
|
+
if (!c) return;
|
|
23
|
+
r.prepareRender(e, i), R(s, c, t);
|
|
24
|
+
}
|
|
25
|
+
u.current = requestAnimationFrame(m.current);
|
|
26
|
+
}), R = L((n, r, e) => {
|
|
27
|
+
p(n, r, e);
|
|
28
|
+
}, [p]);
|
|
29
|
+
F(() => {
|
|
30
|
+
m.current = (n) => {
|
|
31
|
+
const r = o.current, e = g.current;
|
|
32
|
+
if (!r || !e) return;
|
|
33
|
+
const s = n - A.current, t = r.context;
|
|
34
|
+
if (d)
|
|
35
|
+
r.fastRender(e, s, i.clear), t.drawArrays(t.TRIANGLE_STRIP, 0, 4);
|
|
36
|
+
else {
|
|
37
|
+
const c = r.resources.get(e);
|
|
38
|
+
if (!c) return;
|
|
39
|
+
r.prepareRender(e, i), R(s, c, t);
|
|
40
|
+
}
|
|
41
|
+
u.current = requestAnimationFrame(m.current);
|
|
42
|
+
};
|
|
43
|
+
}, [i, d, R]);
|
|
44
|
+
const l = L(() => {
|
|
45
|
+
if (!f.current || !o.current) return;
|
|
46
|
+
const n = window.innerWidth, r = window.innerHeight;
|
|
47
|
+
o.current.setSize(n, r, w);
|
|
48
|
+
}, [w]);
|
|
49
|
+
return F(() => {
|
|
50
|
+
if (f.current)
|
|
51
|
+
try {
|
|
52
|
+
const n = new h(f.current);
|
|
53
|
+
o.current = n, l();
|
|
54
|
+
const r = Object.entries(E);
|
|
55
|
+
if (r.length > 0) {
|
|
56
|
+
const [e, s] = r[0];
|
|
57
|
+
n.createProgram(e, s), n.createBuffer(
|
|
58
|
+
e,
|
|
59
|
+
"a_position",
|
|
60
|
+
new Float32Array([
|
|
61
|
+
-1,
|
|
62
|
+
-1,
|
|
63
|
+
1,
|
|
64
|
+
-1,
|
|
65
|
+
-1,
|
|
66
|
+
1,
|
|
67
|
+
1,
|
|
68
|
+
1
|
|
69
|
+
])
|
|
70
|
+
), g.current = e, n.setAttributeOnce(e, "a_position", {
|
|
71
|
+
name: "a_position",
|
|
72
|
+
size: 2,
|
|
73
|
+
type: "FLOAT",
|
|
74
|
+
normalized: !1,
|
|
75
|
+
stride: 0,
|
|
76
|
+
offset: 0
|
|
77
|
+
});
|
|
78
|
+
const t = T[e];
|
|
79
|
+
t && t.forEach((c) => {
|
|
80
|
+
n.registerUniformUpdater(
|
|
81
|
+
e,
|
|
82
|
+
c.name,
|
|
83
|
+
c.type,
|
|
84
|
+
c.updateFn
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return A.current = performance.now(), u.current = requestAnimationFrame(m.current), window.addEventListener("resize", l), () => {
|
|
89
|
+
window.removeEventListener("resize", l), u.current && cancelAnimationFrame(u.current), o.current && o.current.destroyAll();
|
|
90
|
+
};
|
|
91
|
+
} catch (n) {
|
|
92
|
+
return console.error("Failed to initialize WebGL:", n), () => {
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}, [E, T, l]), /* @__PURE__ */ S(
|
|
96
|
+
"canvas",
|
|
97
|
+
{
|
|
98
|
+
ref: f,
|
|
99
|
+
className: _,
|
|
100
|
+
style: I
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
export {
|
|
105
|
+
P as ShaderEngine
|
|
106
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),a=()=>{const[o,c]=r.useState(!1);return r.useEffect(()=>{const t=()=>{const e=document.documentElement.classList.contains("dark");c(e)};t();const s=new MutationObserver(e=>{e.forEach(n=>{n.attributeName==="class"&&t()})});return s.observe(document.documentElement,{attributes:!0}),()=>{s.disconnect()}},[]),o};exports.useDarkMode=a;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useState as c, useEffect as a } from "react";
|
|
2
|
+
const d = () => {
|
|
3
|
+
const [o, r] = c(!1);
|
|
4
|
+
return a(() => {
|
|
5
|
+
const t = () => {
|
|
6
|
+
const e = document.documentElement.classList.contains("dark");
|
|
7
|
+
r(e);
|
|
8
|
+
};
|
|
9
|
+
t();
|
|
10
|
+
const s = new MutationObserver((e) => {
|
|
11
|
+
e.forEach((n) => {
|
|
12
|
+
n.attributeName === "class" && t();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
return s.observe(document.documentElement, { attributes: !0 }), () => {
|
|
16
|
+
s.disconnect();
|
|
17
|
+
};
|
|
18
|
+
}, []), o;
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
d as useDarkMode
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react"),v=require("./useUniformUpdaters.js"),$=({programId:e,secondaryProgramId:n,iterations:o=1,uniforms:C,secondaryUniforms:E={},framebufferOptions:c={width:0,height:0,textureCount:2,textureOptions:{minFilter:WebGLRenderingContext.LINEAR,magFilter:WebGLRenderingContext.LINEAR}},renderOptions:s={clear:!0},customPasses:r})=>{const l=v.useUniformUpdaters(e,C),U=v.useUniformUpdaters(n??`${e}-secondary`,E);return S.useMemo(()=>{const u=`${e}-fb-a`,f=`${e}-fb-b`,L={[u]:c,[f]:c};let i=[];if(r)i=r;else{i.push({programId:e,inputTextures:[],outputFramebuffer:u,renderOptions:s});for(let t=0;t<o;t++){const p=n&&t%2===1?n:e,b=t%2===0?u:f,a=t%2===0?f:u,x=n&&t%2===1?U[n]:l[e],T={};x.forEach(F=>{const R=F.updateFn;T[F.name]={type:F.type,value:(m,y,A)=>R(m,y,A)}}),i.push({programId:p,inputTextures:[{id:b,textureUnit:0,bindingType:"read"}],outputFramebuffer:a,uniforms:T,renderOptions:s})}const M=o%2===0?f:u,h={};(n?U[n]:l[e]).forEach(t=>{const p=t.updateFn;h[t.name]={type:t.type,value:(b,a,x)=>p(b,a,x)}}),i.push({programId:n??e,inputTextures:[{id:M,textureUnit:0,bindingType:"read"}],outputFramebuffer:null,uniforms:h,renderOptions:s})}return{passes:i,framebuffers:L}},[e,n,o,l,U,c,s,r])};exports.usePingPongPasses=$;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useMemo as G } from "react";
|
|
2
|
+
import { useUniformUpdaters as m } from "./useUniformUpdaters.mjs";
|
|
3
|
+
const y = ({
|
|
4
|
+
programId: t,
|
|
5
|
+
secondaryProgramId: n,
|
|
6
|
+
iterations: o = 1,
|
|
7
|
+
uniforms: C,
|
|
8
|
+
secondaryUniforms: E = {},
|
|
9
|
+
framebufferOptions: l = {
|
|
10
|
+
width: 0,
|
|
11
|
+
height: 0,
|
|
12
|
+
textureCount: 2,
|
|
13
|
+
textureOptions: {
|
|
14
|
+
minFilter: WebGLRenderingContext.LINEAR,
|
|
15
|
+
magFilter: WebGLRenderingContext.LINEAR
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
renderOptions: s = { clear: !0 },
|
|
19
|
+
customPasses: c
|
|
20
|
+
}) => {
|
|
21
|
+
const p = m(t, C), U = m(
|
|
22
|
+
n ?? `${t}-secondary`,
|
|
23
|
+
E
|
|
24
|
+
);
|
|
25
|
+
return G(() => {
|
|
26
|
+
const u = `${t}-fb-a`, f = `${t}-fb-b`, L = {
|
|
27
|
+
[u]: l,
|
|
28
|
+
[f]: l
|
|
29
|
+
};
|
|
30
|
+
let i = [];
|
|
31
|
+
if (c)
|
|
32
|
+
i = c;
|
|
33
|
+
else {
|
|
34
|
+
i.push({
|
|
35
|
+
programId: t,
|
|
36
|
+
inputTextures: [],
|
|
37
|
+
outputFramebuffer: u,
|
|
38
|
+
renderOptions: s
|
|
39
|
+
});
|
|
40
|
+
for (let e = 0; e < o; e++) {
|
|
41
|
+
const r = n && e % 2 === 1 ? n : t, b = e % 2 === 0 ? u : f, x = e % 2 === 0 ? f : u, F = n && e % 2 === 1 ? U[n] : p[t], T = {};
|
|
42
|
+
F.forEach((h) => {
|
|
43
|
+
const v = h.updateFn;
|
|
44
|
+
T[h.name] = {
|
|
45
|
+
type: h.type,
|
|
46
|
+
value: (A, M, $) => v(A, M, $)
|
|
47
|
+
};
|
|
48
|
+
}), i.push({
|
|
49
|
+
programId: r,
|
|
50
|
+
inputTextures: [{
|
|
51
|
+
id: b,
|
|
52
|
+
textureUnit: 0,
|
|
53
|
+
bindingType: "read"
|
|
54
|
+
}],
|
|
55
|
+
outputFramebuffer: x,
|
|
56
|
+
uniforms: T,
|
|
57
|
+
renderOptions: s
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const R = o % 2 === 0 ? f : u, a = {};
|
|
61
|
+
(n ? U[n] : p[t]).forEach((e) => {
|
|
62
|
+
const r = e.updateFn;
|
|
63
|
+
a[e.name] = {
|
|
64
|
+
type: e.type,
|
|
65
|
+
value: (b, x, F) => r(b, x, F)
|
|
66
|
+
};
|
|
67
|
+
}), i.push({
|
|
68
|
+
programId: n ?? t,
|
|
69
|
+
inputTextures: [{
|
|
70
|
+
id: R,
|
|
71
|
+
textureUnit: 0,
|
|
72
|
+
bindingType: "read"
|
|
73
|
+
}],
|
|
74
|
+
outputFramebuffer: null,
|
|
75
|
+
uniforms: a,
|
|
76
|
+
renderOptions: s
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return { passes: i, framebuffers: L };
|
|
80
|
+
}, [
|
|
81
|
+
t,
|
|
82
|
+
n,
|
|
83
|
+
o,
|
|
84
|
+
p,
|
|
85
|
+
U,
|
|
86
|
+
l,
|
|
87
|
+
s,
|
|
88
|
+
c
|
|
89
|
+
]);
|
|
90
|
+
};
|
|
91
|
+
export {
|
|
92
|
+
y as usePingPongPasses
|
|
93
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),u=require("../lib/createUniformUpdater.js"),a=(t,r)=>n.useMemo(()=>{const s=u.createCommonUpdaters();return Object.entries(r).forEach(([e,o])=>{const c=e.startsWith("u_")?e:`u_${e}`;s.push(u.createUniformUpdater(c,o.type,o.value))}),{[t]:s}},[t,r]);exports.useUniformUpdaters=a;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useMemo as c } from "react";
|
|
2
|
+
import { createCommonUpdaters as n, createUniformUpdater as p } from "../lib/createUniformUpdater.mjs";
|
|
3
|
+
const a = (e, r) => c(() => {
|
|
4
|
+
const o = n();
|
|
5
|
+
return Object.entries(r).forEach(([t, s]) => {
|
|
6
|
+
const u = t.startsWith("u_") ? t : `u_${t}`;
|
|
7
|
+
o.push(p(u, s.type, s.value));
|
|
8
|
+
}), { [e]: o };
|
|
9
|
+
}, [e, r]);
|
|
10
|
+
export {
|
|
11
|
+
a as useUniformUpdaters
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../../core/lib/vectorUtils.js");function n(t,r,e){return{name:t,type:r,updateFn:typeof e=="function"?e:o=>e}}function c(t){return t.map(({name:r,type:e,value:o})=>n(r,e,o))}function a(){return[n("u_time","float",t=>(t??0)*.001),n("u_resolution","vec2",(t,r,e)=>i.vec2([r??0,e??0]))]}exports.createCommonUpdaters=a;exports.createUniformUpdater=n;exports.createUniformUpdaters=c;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { vec2 as i } from "../../core/lib/vectorUtils.mjs";
|
|
2
|
+
function n(e, r, t) {
|
|
3
|
+
return {
|
|
4
|
+
name: e,
|
|
5
|
+
type: r,
|
|
6
|
+
updateFn: typeof t == "function" ? t : (o) => t
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function c(e) {
|
|
10
|
+
return e.map(
|
|
11
|
+
({ name: r, type: t, value: o }) => n(r, t, o)
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
function f() {
|
|
15
|
+
return [
|
|
16
|
+
n("u_time", "float", (e) => (e ?? 0) * 1e-3),
|
|
17
|
+
n(
|
|
18
|
+
"u_resolution",
|
|
19
|
+
"vec2",
|
|
20
|
+
(e, r, t) => i([r ?? 0, t ?? 0])
|
|
21
|
+
)
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
f as createCommonUpdaters,
|
|
26
|
+
n as createUniformUpdater,
|
|
27
|
+
c as createUniformUpdaters
|
|
28
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
export declare interface AttributeConfig {
|
|
2
|
+
name: string;
|
|
3
|
+
size: number;
|
|
4
|
+
type: AttributeType;
|
|
5
|
+
normalized: boolean;
|
|
6
|
+
stride: number;
|
|
7
|
+
offset: number;
|
|
8
|
+
instanced?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare type AttributeType = 'FLOAT' | 'BYTE' | 'SHORT' | 'UNSIGNED_BYTE' | 'UNSIGNED_SHORT';
|
|
12
|
+
|
|
13
|
+
export declare interface BufferData {
|
|
14
|
+
buffer: WebGLBuffer;
|
|
15
|
+
data: Float32Array | Uint8Array | Uint16Array | Int8Array | Int16Array;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export declare type Float32Array16 = TypedFloat32Array<16>;
|
|
19
|
+
|
|
20
|
+
export declare type Float32Array2 = TypedFloat32Array<2>;
|
|
21
|
+
|
|
22
|
+
export declare type Float32Array3 = TypedFloat32Array<3>;
|
|
23
|
+
|
|
24
|
+
export declare type Float32Array4 = TypedFloat32Array<4>;
|
|
25
|
+
|
|
26
|
+
export declare type Float32Array9 = TypedFloat32Array<9>;
|
|
27
|
+
|
|
28
|
+
export declare interface FramebufferOptions {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
textureCount?: number;
|
|
32
|
+
textureOptions?: Partial<TextureOptions>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export declare interface FramebufferResources {
|
|
36
|
+
framebuffer: WebGLFramebuffer;
|
|
37
|
+
textures: WebGLTexture[];
|
|
38
|
+
currentTextureIndex: number;
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export declare type Mat2 = [
|
|
44
|
+
number,
|
|
45
|
+
number,
|
|
46
|
+
number,
|
|
47
|
+
number
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
export declare type Mat3 = [
|
|
51
|
+
number,
|
|
52
|
+
number,
|
|
53
|
+
number,
|
|
54
|
+
number,
|
|
55
|
+
number,
|
|
56
|
+
number,
|
|
57
|
+
number,
|
|
58
|
+
number,
|
|
59
|
+
number
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
export declare type Mat4 = [
|
|
63
|
+
number,
|
|
64
|
+
number,
|
|
65
|
+
number,
|
|
66
|
+
number,
|
|
67
|
+
number,
|
|
68
|
+
number,
|
|
69
|
+
number,
|
|
70
|
+
number,
|
|
71
|
+
number,
|
|
72
|
+
number,
|
|
73
|
+
number,
|
|
74
|
+
number,
|
|
75
|
+
number,
|
|
76
|
+
number,
|
|
77
|
+
number,
|
|
78
|
+
number
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
export declare interface PingPongState {
|
|
82
|
+
readIndex: number;
|
|
83
|
+
writeIndex: number;
|
|
84
|
+
swap: () => void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export declare interface RenderOptions {
|
|
88
|
+
clear?: boolean;
|
|
89
|
+
clearColor?: Vec4;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export declare interface RenderPass {
|
|
93
|
+
programId: string;
|
|
94
|
+
inputTextures: TextureBinding[];
|
|
95
|
+
outputFramebuffer?: string | null;
|
|
96
|
+
uniforms?: Record<string, {
|
|
97
|
+
type: UniformType;
|
|
98
|
+
value: RenderPassUniformValue;
|
|
99
|
+
}>;
|
|
100
|
+
renderOptions?: RenderOptions;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export declare type RenderPassUniformUpdateFn = (time: number, width: number, height: number) => UniformTypeMap[UniformType];
|
|
104
|
+
|
|
105
|
+
export declare type RenderPassUniformValue = UniformTypeMap[UniformType] | RenderPassUniformUpdateFn;
|
|
106
|
+
|
|
107
|
+
export declare type ShaderAttributeLocations = Record<string, number>;
|
|
108
|
+
|
|
109
|
+
export declare interface ShaderProgramConfig {
|
|
110
|
+
vertexShader: string;
|
|
111
|
+
fragmentShader: string;
|
|
112
|
+
uniforms: UniformConfig[];
|
|
113
|
+
attributes?: AttributeConfig[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export declare type ShaderRenderCallback = (time: number, resources: ShaderResources, gl: WebGLRenderingContext) => void;
|
|
117
|
+
|
|
118
|
+
export declare interface ShaderResources {
|
|
119
|
+
program: WebGLProgram;
|
|
120
|
+
uniforms: ShaderUniformLocations;
|
|
121
|
+
attributes: ShaderAttributeLocations;
|
|
122
|
+
buffers: Record<string, BufferData>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export declare type ShaderUniformLocations = Record<string, WebGLUniformLocation | null>;
|
|
126
|
+
|
|
127
|
+
export declare interface TextureBinding {
|
|
128
|
+
id: string;
|
|
129
|
+
textureUnit: number;
|
|
130
|
+
bindingType: 'read' | 'write' | 'readwrite';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export declare interface TextureOptions {
|
|
134
|
+
width: number;
|
|
135
|
+
height: number;
|
|
136
|
+
internalFormat?: number;
|
|
137
|
+
format?: number;
|
|
138
|
+
type?: number;
|
|
139
|
+
minFilter?: number;
|
|
140
|
+
magFilter?: number;
|
|
141
|
+
wrapS?: number;
|
|
142
|
+
wrapT?: number;
|
|
143
|
+
generateMipmap?: boolean;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export declare type TypedFloat32Array<N extends number> = Float32Array & {
|
|
147
|
+
length: N;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export declare interface UniformConfig {
|
|
151
|
+
name: string;
|
|
152
|
+
type: UniformType;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export declare interface UniformParam<T extends UniformType = UniformType> {
|
|
156
|
+
value: UniformValue<T>;
|
|
157
|
+
type: T;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export declare type UniformParamMap = {
|
|
161
|
+
[K in UniformType]: UniformParam<K>;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export declare type UniformType = 'float' | 'vec2' | 'vec3' | 'vec4' | 'mat2' | 'mat3' | 'mat4' | 'int' | 'sampler2D';
|
|
165
|
+
|
|
166
|
+
export declare interface UniformTypeMap {
|
|
167
|
+
'float': number;
|
|
168
|
+
'int': number;
|
|
169
|
+
'sampler2D': number;
|
|
170
|
+
'vec2': Float32Array2;
|
|
171
|
+
'vec3': Float32Array3;
|
|
172
|
+
'vec4': Float32Array4;
|
|
173
|
+
'mat2': Float32Array4;
|
|
174
|
+
'mat3': Float32Array9;
|
|
175
|
+
'mat4': Float32Array16;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export declare type UniformUpdateFn<T extends UniformType> = (time?: number, width?: number, height?: number) => UniformTypeMap[T];
|
|
179
|
+
|
|
180
|
+
export declare interface UniformUpdaterDef<T extends UniformType> {
|
|
181
|
+
name: string;
|
|
182
|
+
type: T;
|
|
183
|
+
updateFn: UniformUpdateFn<T>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export declare type UniformValue<T extends UniformType> = UniformTypeMap[T] | UniformUpdateFn<T>;
|
|
187
|
+
|
|
188
|
+
export declare type Vec2 = [number, number];
|
|
189
|
+
|
|
190
|
+
export declare type Vec3 = [number, number, number];
|
|
191
|
+
|
|
192
|
+
export declare type Vec4 = [number, number, number, number];
|
|
193
|
+
|
|
194
|
+
export declare type WebGLExtensionName = Extract<keyof WebGLExtensionTypes, string>;
|
|
195
|
+
|
|
196
|
+
export declare interface WebGLExtensionTypes {
|
|
197
|
+
'OES_texture_float': OES_texture_float;
|
|
198
|
+
'OES_texture_float_linear': OES_texture_float_linear;
|
|
199
|
+
'OES_vertex_array_object': OES_vertex_array_object;
|
|
200
|
+
'ANGLE_instanced_arrays': ANGLE_instanced_arrays;
|
|
201
|
+
[key: string]: unknown;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { }
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/package.json
CHANGED
|
@@ -1,31 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "micugl",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Micu gl - Small React shader library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
|
+
"typesVersions": {
|
|
10
|
+
"*": {
|
|
11
|
+
"*": [
|
|
12
|
+
"dist/*"
|
|
13
|
+
],
|
|
14
|
+
"types": [
|
|
15
|
+
"dist/types.d.ts"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
9
19
|
"exports": {
|
|
10
20
|
".": {
|
|
11
21
|
"types": "./dist/index.d.ts",
|
|
12
22
|
"import": "./dist/index.mjs",
|
|
13
23
|
"require": "./dist/index.js"
|
|
14
24
|
},
|
|
25
|
+
"./types": {
|
|
26
|
+
"types": "./dist/types.d.ts",
|
|
27
|
+
"import": "./dist/types.mjs",
|
|
28
|
+
"require": "./dist/types.js"
|
|
29
|
+
},
|
|
30
|
+
"./core": {
|
|
31
|
+
"types": "./dist/core/index.d.ts",
|
|
32
|
+
"import": "./dist/core/index.mjs",
|
|
33
|
+
"require": "./dist/core/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./react": {
|
|
36
|
+
"types": "./dist/react/index.d.ts",
|
|
37
|
+
"import": "./dist/react/index.mjs",
|
|
38
|
+
"require": "./dist/react/index.js"
|
|
39
|
+
},
|
|
15
40
|
"./examples": {
|
|
16
41
|
"types": "./dist/examples/index.d.ts",
|
|
17
42
|
"import": "./dist/examples/index.mjs",
|
|
18
43
|
"require": "./dist/examples/index.js"
|
|
19
44
|
},
|
|
20
|
-
"./examples/Marble": {
|
|
21
|
-
"types": "./dist/examples/Marble/
|
|
22
|
-
"import": "./dist/examples/Marble/
|
|
23
|
-
"require": "./dist/examples/Marble/
|
|
45
|
+
"./examples/Marble/MarbleScene": {
|
|
46
|
+
"types": "./dist/examples/Marble/MarbleScene.d.ts",
|
|
47
|
+
"import": "./dist/examples/Marble/MarbleScene.mjs",
|
|
48
|
+
"require": "./dist/examples/Marble/MarbleScene.js"
|
|
49
|
+
},
|
|
50
|
+
"./examples/Marble/marbleShaders": {
|
|
51
|
+
"types": "./dist/examples/Marble/marbleShaders.d.ts",
|
|
52
|
+
"import": "./dist/examples/Marble/marbleShaders.mjs",
|
|
53
|
+
"require": "./dist/examples/Marble/marbleShaders.js"
|
|
54
|
+
},
|
|
55
|
+
"./examples/SimpleRipple/SimpleRippleScene": {
|
|
56
|
+
"types": "./dist/examples/SimpleRipple/SimpleRippleScene.d.ts",
|
|
57
|
+
"import": "./dist/examples/SimpleRipple/SimpleRippleScene.mjs",
|
|
58
|
+
"require": "./dist/examples/SimpleRipple/SimpleRippleScene.js"
|
|
24
59
|
},
|
|
25
|
-
"./examples/SimpleRipple": {
|
|
26
|
-
"types": "./dist/examples/SimpleRipple/
|
|
27
|
-
"import": "./dist/examples/SimpleRipple/
|
|
28
|
-
"require": "./dist/examples/SimpleRipple/
|
|
60
|
+
"./examples/SimpleRipple/rippleShaders": {
|
|
61
|
+
"types": "./dist/examples/SimpleRipple/rippleShaders.d.ts",
|
|
62
|
+
"import": "./dist/examples/SimpleRipple/rippleShaders.mjs",
|
|
63
|
+
"require": "./dist/examples/SimpleRipple/rippleShaders.js"
|
|
29
64
|
}
|
|
30
65
|
},
|
|
31
66
|
"files": [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const v=require("react/jsx-runtime"),h=require("react"),U=require("./useUniformUpdaters-DGX0mf9g.js");class A{constructor(e){this.passes=[],this.pingPongIds=new Set,this.webglManager=e}addPass(e){this.passes.push(e),e.outputFramebuffer&&this.pingPongIds.add(e.outputFramebuffer),e.inputTextures.forEach(s=>{s.bindingType==="readwrite"&&this.pingPongIds.add(s.id)})}clearPasses(){this.passes=[],this.pingPongIds.clear()}execute(e){const s=this.webglManager.context,u=this.webglManager.fbo;for(const r of this.passes){if(r.outputFramebuffer)if(this.pingPongIds.has(r.outputFramebuffer)){const{write:t}=u.getPingPongIndices(r.outputFramebuffer);u.bindFramebuffer(r.outputFramebuffer,t)}else u.bindFramebuffer(r.outputFramebuffer);else u.bindFramebuffer(null);this.webglManager.prepareRender(r.programId,r.renderOptions),r.inputTextures.forEach(t=>{let i=t.bindingType==="read"?0:1;if(this.pingPongIds.has(t.id)){const{read:o,write:g}=u.getPingPongIndices(t.id);i=t.bindingType==="read"||t.bindingType==="readwrite"?o:g}u.bindTexture(t.id,t.textureUnit,i),this.webglManager.setUniform(r.programId,`u_${t.id}`,t.textureUnit,"sampler2D")}),this.webglManager.updateUniforms(r.programId,e),r.uniforms&&Object.entries(r.uniforms).forEach(([t,i])=>{const o=typeof i.value=="function"?i.value(e,s.canvas.width,s.canvas.height):i.value;this.webglManager.setUniform(r.programId,t,o,i.type)}),s.drawArrays(s.TRIANGLE_STRIP,0,4),r.outputFramebuffer&&this.pingPongIds.has(r.outputFramebuffer)&&u.swapTextures(r.outputFramebuffer),r.inputTextures.forEach(t=>{t.bindingType==="readwrite"&&this.pingPongIds.has(t.id)&&u.swapTextures(t.id)})}}initializeResources(){for(const e of this.passes){const s=this.webglManager.resources.get(e.programId);s&&!s.buffers.a_position&&(this.webglManager.createBuffer(e.programId,"a_position",new Float32Array([-1,-1,1,-1,-1,1,1,1])),this.webglManager.setAttributeOnce(e.programId,"a_position",{name:"a_position",size:2,type:"FLOAT",normalized:!1,stride:0,offset:0}))}}}const _="",j={},L=({programConfigs:a,passes:e,framebuffers:s,className:u=_,style:r=j,useDevicePixelRatio:t=!0})=>{const i=h.useRef(null),o=h.useRef(null),g=h.useRef(null),l=h.useRef(null),p=h.useRef(0),b=h.useRef(n=>{const f=o.current,c=g.current;if(!f||!c)return;const w=n-p.current;c.execute(w),l.current=requestAnimationFrame(b.current)}),m=h.useCallback(()=>{if(!i.current||!o.current)return;const n=window.innerWidth,f=window.innerHeight;o.current.setSize(n,f,t);const c=o.current,w=c.context.canvas;Object.entries(s??[]).forEach(([d,F])=>{const P=F.width||w.width,E=F.height||w.height;c.fbo.resizeFramebuffer(d,P,E)})},[s,t]);return h.useEffect(()=>{if(i.current)try{const n=new U.WebGLManager(i.current);o.current=n,Object.entries(a).forEach(([c,w])=>{n.createProgram(c,w)}),Object.entries(s??[]).forEach(([c,w])=>{n.fbo.createFramebuffer(c,w)});const f=new A(n);return g.current=f,e.forEach(c=>{f.addPass(c)}),f.initializeResources(),m(),p.current=performance.now(),l.current=requestAnimationFrame(b.current),window.addEventListener("resize",m),()=>{window.removeEventListener("resize",m),l.current&&cancelAnimationFrame(l.current),o.current&&o.current.destroyAll()}}catch(n){return console.error("Failed to initialize WebGL:",n),()=>{}}},[a,e,s,m]),h.useEffect(()=>{const n=g.current;n&&(n.clearPasses(),e.forEach(f=>{n.addPass(f)}),n.initializeResources())},[e]),v.jsx("canvas",{ref:i,className:u,style:{width:"100%",height:"100%",display:"block",...r}})},M=({programId:a,secondaryProgramId:e,iterations:s=1,uniforms:u,secondaryUniforms:r={},framebufferOptions:t={width:0,height:0,textureCount:2,textureOptions:{minFilter:WebGLRenderingContext.LINEAR,magFilter:WebGLRenderingContext.LINEAR}},renderOptions:i={clear:!0},customPasses:o})=>{const g=U.useUniformUpdaters(a,u),l=U.useUniformUpdaters(e??`${a}-secondary`,r);return h.useMemo(()=>{const p=`${a}-fb-a`,b=`${a}-fb-b`,m={[p]:t,[b]:t};let n=[];if(o)n=o;else{n.push({programId:a,inputTextures:[],outputFramebuffer:p,renderOptions:i});for(let d=0;d<s;d++){const F=e&&d%2===1?e:a,P=d%2===0?p:b,E=d%2===0?b:p,R=e&&d%2===1?l[e]:g[a],y={};R.forEach(T=>{const S=T.updateFn;y[T.name]={type:T.type,value:(x,I,z)=>S(x,I,z)}}),n.push({programId:F,inputTextures:[{id:P,textureUnit:0,bindingType:"read"}],outputFramebuffer:E,uniforms:y,renderOptions:i})}const f=s%2===0?b:p,c={};(e?l[e]:g[a]).forEach(d=>{const F=d.updateFn;c[d.name]={type:d.type,value:(P,E,R)=>F(P,E,R)}}),n.push({programId:e??a,inputTextures:[{id:f,textureUnit:0,bindingType:"read"}],outputFramebuffer:null,uniforms:c,renderOptions:i})}return{passes:n,framebuffers:m}},[a,e,s,g,l,t,i,o])},C={clear:!0,clearColor:[0,0,0,1]},N=({programId:a,shaderConfig:e,secondaryProgramId:s,secondaryShaderConfig:u,iterations:r=1,uniforms:t,secondaryUniforms:i,framebufferOptions:o,className:g="",style:l,customPasses:p,renderOptions:b=C})=>{const m=s??`${a}-secondary`,n={[a]:e};u&&(n[m]=u);const{passes:f,framebuffers:c}=M({programId:a,secondaryProgramId:u?m:void 0,iterations:r,uniforms:t,secondaryUniforms:i,framebufferOptions:o,renderOptions:b,customPasses:p});return v.jsx(L,{programConfigs:n,passes:f,framebuffers:c,className:g,style:l})};exports.BasePingPongShaderComponent=N;exports.Passes=A;exports.PingPongShaderEngine=L;exports.usePingPongPasses=M;
|