glre 0.46.0 → 0.48.0
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 +1017 -29
- package/dist/addons.d.ts +3 -2
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +27 -26
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts +8 -5
- package/dist/node.cjs +42 -42
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +3 -2
- package/dist/node.js +15 -15
- package/dist/node.js.map +1 -1
- package/dist/react.d.ts +27 -26
- package/dist/solid.d.ts +27 -26
- package/package.json +1 -1
- package/src/helpers.ts +2 -2
- package/src/index.ts +5 -3
- package/src/node/types.ts +0 -2
- package/src/node/utils/index.ts +4 -1
- package/src/node/utils/infer.ts +13 -14
- package/src/node/utils/parse.ts +5 -5
- package/src/node/utils/utils.ts +13 -8
- package/src/types.ts +6 -4
- package/src/webgl/compute.ts +4 -4
- package/src/webgl/graphic.ts +6 -6
- package/src/webgpu/compute.ts +5 -5
- package/src/webgpu/graphic.ts +15 -27
- package/src/webgpu/index.ts +36 -17
- package/src/webgpu/utils.ts +23 -27
package/dist/node.d.ts
CHANGED
|
@@ -128,7 +128,9 @@ type GL = EventState<{
|
|
|
128
128
|
gpu: GPUCanvasContext;
|
|
129
129
|
device: GPUDevice;
|
|
130
130
|
format: GPUTextureFormat;
|
|
131
|
-
|
|
131
|
+
passEncoder: GPURenderPassEncoder;
|
|
132
|
+
commandEncoder: GPUCommandEncoder;
|
|
133
|
+
depthTexture?: GPUTexture;
|
|
132
134
|
binding: Binding;
|
|
133
135
|
/**
|
|
134
136
|
* core state
|
|
@@ -219,7 +221,6 @@ interface NodeProps {
|
|
|
219
221
|
}
|
|
220
222
|
interface NodeContext {
|
|
221
223
|
gl?: Partial<GL>;
|
|
222
|
-
binding?: Binding;
|
|
223
224
|
label?: 'vert' | 'frag' | 'compute';
|
|
224
225
|
isWebGL?: boolean;
|
|
225
226
|
units?: any;
|
package/dist/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var G=["toBool","toUInt","toInt","toFloat","toBVec2","toIVec2","toUVec2","toVec2","toBVec3","toIVec3","toUVec3","toVec3","toBVec4","toIVec4","toUVec4","toVec4","toColor","toMat2","toMat3","toMat4"],D={bool:"bool",uint:"u32",int:"i32",float:"f32",bvec2:"vec2<bool>",ivec2:"vec2i",uvec2:"vec2u",vec2:"vec2f",bvec3:"vec3<bool>",ivec3:"vec3i",uvec3:"vec3u",vec3:"vec3f",bvec4:"vec4<bool>",ivec4:"vec4i",uvec4:"vec4u",vec4:"vec4f",color:"color",mat2:"mat2x2f",mat3:"mat3x3f",mat4:"mat4x4f",texture:"texture_2d<f32>",sampler2D:"sampler",struct:"struct"},P=Object.keys(D),w={not:"",add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>",addAssign:"+=",subAssign:"-=",mulAssign:"*=",divAssign:"/=",modAssign:"%=",bitAndAssign:"&=",bitOrAssign:"|=",bitXorAssign:"^=",shiftLeftAssign:"<<=",shiftRightAssign:">>="},q=Object.keys(w),W={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},j={position:"vec4",vertex_index:"uint",instance_index:"uint",front_facing:"bool",frag_depth:"float",sample_index:"uint",sample_mask:"uint",point_coord:"vec2",global_invocation_id:"uvec3",positionLocal:"vec3",positionWorld:"vec3",positionView:"vec3",normalLocal:"vec3",normalWorld:"vec3",normalView:"vec3",screenCoordinate:"vec2",screenUV:"vec2",gl_FragCoord:"vec4",gl_VertexID:"uint",gl_InstanceID:"uint",gl_FrontFacing:"bool",gl_FragDepth:"float",gl_SampleID:"uint",gl_SampleMask:"uint",gl_PointCoord:"vec2",normal:"vec3",uv:"vec2",color:"vec4"},K=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],Z=["and","or"],Q=[["float","vec2","vec2"],["float","vec3","vec3"],["float","vec4","vec4"],["int","ivec2","ivec2"],["int","ivec3","ivec3"],["int","ivec4","ivec4"],["uint","uvec2","uvec2"],["uint","uvec3","uvec3"],["uint","uvec4","uvec4"],["mat2","vec2","vec2"],["mat3","vec3","vec3"],["mat4","vec4","vec4"],["vec2","mat2","vec2"],["vec3","mat3","vec3"],["vec4","mat4","vec4"]],J={position:"gl_FragCoord",vertex_index:"gl_VertexID",instance_index:"gl_InstanceID",front_facing:"gl_FrontFacing",frag_depth:"gl_FragDepth",sample_index:"gl_SampleID",sample_mask:"gl_SampleMask",point_coord:"gl_PointCoord",uv:"gl_FragCoord.xy"},M={all:"bool",any:"bool",determinant:"float",distance:"float",dot:"float",length:"float",lengthSq:"float",luminance:"float",cross:"vec3",cubeTexture:"vec4",texture:"vec4",texelFetch:"vec4",textureLod:"vec4"},ee=[...Object.keys(M),"abs","acos","acosh","asin","asinh","atan","atanh","ceil","cos","cosh","dFdx","dFdy","degrees","exp","exp2","floor","fract","fwidth","inverse","inverseSqrt","log","log2","negate","normalize","oneMinus","radians","reciprocal","round","sign","sin","sinh","sqrt","tan","tanh","trunc","saturate","atan2","clamp","max","min","mix","pow","reflect","refract","smoothstep","step"],O=(e,t)=>e===t,Ve=(e,t)=>Q.some(([n,r,s])=>n===e&&r===t||n===t&&r===e),te=(e,t,n)=>K.includes(n)||Z.includes(n)?O(e,t):O(e,t)?!0:Ve(e,t),ne=(e,t,n)=>{if(K.includes(n)||Z.includes(n))return"bool";if(O(e,t))return e;let r=Q.find(([s,o,a])=>s===e&&o===t||s===t&&o===e);return r?r[2]:e};var c={arr:Array.isArray,bol:e=>typeof e=="boolean",str:e=>typeof e=="string",num:e=>typeof e=="number",int:e=>Number.isInteger(e),fun:e=>typeof e=="function",und:e=>typeof e>"u",nul:e=>e===null,set:e=>e instanceof Set,map:e=>e instanceof Map,obj:e=>!!e&&e.constructor.name==="Object",nan:e=>typeof e=="number"&&Number.isNaN(e)};var A=e=>e instanceof Float32Array;var Be=e=>[1,2,3,4,9,16].includes(e),ze=(e,t=3)=>e%t===0?Math.floor(e/t):-1,re=(e,t=1,n=console.warn,r="")=>{let s=ze(e,t);return Be(s)||n(`glre attribute error: Invalid attribute length ${e}, ${r?`${r} `:" "}must divide by vertex count (${t}) with valid stride (1,2,3,4,9,16)`),s};var mt=`
|
|
2
2
|
struct In { @builtin(vertex_index) vertex_index: u32 }
|
|
3
3
|
struct Out { @builtin(position) position: vec4f }
|
|
4
4
|
@vertex
|
|
@@ -9,26 +9,26 @@ fn main(in: In) -> Out {
|
|
|
9
9
|
out.position = vec4f(x, y, 0.0, 1.0);
|
|
10
10
|
return out;
|
|
11
11
|
}
|
|
12
|
-
`.trim();var
|
|
12
|
+
`.trim();var Y=(e=1024)=>{if(c.num(e)){let s=Math.sqrt(e),o=Math.ceil(s);return Number.isInteger(s)||console.warn(`GLRE Storage Warning: particleCount (${e}) is not a square. Using ${o}x${o} texture may waste GPU memory. Consider using [width, height] format for optimal storage.`),{x:o,y:o}}let[t,n,r]=e;if(r!==void 0){let s=n*r;return console.warn(`GLRE Storage Warning: 3D particleCount [${t}, ${n}, ${r}] specified but WebGL storage textures only support 2D. Flattening to 2D by multiplying height=${n} * depth=${r} = ${s}.`),{x:t,y:s}}return{x:t,y:n}};var oe=e=>c.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),se=e=>q.includes(e),ie=e=>ee.includes(e),ae=e=>c.obj(e)?!1:e instanceof Element,ue=e=>G.includes(e),S=e=>!e||typeof e!="object"?!1:e.isProxy,V=e=>c.str(e)?P.includes(e):!1,pe=e=>{let t=(e>>16&255)/255,n=(e>>8&255)/255,r=(e&255)/255;return[t,n,r]},He=0,v=()=>`x${He++}`,fe=(e,t)=>{if(t==="global_invocation_id")return`uvec3(uint(gl_FragCoord.y) * uint(${Y(e.gl?.particleCount).x}) + uint(gl_FragCoord.x), 0u, 0u)`;let n=J[t];if(!n)throw new Error(`Error: unknown builtin variable ${t}`);return n},C=(e,t)=>c.str(e)?t?.isWebGL?e:D[e]||e:"",B=e=>w[e]||e,le=e=>{let t=G.indexOf(e);return t!==-1?P[t]:"float"},ce=e=>(e.code||(e.code={headers:new Map,fragInputs:new Map,vertInputs:new Map,vertOutputs:new Map,vertVaryings:new Map,computeInputs:new Map,dependencies:new Map,structStructFields:new Map},e.isWebGL)||(e.code.fragInputs.set("position","@builtin(position) position: vec4f"),e.code.vertOutputs.set("position","@builtin(position) position: vec4f")),e),de=e=>c.num(e)||c.str(e)&&/^\d+$/.test(e),U=(e,t="",n)=>{e.code?.dependencies?.has(t)||e.code.dependencies.set(t,new Set),V(n)||e.code.dependencies.get(t).add(n)},ke=(e,t,n)=>e.isWebGL?n==="attribute"?e.gl?.attribute?.bind(null,t):n==="instance"?e.gl?.instance?.bind(null,t):n==="texture"?e.gl?.texture?.bind(null,t):n==="storage"?e.gl?.storage?.bind(null,t):r=>e.gl?.uniform?.(t,r):n==="attribute"?e.gl?._attribute?.bind(null,t):n==="instance"?e.gl?._instance?.bind(null,t):n==="texture"?e.gl?._texture?.bind(null,t):n==="storage"?e.gl?._storage?.bind(null,t):r=>e.gl?._uniform?.(t,r),qe=(e,t)=>{if(c.und(e))return;if(!S(e))return t(e);if(e.type!=="conversion")return;let n=e.props.children?.slice(1);if(!c.und(n?.[0])){if(c.arr(n[0])||A(n[0]))return t(n[0]);t(n.map(r=>r??n[0]))}},N=(e,t,n,r,s)=>{let o=ke(e,t,n);if(o)return qe(s,o),r.listeners.add(o),o};var je=e=>j[e],Ke=(e,t,n)=>(te(e,t,n)||console.warn(`GLRE Type Warning: Invalid operator '${n}' between types '${e}' and '${t}'`),ne(e,t,n)),Ze=e=>c.bol(e)?"bool":c.str(e)?"texture":c.num(e)?"float":c.arr(e)||A(e)?W[e.length]:ae(e)?"texture":"void",z=(e,t=console.warn,n="")=>{let r=W[e];return r||console.warn(`glre node system error: Cannot infer ${n?`${n} `:""} type from array length ${e}. Check your data size. Supported: 1(float), 2(vec2), 3(vec3), 4(vec4), 9(mat3), 16(mat4)`),r},xe=(e,t)=>{if(e.length===0)return"void";let[n]=e;return c.str(n)?n:g(n,t)},Qe=e=>M[e],Je=(e,t)=>{let{type:n,props:r}=e,{id:s,children:o=[],inferFrom:a,layout:l}=r,[i,u,m]=o;if(n==="conversion")return i;if(n==="operator")return Ke(g(u,t),g(m,t),i);if(n==="builtin")return je(s);if(n==="function")return Qe(i)||g(u,t);if(n==="define")return V(l?.type)?l?.type:!a||a.length===0?"void":xe(a,t);if((n==="attribute"||n==="instance")&&c.arr(i)){let h=n==="instance"?t.gl?.instanceCount:t.gl?.count,$=re(i.length,h,t.gl?.error,s);return z($,t.gl?.error,s)}if(n==="member"){if(oe(u))return z(u.length,t.gl?.error,s);if(S(i)){let h=g(i,t),$=t.code?.structStructFields?.get(h);if($&&$[u])return g($[u],t)}return"float"}return a?xe(a,t):i?g(i,t):"void"},g=(e,t)=>{if(t||(t={}),!S(e))return Ze(e);if(c.arr(e))return z(e.length,t.gl?.error,e.props.id);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let n=Je(e,t);return t.infers.set(e,n),n};var y=(e,t)=>e.filter(n=>!c.und(n)&&!c.nul(n)).map(n=>p(n,t)).join(", "),Te=(e,t,n,r)=>{let s=()=>{let u=g(r,e);if(u==="float")return".x";if(u==="vec2")return".xy";if(u==="vec3")return".xyz";if(u==="vec4")return"";throw new Error(`Unsupported storage scatter type: ${u}`)},o=p(n,e),a=Y(e.gl?.particleCount),l=`int(${o}) % ${a.x}`,i=`int(${o}) / ${a.x}`;return`texelFetch(${p(t,e)}, ivec2(${l}, ${i}), 0)${s()}`},me=(e,t,n)=>{let r=p(t,e),s=p(n,e),o=g(n,e);if(o==="float")return`_${r} = vec4(${s}, 0.0, 0.0, 1.0);`;if(o==="vec2")return`_${r} = vec4(${s}, 0.0, 1.0);`;if(o==="vec3")return`_${r} = vec4(${s}, 1.0);`;if(o==="vec4")return`_${r} = ${s};`;throw new Error(`Unsupported storage scatter type: ${o}`)},ge=(e,t,n,r)=>{if(e.isWebGL)return`texture(${y(r?[t,n,r]:[t,n],e)})`;let s=p(t,e),o=[s,s+"Sampler",p(n,e)];return r?(o.push(p(r,e)),`textureSampleLevel(${o})`):`textureSample(${o})`},ve=(e,t,n,r)=>{let s=`if (${p(t,e)}) {
|
|
13
13
|
${p(n,e)}
|
|
14
14
|
}`;for(let o=2;o<r.length;o+=2){let a=o>=r.length-1;s+=a?` else {
|
|
15
15
|
${p(r[o],e)}
|
|
16
16
|
}`:` else if (${p(r[o],e)}) {
|
|
17
17
|
${p(r[o+1],e)}
|
|
18
|
-
}`}return s},
|
|
18
|
+
}`}return s},be=(e,t,n)=>{let r=`switch (${p(t,e)}) {
|
|
19
19
|
`;for(let s=1;s<n.length;s+=2)s>=n.length-1&&n.length%2===0?r+=`default:
|
|
20
20
|
${p(n[s],e)}
|
|
21
21
|
break;
|
|
22
22
|
`:s+1<n.length&&(r+=`case ${p(n[s],e)}:
|
|
23
23
|
${p(n[s+1],e)}
|
|
24
24
|
break;
|
|
25
|
-
`);return r+="}",r}
|
|
25
|
+
`);return r+="}",r},$e=(e,t,n)=>{let r=g(t,e),s=n?.props?.id;if(e.isWebGL)return`${r} ${s} = ${p(t,e)};`;let o=C(r);return`var ${s}: ${o} = ${p(t,e)};`},he=(e,t,n={})=>{e.code?.structStructFields?.set(t,n);let r=[];for(let o in n){let a=n[o],l=g(a,e);e.isWebGL&&U(e,t,l),r.push(e.isWebGL?`${l} ${o};`:`${o}: ${C(l,e)},`)}let s=r.join(`
|
|
26
26
|
`);return`struct ${t} {
|
|
27
27
|
${s}
|
|
28
|
-
};`},
|
|
29
|
-
`)},
|
|
30
|
-
@group(${
|
|
31
|
-
layout(location = ${
|
|
28
|
+
};`},Ce=(e,t,n="",r)=>{let s=e.code?.structStructFields?.get(t)||{};if(e.isWebGL)if(r){let o=[];for(let a in s)o.push(r[a]);return`${t} ${n} = ${t}(${y(o,e)});`}else return`${t} ${n};`;else if(r){let o=[];for(let a in s)o.push(r[a]);return`var ${n}: ${t} = ${t}(${y(o,e)});`}else return`var ${n}: ${t};`},Ee=(e,t,n)=>{let{id:r,children:s=[],layout:o}=t,[a,...l]=s,i=[],u=[];for(let x=0;x<l.length;x++){let E=o?.inputs?.[x];E?i.push([E.name,E.type==="auto"?g(l[x],e):E.type]):i.push([`p${x}`,g(l[x],e)])}let m=p(a,e),h=g(n,e),$=[];if(e?.isWebGL){for(let[x,E]of i)U(e,r,E),u.push(`${E} ${x}`);U(e,r,h),$.push(`${h} ${r}(${u}) {`)}else{for(let[E,Me]of i)u.push(`${E}: ${C(Me,e)}`);h==="void"?$.push(`fn ${r}(${u}) {`):$.push(`fn ${r}(${u}) -> ${C(h,e)} {`)}return m&&$.push(m),$.push("}"),$.join(`
|
|
29
|
+
`)},_e=(e,t,n)=>e.isWebGL?`${n} ${t};`:`@location(${e.code?.vertVaryings?.size||0}) ${t}: ${C(n,e)}`,ye=(e,t,n)=>{if(e.isWebGL)return`${n} ${t};`;let{location:r=0}=e.gl?.binding?.attrib(t)||{},s=C(n,e);return`@location(${r}) ${t}: ${s}`},Xe=(e,t,n)=>{let r=n==="sampler2D"||n==="texture";if(e.isWebGL)return r?`uniform sampler2D ${t};`:`uniform ${n} ${t};`;if(r){let{group:l=1,binding:i=0}=e.gl?.binding?.texture(t)||{};return`@group(${l}) @binding(${i}) var ${t}Sampler: sampler;
|
|
30
|
+
@group(${l}) @binding(${i+1}) var ${t}: texture_2d<f32>;`}let{group:s=0,binding:o=0}=e.gl?.binding?.uniform(t)||{},a=C(n,e);return`@group(${s}) @binding(${o}) var<uniform> ${t}: ${a};`},Se=(e,t,n)=>{if(e.isWebGL){let a=`uniform sampler2D ${t};`;if(e.label!=="compute")return a;let l=e.units?.(t);return`${a}
|
|
31
|
+
layout(location = ${l}) out vec4 _${t};`}let{group:r=0,binding:s=0}=e.gl?.binding?.storage(t)||{},o=C(n,e);return`@group(${r}) @binding(${s}) var<storage, read_write> ${t}: array<${o}>;`},Re=(e,t,n,r)=>{let s=g(t,e),o=p(n,e),a=p(t,e);return e.isWebGL?s==="int"?`for (int ${r} = 0; ${r} < ${a}; ${r} += 1) {
|
|
32
32
|
${o}
|
|
33
33
|
}`:s==="float"?`for (float ${r} = 0.0; ${r} < ${a}; ${r} += 1.0) {
|
|
34
34
|
${o}
|
|
@@ -48,18 +48,18 @@ ${o}
|
|
|
48
48
|
${o}
|
|
49
49
|
}`:`for (var ${r}: i32 = 0; ${r} < ${a}; ${r}++) {
|
|
50
50
|
${o}
|
|
51
|
-
}`},
|
|
52
|
-
`);if(n==="assign")return`${p(i,t)} = ${p(u,t)};`;if(n==="return")return`return ${p(i,t)};`;if(n==="break")return"break;";if(n==="continue")return"continue;";if(n==="loop")return
|
|
51
|
+
}`},Le=(e,t,n,r)=>e.isWebGL?`const ${n} ${t} = ${r};`:`const ${t}: ${C(n,e)} = ${r};`;var p=(e,t)=>{if(t||(t={}),ce(t),c.arr(e))return y(e,t);if(c.str(e))return e;if(c.num(e)){let x=`${e}`;return x.includes(".")?x:x+".0"}if(c.bol(e))return e?"true":"false";if(!e||!S(e))return"";let{type:n,props:r={}}=e,{id:s="i",children:o=[],fields:a,initialValues:l}=r,[i,u,m,h]=o;if(n==="variable")return s;if(n==="member")return`${p(i,t)}.${p(u,t)}`;if(n==="element")return`${p(i,t)}[${p(u,t)}]`;if(n==="gather")return t.isWebGL?Te(t,i,u,e):`${p(i,t)}[${p(u,t)}]`;if(n==="scatter"){let[x,E]=i.props.children??[];return t.isWebGL?me(t,x,u):`${p(x,t)}[${p(E,t)}] = ${p(u,t)};`}if(n==="ternary")return t.isWebGL?`(${p(m,t)} ? ${p(i,t)} : ${p(u,t)})`:`select(${p(i,t)}, ${p(u,t)}, ${p(m,t)})`;if(n==="conversion")return`${C(i,t)}(${y(o.slice(1),t)})`;if(n==="operator")return i==="not"||i==="bitNot"?`!${p(u,t)}`:i==="mod"?p(Fe(u,m),t):i.endsWith("Assign")?`${p(u,t)} ${B(i)} ${p(m,t)};`:`(${p(u,t)} ${B(i)} ${p(m,t)})`;if(n==="function"){if(i==="negate")return`(-${p(u,t)})`;if(i==="reciprocal")return`(1.0 / ${p(u,t)})`;if(i==="oneMinus")return`(1.0-${p(u,t)})`;if(i==="saturate")return`clamp(${p(u,t)}, 0.0, 1.0)`;if(i==="texture")return ge(t,u,m,h);if(i==="atan2"&&t.isWebGL)return`atan(${p(u,t)}, ${p(m,t)})`;if(!t.isWebGL){if(i==="dFdx")return`dpdx(${p(u,t)})`;if(i==="dFdy")return`dpdy(${p(u,t)})`}return`${i}(${y(o.slice(1),t)})`}if(n==="scope")return o.map(x=>p(x,t)).join(`
|
|
52
|
+
`);if(n==="assign")return`${p(i,t)} = ${p(u,t)};`;if(n==="return")return`return ${p(i,t)};`;if(n==="break")return"break;";if(n==="continue")return"continue;";if(n==="loop")return Re(t,i,u,s);if(n==="if")return ve(t,i,u,o);if(n==="switch")return be(t,i,o);if(n==="declare")return $e(t,i,u);if(n==="define")return t.code?.headers.has(s)||t.code?.headers.set(s,Ee(t,r,e)),`${s}(${y(o.slice(1),t)})`;if(n==="struct")return t.code?.headers.has(s)||t.code?.headers.set(s,he(t,s,a)),Ce(t,s,i.props.id,l);if(n==="varying"){if(t.code?.vertOutputs.has(s))return t.isWebGL?`${s}`:`out.${s}`;let x=_e(t,s,g(e,t));return t.code?.fragInputs.set(s,x),t.code?.vertOutputs.set(s,x),t.code?.vertVaryings.set(s,{node:i}),t.isWebGL?`${s}`:`out.${s}`}if(n==="builtin"){if(t.isWebGL)return fe(t,s);if(s==="position")return"out.position";let x=`@builtin(${s}) ${s}: ${C(g(e,t),t)}`;return t.label==="compute"?t.code?.computeInputs.set(s,x):t.label==="frag"?t.code?.fragInputs.set(s,x):t.label==="vert"&&t.code?.vertInputs.set(s,x),`in.${s}`}if(n==="attribute"||n==="instance")return N(t,s,n,e,i),t.code?.vertInputs.set(s,ye(t,s,g(e,t))),t.isWebGL?`${s}`:`in.${s}`;if(t.code?.headers.has(s))return s;let $="";if(n==="uniform"){let x=g(e,t);N(t,s,x,e,i),$=Xe(t,s,x)}return n==="storage"&&(N(t,s,n,e,i),$=Se(t,s,g(e,t))),n==="constant"&&($=Le(t,s,g(e,t),p(i,t))),$?(t.code?.headers.set(s,$),s):p(i,t)};var et=(e,t)=>{let n=[],r=new Set,s=new Set,o=a=>{if(s.has(a)||r.has(a))return;s.add(a);let l=t.get(a)||new Set;for(let i of l)e.has(i)&&o(i);s.delete(a),r.add(a),e.has(a)&&n.push([a,e.get(a)])};for(let[a]of e)o(a);return n},H=(e,t)=>{let n=p(e,t),r="";t.isWebGL&&t.code?.dependencies?r=et(t.code.headers,t.code.dependencies).map(([,l])=>l).join(`
|
|
53
53
|
`):r=Array.from(t.code?.headers?.values()||[]).join(`
|
|
54
|
-
`);let[s,o]=n.split("return ");return o?o=o.replace(";",""):[s,o]=["",n],[r,s.trim(),o]},
|
|
54
|
+
`);let[s,o]=n.split("return ");return o?o=o.replace(";",""):[s,o]=["",n],[r,s.trim(),o]},I=(e,t)=>`struct ${e} {
|
|
55
55
|
${Array.from(t.values()).join(`,
|
|
56
56
|
`)}
|
|
57
|
-
}`,
|
|
57
|
+
}`,tt=["float","int","sampler2D","samplerCube","sampler3D","sampler2DArray","sampler2DShadow","samplerCubeShadow","sampler2DArrayShadow","isampler2D","isampler3D","isamplerCube","isampler2DArray","usampler2D","usampler3D","usamplerCube","usampler2DArray"],Ae=(e,t="highp")=>{for(let n of tt)e.push(`precision ${t} ${n};`)},nt=(e,t="highp")=>{if(!e)return"highp";if(t==="highp"){let n=e.getShaderPrecisionFormat(e.VERTEX_SHADER,e.HIGH_FLOAT),r=e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT);if(n&&n.precision>0&&r&&r.precision>0)return"highp";t="mediump"}if(t==="mediump"){let n=e.getShaderPrecisionFormat(e.VERTEX_SHADER,e.MEDIUM_FLOAT),r=e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT);if(n&&n.precision>0&&r&&r.precision>0)return"mediump"}return"lowp"},Ye=(e,t={})=>{t.code?.headers?.clear(),t.label="frag";let[n,r,s]=H(e,t),o=[];if(t.isWebGL){o.push("#version 300 es"),Ae(o,nt(t.gl?.gl,t.gl?.precision)),o.push("out vec4 fragColor;");for(let l of t.code?.fragInputs?.values()||[])o.push(`in ${l}`);o.push(n),o.push("void main() {"),o.push(` ${r}`),o.push(` fragColor = ${s};`)}else t.code?.fragInputs?.size&&o.push(I("Out",t.code.fragInputs)),o.push(n),o.push(`@fragment
|
|
58
58
|
fn main(out: Out) -> @location(0) vec4f {`),o.push(` ${r}`),o.push(` return ${s};`);o.push("}");let a=o.filter(Boolean).join(`
|
|
59
59
|
`).trim();return t.gl?.isDebug&&console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
60
|
-
${a}`),a},
|
|
60
|
+
${a}`),a},Ue=(e,t={})=>{if(t.code?.headers?.clear(),t.label="vert",t.code)for(let[l,{node:i}]of t.code.vertVaryings.entries())t.code.vertVaryings.set(l,{node:i,code:p(i,t)});let[n,r,s]=H(e,t),o=[];if(t.isWebGL){o.push("#version 300 es");for(let l of t.code?.vertInputs?.values()||[])o.push(`in ${l}`);for(let l of t.code?.vertOutputs?.values()||[])o.push(`out ${l}`);if(o.push(n),o.push("void main() {"),o.push(` ${r}`),o.push(` gl_Position = ${s};`),t.code)for(let[l,i]of t.code.vertVaryings.entries())o.push(` ${l} = ${i.code};`)}else{if(t.code?.vertInputs?.size&&o.push(I("In",t.code.vertInputs)),t.code?.vertOutputs?.size&&o.push(I("Out",t.code.vertOutputs)),o.push(n),o.push("@vertex"),o.push(`fn main(${t.code?.vertInputs?.size?"in: In":""}) -> Out {`),o.push(" var out: Out;"),o.push(` ${r}`),o.push(` out.position = ${s};`),t.code)for(let[l,i]of t.code.vertVaryings.entries())o.push(` out.${l} = ${i.code};`);o.push(" return out;")}o.push("}");let a=o.filter(Boolean).join(`
|
|
61
61
|
`).trim();return t.gl?.isDebug&&console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
62
|
-
${a}`),a},
|
|
62
|
+
${a}`),a},Ne=(e,t={})=>{t.code?.headers?.clear(),t.label="compute";let[n,r,s]=H(e,t),o=[];t.isWebGL?(o.push("#version 300 es"),Ae(o,"highp"),o.push(n),o.push("void main() {"),o.push(` ${r}`),o.push(` ${s};`),o.push("}")):(t.code?.computeInputs?.size&&o.push(I("In",t.code.computeInputs)),o.push(n),o.push("@compute @workgroup_size(32)"),o.push(`fn main(${t.code?.computeInputs?.size?"in: In":""}) {`),o.push(` ${r}`),o.push(` ${s};`),o.push("}"));let a=o.filter(Boolean).join(`
|
|
63
63
|
`).trim();return t.gl?.isDebug&&console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
64
|
-
${a}`),a};var X=null,R=null,_=e=>{if(!X)return;if(X.props.children||(X.props.children=[]),X.props.children.push(e),e.type!=="return"||!R)return e;let{props:t}=R;return t.inferFrom||(t.inferFrom=[]),t.inferFrom.push(e),e};function
|
|
64
|
+
${a}`),a};var X=null,R=null,_=e=>{if(!X)return;if(X.props.children||(X.props.children=[]),X.props.children.push(e),e.type!=="return"||!R)return e;let{props:t}=R;return t.inferFrom||(t.inferFrom=[]),t.inferFrom.push(e),e};function Ie(e,t){t||(t=v());let n=d("variable",{id:t,inferFrom:[e]}),r=d("declare",null,e,n);return _(r),n}var Oe=(e,t=!1,n)=>{let r=d(t?"scatter":"assign",null,e,n);return _(r),e},rt=e=>_(d("return",{inferFrom:[e]},e)),zt=()=>_(d("break")),Ht=()=>_(d("continue")),kt=(e,t=v())=>(n={},r=v())=>{let s=d("variable",{id:r,inferFrom:[t]}),o=d("struct",{id:t,fields:e,initialValues:n},s);return _(o),s},Ge=(e,t,n=R)=>{let[r,s]=[X,R];[X,R]=[e,n];let o=t();o&&rt(o),[X,R]=[r,s]},L=e=>{let t=d("scope");return Ge(t,e),t},qt=(e,t)=>{let n=L(t),r=d("if",null,e,n);_(r);let s=()=>({ElseIf:(o,a)=>{let l=L(a);return r.props.children.push(o,l),s()},Else:o=>{let a=L(o);r.props.children.push(a)}});return s()},jt=(e,t)=>{let n=v(),r=L(()=>t({i:d("variable",{id:n,inferFrom:[T("int",0)]})})),s=d("loop",{id:n},e,r);return _(s)},Kt=e=>{let t=d("switch",null,e);_(t);let n=()=>({Case:(...r)=>s=>{let o=L(s);for(let a of r)t.props.children.push(a,o);return n()},Default:r=>{let s=L(r);t.props.children.push(s)}});return n()};function Zt(e,t){let n=v(),r=(...s)=>{let o=t?.name||n,a=[],l=[];for(let m=0;m<s.length;m++){let h=t?.inputs?.[m];h?l.push({id:h.name,inferFrom:h.type==="auto"?[s[m]]:[T(h.type,s[m])]}):l.push({id:`p${m}`,inferFrom:[s[m]]})}for(let m of l)a.push(d("variable",m));let i=d("scope"),u=d("define",{id:o,layout:t},i,...s);return Ge(i,()=>e(a),u),u};return r.getLayout=()=>t,r.setLayout=s=>(t=s,r),r}var ot=(e,t)=>{if(t==="string")return p(e,null)},d=(e,t,...n)=>{t||(t={}),n.length&&(t.children=n);let r=new Set,s=(l,i)=>{if(i==="type")return e;if(i==="props")return t;if(i==="toVar")return Ie.bind(null,a);if(i==="isProxy")return!0;if(i==="toString")return p.bind(null,a);if(i==="fragment")return Ye.bind(null,a);if(i==="compute")return Ne.bind(null,a);if(i==="vertex")return Ue.bind(null,a);if(i===Symbol.toPrimitive)return ot.bind(null,a);if(i==="listeners")return r;if(i==="attribute")return(u=v())=>st(a,u);if(i==="instance")return(u=v())=>it(a,u);if(i==="constant")return(u=v())=>at(a,u);if(i==="uniform")return(u=v())=>F(a,u);if(i==="variable")return(u=v())=>ut(u);if(i==="builtin")return(u=v())=>b(u);if(i==="vertexStage")return(u=v())=>pt(a,u);if(i==="element")return u=>e==="storage"?ft(a,u):De(a,u);if(i==="member")return u=>k(a,u);if(i==="assign")return Oe.bind(null,a,a.type==="gather");if(i==="select")return lt.bind(null,a);if(se(i))return i.endsWith("Assign")?(...u)=>_(Pe(i,a,...u)):(...u)=>Pe(i,a,...u);if(ie(i))return(...u)=>f(i,a,...u);if(ue(i))return()=>T(le(i),a);if(c.str(i))return de(i)?De(a,i):k(a,i)},o=(l,i,u)=>(i==="value"&&r.forEach(m=>m(u)),c.str(i)&&k(a,i).assign(u),!0),a=new Proxy({},{get:s,set:o});return a},st=(e,t=v())=>d("attribute",{id:t},e),it=(e,t=v())=>d("instance",{id:t},e),at=(e,t=v())=>d("constant",{id:t},e),F=(e,t=v())=>d("uniform",{id:t},e),rn=(e,t=v())=>d("storage",{id:t},e),ut=(e=v())=>d("variable",{id:e}),b=(e=v())=>d("builtin",{id:e}),pt=(e,t=v())=>d("varying",{id:t,inferFrom:[e]},e),k=(e,t)=>d("member",null,e,t),De=(e,t)=>d("element",null,e,t),ft=(e,t)=>d("gather",null,e,t),on=(e,t)=>d("scatter",null,e,t),lt=(e,t,n)=>d("ternary",null,e,t,n),Pe=(e,...t)=>d("operator",null,e,...t),f=(e,...t)=>d("function",null,e,...t),T=(e,...t)=>d("conversion",null,e,...t);var ct=b("position"),fn=b("vertex_index"),ln=b("instance_index"),cn=b("front_facing"),dn=b("frag_depth"),xn=b("sample_index"),Tn=b("sample_mask"),mn=b("point_coord"),gn=b("global_invocation_id"),vn=b("position"),bn=b("positionWorld"),$n=b("positionView"),hn=b("normalLocal"),Cn=b("normalWorld"),En=b("normalView"),_n=b("screenCoordinate"),yn=b("screenUV"),dt=e=>T("float",e),Xn=e=>T("int",e),Sn=e=>T("uint",e),Rn=e=>T("bool",e),We=(e,t)=>T("vec2",e,t),we=(e,t,n)=>T("vec3",e,t,n),Ln=(e,t,n,r)=>T("vec4",e,t,n,r),Fn=(...e)=>T("mat2",...e),An=(...e)=>T("mat3",...e),Yn=(...e)=>T("mat4",...e),Un=(e,t)=>T("ivec2",e,t),Nn=(e,t,n)=>T("ivec3",e,t,n),In=(e,t,n,r)=>T("ivec4",e,t,n,r),On=(e,t)=>T("uvec2",e,t),Gn=(e,t,n)=>T("uvec3",e,t,n),Dn=(e,t,n,r)=>T("uvec4",e,t,n,r),Pn=(e,t)=>T("bvec2",e,t),wn=(e,t,n)=>T("bvec3",e,t,n),Wn=(e,t,n,r)=>T("bvec4",e,t,n,r),Mn=e=>T("texture",e),Vn=()=>T("sampler2D"),Bn=(e,t,n)=>c.num(e)&&c.und(t)&&c.und(n)?we(...pe(e)):we(e,t,n),xt=F(We(),"iResolution"),zn=F(We(),"iMouse"),Hn=F(dt(),"iTime"),kn=ct.xy.div(xt),qn=e=>f("all",e),jn=e=>f("any",e),Kn=e=>f("determinant",e),Zn=(e,t)=>f("distance",e,t),Qn=(e,t)=>f("dot",e,t),Jn=e=>f("length",e),er=e=>f("lengthSq",e),tr=e=>f("luminance",e),nr=(e,t)=>f("cross",e,t),rr=(e,t,n)=>f("cubeTexture",e,t,n),or=(e,t,n)=>f("texture",e,t,n),sr=(e,t,n)=>f("texelFetch",e,t,n),ir=(e,t,n)=>f("textureLod",e,t,n),ar=e=>f("abs",e),ur=e=>f("acos",e),pr=e=>f("acosh",e),fr=e=>f("asin",e),lr=e=>f("asinh",e),cr=e=>f("atan",e),dr=e=>f("atanh",e),xr=e=>f("ceil",e),Tr=e=>f("cos",e),mr=e=>f("cosh",e),gr=e=>f("dFdx",e),vr=e=>f("dFdy",e),br=e=>f("degrees",e),$r=e=>f("exp",e),hr=e=>f("exp2",e),Cr=e=>f("floor",e),Er=e=>f("fract",e),_r=e=>f("fwidth",e),yr=e=>f("inverseSqrt",e),Xr=e=>f("log",e),Sr=e=>f("log2",e),Rr=e=>f("negate",e),Lr=e=>f("normalize",e),Fr=e=>f("oneMinus",e),Ar=e=>f("radians",e),Yr=e=>f("reciprocal",e),Ur=e=>f("round",e),Nr=e=>f("sign",e),Ir=e=>f("sin",e),Or=e=>f("sinh",e),Gr=e=>f("sqrt",e),Dr=e=>f("tan",e),Pr=e=>f("tanh",e),wr=e=>f("trunc",e),Wr=(e,t)=>f("atan2",e,t),Mr=(e,t,n)=>f("clamp",e,t,n),Vr=(e,t)=>f("max",e,t),Br=(e,t)=>f("min",e,t),zr=(e,t,n)=>f("mix",e,t,n),Hr=(e,t)=>f("pow",e,t),kr=(e,t)=>f("reflect",e,t),qr=(e,t,n)=>f("refract",e,t,n),jr=(e,t,n)=>f("smoothstep",e,t,n),Kr=(e,t)=>f("step",e,t),Fe=(e,t)=>e.sub(e.div(t).floor().mul(t));export{zt as Break,Ht as Continue,Zt as Fn,qt as If,jt as Loop,rt as Return,L as Scope,Kt as Switch,ar as abs,ur as acos,pr as acosh,_ as addToScope,qn as all,jn as any,fr as asin,lr as asinh,Oe as assign,cr as atan,Wr as atan2,dr as atanh,st as attribute,Rn as bool,b as builtin,Pn as bvec2,wn as bvec3,Wn as bvec4,xr as ceil,Mr as clamp,Bn as color,Ne as compute,at as constant,T as conversion,Tr as cos,mr as cosh,d as create,nr as cross,rr as cubeTexture,gr as dFdx,vr as dFdy,br as degrees,Kn as determinant,Zn as distance,Qn as dot,De as element,$r as exp,hr as exp2,dt as float,Cr as floor,Er as fract,dn as fragDepth,Ye as fragment,cn as frontFacing,f as function_,_r as fwidth,ft as gather,zn as iMouse,xt as iResolution,Hn as iTime,gn as id,it as instance,ln as instanceIndex,Xn as int,yr as inverseSqrt,Un as ivec2,Nn as ivec3,In as ivec4,Jn as length,er as lengthSq,Xr as log,Sr as log2,tr as luminance,Fn as mat2,An as mat3,Yn as mat4,Vr as max,k as member,Br as min,zr as mix,Fe as mod,Rr as negate,hn as normalLocal,En as normalView,Cn as normalWorld,Lr as normalize,Fr as oneMinus,Pe as operator,mn as pointCoord,ct as position,vn as positionLocal,$n as positionView,bn as positionWorld,Hr as pow,Ar as radians,Yr as reciprocal,kr as reflect,qr as refract,Ur as round,xn as sampleIndex,Tn as sampleMask,Vn as sampler2D,on as scatter,Ge as scoped,_n as screenCoordinate,yn as screenUV,lt as select,Nr as sign,Ir as sin,Or as sinh,jr as smoothstep,Gr as sqrt,Kr as step,rn as storage,kt as struct,Dr as tan,Pr as tanh,sr as texelFetch,or as texture,Mn as texture2D,ir as textureLod,Ie as toVar,wr as trunc,Sn as uint,F as uniform,kn as uv,On as uvec2,Gn as uvec3,Dn as uvec4,ut as variable,We as vec2,we as vec3,Ln as vec4,Ue as vertex,fn as vertexIndex,pt as vertexStage};
|
|
65
65
|
//# sourceMappingURL=node.js.map
|