glre 0.33.0 → 0.34.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/dist/index.cjs +29 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1796 -236
- package/dist/index.js +28 -28
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +29 -29
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.ts +9 -9
- package/dist/native.js +28 -28
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +29 -29
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +28 -28
- package/dist/react.js.map +1 -1
- package/dist/solid.cjs +29 -29
- package/dist/solid.cjs.map +1 -1
- package/dist/solid.d.ts +1 -1
- package/dist/solid.js +28 -28
- package/dist/solid.js.map +1 -1
- package/package.json +1 -1
- package/src/node/code.ts +9 -7
- package/src/node/const.ts +57 -30
- package/src/node/index.ts +108 -96
- package/src/node/infer.ts +47 -64
- package/src/node/node.ts +19 -17
- package/src/node/parse.ts +5 -3
- package/src/node/scope.ts +23 -19
- package/src/node/types.ts +222 -98
- package/src/node/utils.ts +4 -4
- package/src/types.ts +7 -7
package/dist/native.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as reev from 'reev';
|
|
2
2
|
import * as refr_dist_types_687121c7 from 'refr/dist/types-687121c7';
|
|
3
|
-
import { GL,
|
|
4
|
-
export { AttribData, Attributes, BaseNodeProxy, Constants, Conversions, Fn, FnLayout, Functions, GLClearMode, GLDrawMode, GLDrawType, If, Loop, NodeContext, NodeProps, NodeTypes, Operators, PrecisionMode,
|
|
3
|
+
import { GL, Vec4, WebGPUState, WebGLState, Uniform, NodeProxy, Attribute } from './index.js';
|
|
4
|
+
export { AttribData, Attributes, BVec2, BVec3, BVec4, BaseNodeProxy, Bool, Color, Constants, ConstantsToType, Conversions, Float, Fn, FnLayout, Functions, GLClearMode, GLDrawMode, GLDrawType, IVec2, IVec3, IVec4, If, Int, Loop, Mat2, Mat3, Mat4, NodeContext, NodeProps, NodeTypes, Operators, PrecisionMode, Return, Sampler2D, Struct, Switch, Swizzles, Texture, TextureData, UInt, UVec2, UVec3, UVec4, UniformData, Uniforms, Vec2, Vec3, X, abs, acos, acosh, addDependency, all, any, asin, asinh, assign, atan, atan2, atanh, attribute, bitcast, bool, builtin, bvec2, bvec3, bvec4, cbrt, ceil, clamp, code, color, constant, conversion, conversionToConstant, cos, cosh, createAttrib, createAttribBuffer, createBindGroup, createBindings, createDepthTexture, createDescriptor, createDevice, default as createGL, createIbo, createPipeline, createProgram, createTexture, createTextureSampler, createUniformBuffer, createVbo, createVertexBuffers, cross, cubeTexture, dFdx, dFdy, degrees, difference, dig, distance, dot, each, equals, exp, exp2, ext, faceforward, fig, float, floor, flush, formatConversions, fract, fragDepth, fragment, frontFacing, function_, fwidth, getBluiltin, getEventFun, getId, getOperator, getStride, hex2rgb, iMouse, iResolution, iTime, initNodeContext, instanceIndex, int, inverseSqrt, is, isConstants, isConversion, isFunction, isGL, isNodeProxy, isOperator, isServer, isSwizzle, isWebGPUSupported, ivec2, ivec3, ivec4, length, lengthSq, log, log2, mat2, mat3, mat4, max, member, min, mix, negate, node, normalLocal, normalView, normalWorld, normalize, oneMinus, operator, pointCoord, position, positionLocal, positionView, positionWorld, pow, pow2, pow3, pow4, radians, reciprocal, reflect, refract, replace, round, safeEventCall, sampleIndex, sampleMask, sampler2D, saturate, screenCoordinate, screenUV, select, sig, sign, sin, sinh, smoothstep, sortHeadersByDependencies, sqrt, step, struct, tan, tanh, texture, texture2D, textureSize, toVar, transformDirection, trunc, uint, uniform, uv, uvec2, uvec3, uvec4, variable, vec2, vec3, vec4, vertex, vertexIndex, vertexStage, webgl, webgpu } from './index.js';
|
|
5
5
|
export { Frame, Fun, Queue } from 'refr';
|
|
6
6
|
|
|
7
7
|
declare const useGL: (props?: Partial<GL>) => reev.EventState<{
|
|
@@ -15,12 +15,12 @@ declare const useGL: (props?: Partial<GL>) => reev.EventState<{
|
|
|
15
15
|
mouse: [number, number];
|
|
16
16
|
count: number;
|
|
17
17
|
el: HTMLCanvasElement;
|
|
18
|
-
vs: string |
|
|
19
|
-
fs: string |
|
|
20
|
-
vert: string |
|
|
21
|
-
frag: string |
|
|
22
|
-
vertex: string |
|
|
23
|
-
fragment: string |
|
|
18
|
+
vs: string | Vec4;
|
|
19
|
+
fs: string | Vec4;
|
|
20
|
+
vert: string | Vec4;
|
|
21
|
+
frag: string | Vec4;
|
|
22
|
+
vertex: string | Vec4;
|
|
23
|
+
fragment: string | Vec4;
|
|
24
24
|
webgpu: WebGPUState;
|
|
25
25
|
webgl: WebGLState;
|
|
26
26
|
queue: refr_dist_types_687121c7.Q;
|
|
@@ -51,4 +51,4 @@ declare const useGL: (props?: Partial<GL>) => reev.EventState<{
|
|
|
51
51
|
}): GL;
|
|
52
52
|
}, any[] | unknown[]>;
|
|
53
53
|
|
|
54
|
-
export { Attribute, GL, NodeProxy, Uniform, WebGLState, WebGPUState, useGL };
|
|
54
|
+
export { Attribute, GL, NodeProxy, Uniform, Vec4, WebGLState, WebGPUState, useGL };
|
package/dist/native.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import{useState as
|
|
1
|
+
import{useState as It}from"react";import{durable as de,event as $t}from"reev";import{createFrame as Gt,createQueue as Lt}from"refr";import{nested as ce}from"reev";var d={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)},gt=(e,t)=>e.forEach(t),Ut=(e,...t)=>{gt(e,r=>r(...t))},At=(e="",t="_",r="/")=>e.split(t).join(r),Bt=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",Dt=(e=0)=>`${e}`.split(".")[1]?.length??0,Mt=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),Wt=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var K={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"},Z=Object.keys(K),Q=["toBool","toUint","toInt","toFloat","toBvec2","toIvec2","toUvec2","toVec2","toBvec3","toIvec3","toUvec3","toVec3","toBvec4","toIvec4","toUvec4","toVec4","toColor","toMat2","toMat3","toMat4"],J={add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>"},xe=Object.keys(J),me=["dot","distance","length","lengthSq","determinant","luminance","all","any","abs","sign","floor","ceil","round","fract","trunc","sin","cos","tan","asin","acos","atan","sinh","cosh","tanh","asinh","acosh","atanh","exp","exp2","log","log2","sqrt","inverseSqrt","normalize","oneMinus","saturate","negate","reciprocal","dFdx","dFdy","fwidth","degrees","radians","cross","reflect","refract","min","max","mix","clamp","step","smoothstep","pow","atan2","texture","textureLod","textureSize","cubeTexture","faceforward","bitcast","cbrt","difference","equals","pow2","pow3","pow4","transformDirection"],ee={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},Te={texture:"vec4",cubeTexture:"vec4",textureSize:"vec4",length:"float",lengthSq:"float",distance:"float",dot:"float",all:"bool",any:"bool",cross:"vec3"},ge={position:"vec4",vertex_index:"uint",instance_index:"uint",front_facing:"bool",frag_depth:"float",sample_index:"uint",sample_mask:"uint",point_coord:"vec2",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"},be=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],ve=["and","or"],he={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"};var ye=e=>d.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),Ce=e=>xe.includes(e),Xe=e=>me.includes(e),_e=e=>Q.includes(e),W=e=>!e||typeof e!="object"?!1:e.isProxy,te=e=>d.str(e)?Z.includes(e):!1,Pe=e=>{let t=(e>>16&255)/255,r=(e>>8&255)/255,o=(e&255)/255;return[t,r,o]},bt=0,$=()=>`i${bt++}`,G=(e,t)=>d.str(e)?t?.isWebGL?e:K[e]||e:"",Ee=e=>J[e]||e,we=e=>he[e],Ne=e=>{let t=Q.indexOf(e);return t!==-1?Z[t]:"float"},re=(e,t,r=!1,o=!1)=>e.isWebGL?r?n=>e.gl?.attribute?.(t,n):o?n=>e.gl?.texture?.(t,n):n=>e.gl?.uniform?.(t,n):r?n=>e.gl?._attribute?.(t,n):o?n=>e.gl?._texture?.(t,n):n=>e.gl?._uniform?.(t,n),ne=(e,t)=>{if(!e)return;if(!W(e))return t(e);if(e.type!=="conversion")return;let r=e.props.children?.slice(1).filter(Boolean);r?.length&&t(r)},$e=e=>(e.code||(e.code={headers:new Map,fragInputs:new Map,vertInputs:new Map,vertOutputs:new Map,vertVaryings:new Map,dependencies:new Map},e.isWebGL||(e.code.fragInputs.set("position","@builtin(position) position: vec4f"),e.code.vertOutputs.set("position","@builtin(position) position: vec4f"))),e),V=(e,t="",r)=>{e.code?.dependencies?.has(t)||e.code.dependencies.set(t,new Set),te(r)||e.code.dependencies.get(t).add(r)},Ge=(e,t)=>{let r=[],o=new Set,n=new Set,s=i=>{if(n.has(i)||o.has(i))return;n.add(i);let p=t.get(i)||new Set;for(let a of p)e.has(a)&&s(a);n.delete(i),o.add(i),e.has(i)&&r.push([i,e.get(i)])};for(let[i]of e)s(i);return r};var vt=e=>ge[e],Le=(e,t,r)=>be.includes(r)||ve.includes(r)?"bool":e===t?e:e==="float"||e==="int"?t:t==="float"||t==="int"?e:e==="mat4"&&t==="vec4"||e==="mat3"&&t==="vec3"||e==="mat2"&&t==="vec2"?t:e,ht=e=>d.bol(e)?"bool":d.str(e)?"texture":d.num(e)?"float":d.arr(e)?ee[e.length]:"float",oe=e=>ee[e],yt=(e,t)=>{if(e.length===0)return"void";let[r]=e;if(d.str(r))return r;let o=v(r,t);for(let n of e.slice(1))if(o!==v(n,t))throw new Error("glre node system error: defined scope return mismatch");return o},Ct=e=>Te[e],Xt=(e,t)=>{let{type:r,props:o}=e,{id:n,children:s=[],inferFrom:i,layout:p}=o,[a,c,l]=s;if(r==="conversion")return a;if(r==="operator")return Le(v(c,t),v(l,t),a);if(r==="ternary")return Le(v(c,t),v(l,t),"add");if(r==="builtin")return vt(n);if(r==="function")return Ct(a)||v(c,t);if(r==="define"&&te(p?.type))return p?.type;if(r==="attribute"&&d.arr(a)&&t.gl?.count)return oe(a.length/t.gl.count);if(r==="member"){if(ye(a))return oe(a.length);if(W(c)&&d.str(a)){let E=c.props.fields?.[a];if(E)return v(E,t)}return"float"}return i?yt(i,t):v(a,t)},v=(e,t)=>{if(t||(t={}),!W(e))return ht(e);if(d.arr(e))return oe(e.length);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=Xt(e,t);return t.infers.set(e,r),r};var R=(e,t)=>e.filter(r=>!d.und(r)&&!d.nul(r)).map(r=>f(r,t)).join(", "),Se=(e,t,r,o)=>{if(e.isWebGL)return`texture(${R(o?[t,r,o]:[t,r],e)})`;let n=f(t,e),s=[n,n+"Sampler",f(r,e)];return o?(s.push(f(o,e)),`textureSampleLevel(${s})`):`textureSample(${s})`},Re=(e,t,r,o)=>{let n=`if (${f(t,e)}) {
|
|
2
2
|
${f(r,e)}
|
|
3
|
-
}`;for(let s=2;s<
|
|
4
|
-
${f(
|
|
5
|
-
}`:` else if (${f(
|
|
6
|
-
${f(
|
|
7
|
-
}`}return
|
|
8
|
-
`;for(let
|
|
9
|
-
${f(r[
|
|
3
|
+
}`;for(let s=2;s<o.length;s+=2){let i=s>=o.length-1;n+=i?` else {
|
|
4
|
+
${f(o[s],e)}
|
|
5
|
+
}`:` else if (${f(o[s],e)}) {
|
|
6
|
+
${f(o[s+1],e)}
|
|
7
|
+
}`}return n},Oe=(e,t,r)=>{let o=`switch (${f(t,e)}) {
|
|
8
|
+
`;for(let n=1;n<r.length;n+=2)n>=r.length-1&&r.length%2===0?o+=`default:
|
|
9
|
+
${f(r[n],e)}
|
|
10
10
|
break;
|
|
11
|
-
`:
|
|
12
|
-
${f(r[
|
|
11
|
+
`:n+1<r.length&&(o+=`case ${f(r[n],e)}:
|
|
12
|
+
${f(r[n+1],e)}
|
|
13
13
|
break;
|
|
14
|
-
`);return
|
|
15
|
-
`)},
|
|
14
|
+
`);return o+="}",o},Fe=(e,t,r)=>{let o=v(t,e),n=r?.props?.id;if(e.isWebGL)return`${o} ${n} = ${f(t,e)};`;let s=G(o);return`var ${n}: ${s} = ${f(t,e)};`},Ie=(e,t,r)=>{let{id:o,children:n=[],layout:s}=t,[i,...p]=n,a=[],c=[];if(s?.inputs)for(let b of s.inputs)a.push([b.name,b.type]);else for(let b=0;b<p.length;b++)a.push([`p${b}`,v(p[b],e)]);let l=[];if(e?.isWebGL){for(let[b,m]of a)V(e,o,m),c.push(`${m} ${b}`);V(e,o,r),l.push(`${r} ${o}(${c}) {`)}else{for(let[b,m]of a)c.push(`${b}: ${G(m,e)}`);l.push(`fn ${o}(${c}) -> ${G(r,e)} {`)}let E=f(i,e);return E&&l.push(E),l.push("}"),l.join(`
|
|
15
|
+
`)},Ue=(e,t,r={})=>{let o=[];for(let s in r){let i=r[s],p=v(i,e);e.isWebGL&&V(e,t,p),o.push(e.isWebGL?`${p} ${s};`:`${s}: ${G(p,e)},`)}let n=o.join(`
|
|
16
16
|
`);return`struct ${t} {
|
|
17
|
-
${
|
|
18
|
-
};`},
|
|
19
|
-
@group(${
|
|
20
|
-
`);if(r==="assign")return`${f(a,t)} = ${f(
|
|
21
|
-
${f(
|
|
22
|
-
}`:`for (var i: i32 = 0; i < ${a}; i++) {
|
|
23
|
-
${f(
|
|
24
|
-
}`;if(r==="if")return
|
|
17
|
+
${n}
|
|
18
|
+
};`},Ae=(e,t,r="",o,n)=>{if(e.isWebGL)if(n){let s=[];for(let i in o)s.push(n[i]);return`${t} ${r} = ${t}(${R(s,e)});`}else return`${t} ${r};`;else if(n){let s=[];for(let i in o)s.push(n[i]);return`var ${r}: ${t} = ${t}(${R(s,e)});`}else return`var ${r}: ${t};`},Be=(e,t,r)=>e.isWebGL?`${r} ${t};`:`@location(${e.code?.vertVaryings?.size||0}) ${t}: ${G(r,e)}`,De=(e,t,r)=>{let o=r==="sampler2D"||r==="texture";if(e.isWebGL)return o?`uniform sampler2D ${t};`:`uniform ${r} ${t};`;if(o){let{group:p=1,binding:a=0}=e.gl?.webgpu?.textures.map.get(t)||{};return`@group(${p}) @binding(${a}) var ${t}Sampler: sampler;
|
|
19
|
+
@group(${p}) @binding(${a+1}) var ${t}: texture_2d<f32>;`}let{group:n=0,binding:s=0}=e.gl?.webgpu?.uniforms.map.get(t)||{},i=G(r,e);return`@group(${n}) @binding(${s}) var<uniform> ${t}: ${i};`},Me=(e,t,r)=>{if(e.isWebGL)return`${r} ${t};`;let{location:o=0}=e.gl?.webgpu?.attribs.map.get(t)||{},n=G(r,e);return`@location(${o}) ${t}: ${n}`},We=(e,t,r,o)=>e.isWebGL?`const ${r} ${t} = ${o};`:`const ${t}: ${G(r,e)} = ${o};`;var f=(e,t)=>{if(t||(t={}),$e(t),d.arr(e))return R(e,t);if(d.str(e))return e;if(d.num(e)){let m=`${e}`;return m.includes(".")?m:m+".0"}if(d.bol(e))return e?"true":"false";if(!e)return"";let{type:r,props:o}=e,{id:n="",children:s=[],fields:i,initialValues:p}=o,[a,c,l,E]=s;if(r==="variable")return n;if(r==="member")return`${f(c,t)}.${f(a,t)}`;if(r==="ternary")return t.isWebGL?`(${f(l,t)} ? ${f(a,t)} : ${f(c,t)})`:`select(${f(a,t)}, ${f(c,t)}, ${f(l,t)})`;if(r==="conversion")return`${G(a,t)}(${R(s.slice(1),t)})`;if(r==="operator")return a==="not"||a==="bitNot"?`!${f(c,t)}`:`(${f(c,t)} ${Ee(a)} ${f(l,t)})`;if(r==="function")return a==="negate"?`(-${R(s.slice(1),t)})`:a==="texture"?Se(t,c,l,E):`${a}(${R(s.slice(1),t)})`;if(r==="scope")return s.map(m=>f(m,t)).join(`
|
|
20
|
+
`);if(r==="assign")return`${f(a,t)} = ${f(c,t)};`;if(r==="return")return`return ${f(a,t)};`;if(r==="loop")return t.isWebGL?`for (int i = 0; i < ${f(a,t)}; i += 1) {
|
|
21
|
+
${f(c,t)}
|
|
22
|
+
}`:`for (var i: i32 = 0; i < ${f(a,t)}; i++) {
|
|
23
|
+
${f(c,t)}
|
|
24
|
+
}`;if(r==="if")return Re(t,a,c,s);if(r==="switch")return Oe(t,a,s);if(r==="declare")return Fe(t,a,c);if(r==="define")return t.code?.headers.has(n)||t.code?.headers.set(n,Ie(t,o,v(e,t))),`${n}(${R(s.slice(1),t)})`;if(r==="struct")return t.code?.headers.has(n)||t.code?.headers.set(n,Ue(t,n,i)),Ae(t,n,a.props.id,i,p);if(r==="varying"){if(t.code?.vertOutputs.has(n))return t.isWebGL?`${n}`:`out.${n}`;let m=Be(t,n,v(e,t));return t.code?.fragInputs.set(n,m),t.code?.vertOutputs.set(n,m),t.code?.vertVaryings.set(n,f(a,t)),t.isWebGL?`${n}`:`out.${n}`}if(r==="builtin"){if(t.isWebGL)return we(n);if(n==="position")return"out.position";let m=`@builtin(${n}) ${n}: ${G(v(e,t),t)}`;return t.isFrag?t.code?.fragInputs.set(n,m):t.code?.vertInputs.set(n,m),`in.${n}`}if(r==="attribute"){let m=re(t,n,!0);return ne(a,m),e.listeners.add(m),t.code?.vertInputs.set(n,Me(t,n,v(e,t))),t.isWebGL?`${n}`:`in.${n}`}if(t.code?.headers.has(n))return n;let b="";if(r==="uniform"){let m=v(e,t),A=re(t,n,!1,m==="texture");ne(a,A),e.listeners.add(A),b=De(t,n,m)}return r==="constant"&&(b=We(t,n,v(e,t),f(a,t))),b?(t.code?.headers.set(n,b),n):f(a,t)};var O=null,U=null,I=e=>{if(!O||(O.props.children||(O.props.children=[]),O.props.children.push(e),e.type!=="return"||!U))return;let{props:t}=U;t.inferFrom||(t.inferFrom=[]),t.inferFrom.push(e)},Ve=(e,t)=>{t||(t=$());let r=x("variable",{id:t,inferFrom:[e]}),o=x("declare",null,e,r);return I(o),r},ze=(e,t)=>{let r=x("assign",null,e,t);return I(r),e},_t=e=>{let t=x("return",{inferFrom:[e]},e);return I(t),t},cr=(e,t=$())=>(r={},o=$())=>{let n=x("variable",{id:o,inferFrom:[t]}),s=x("struct",{id:t,fields:e,initialValues:r},n);return I(s),n},F=(e,t,r=U)=>{let o=O,n=U;O=e,U=r,o&&(e.props.parent=o);let s=t();s&&_t(s),O=o,U=n},fr=(e,t)=>{let r=x("scope");F(r,t);let o=x("if",null,e,r);I(o);let n=()=>({ElseIf:(s,i)=>{let p=x("scope");return F(p,i),o.props.children.push(s,p),n()},Else:s=>{let i=x("scope");F(i,s),o.props.children.push(i)}});return n()},dr=(e,t)=>{let r=x("scope");F(r,()=>t({i:x("variable",{id:"i",inferFrom:[T("int",0)]})}));let o=x("loop",null,e,r);return I(o),o},lr=e=>{let t=x("switch",null,e);I(t);let r=()=>({Case:(...o)=>n=>{let s=x("scope");F(s,n);for(let i of o)t.props.children.push(i,s);return r()},Default:o=>{let n=x("scope");F(n,o),t.props.children.push(n)}});return r()},xr=(e,t=$())=>{let r,o=(...n)=>{let s=r?.name||t,i=x("scope"),p=[],a=[];if(r?.inputs)for(let l of r.inputs)a.push({id:l.name,inferFrom:[T(l.type)]});else for(let l=0;l<n.length;l++)a.push({id:`p${l}`,inferFrom:[n[l]]});for(let l of a)p.push(x("variable",l));let c=x("define",{id:s,layout:r},i,...n);return F(i,()=>e(p),c),c};return o.setLayout=n=>(r=n,o),o};var Pt=(e,t)=>{if(t==="string")return f(e)},x=(e,t,...r)=>{t||(t={}),r.length&&(t.children=r);let o=new Set,n=(p,a)=>{if(a==="type")return e;if(a==="props")return t;if(a==="toVar")return Ve.bind(null,i);if(a==="assign")return ze.bind(null,i);if(a==="isProxy")return!0;if(a==="toString")return f.bind(null,i);if(a===Symbol.toPrimitive)return Pt.bind(null,i);if(a==="listeners")return o;if(Ce(a))return(...c)=>Et(a,i,...c);if(Xe(a))return(...c)=>u(a,i,...c);if(_e(a))return()=>T(Ne(a),i);if(d.str(a))return ke(a,i)},s=(p,a,c)=>(a==="value"&&o.forEach(l=>l(c)),d.str(a)&&ke(a,i).assign(c),!0),i=new Proxy({},{get:n,set:s});return i},hr=(e,t=$())=>x("attribute",{id:t},e),yr=(e,t=$())=>x("constant",{id:t},e),z=(e,t=$())=>x("uniform",{id:t},e),Cr=(e=$())=>x("variable",{id:e}),C=(e=$())=>x("builtin",{id:e}),Xr=(e,t=$())=>x("varying",{id:t,inferFrom:[e]},e),ke=(e,t)=>x("member",null,e,t),_r=(e,t,r)=>x("ternary",null,e,t,r),Et=(e,...t)=>x("operator",null,e,...t),u=(e,...t)=>x("function",null,e,...t),T=(e,...t)=>x("conversion",null,e,...t);var wt=`
|
|
25
25
|
#version 300 es
|
|
26
26
|
precision mediump float;
|
|
27
27
|
out vec4 fragColor;
|
|
28
|
-
`.trim(),
|
|
29
|
-
`):
|
|
30
|
-
`),[
|
|
28
|
+
`.trim(),Ye=(e,t)=>{let r=f(e,t),o="";return t.isWebGL&&t.code?.dependencies?o=Ge(t.code.headers,t.code.dependencies).map(([,s])=>s).join(`
|
|
29
|
+
`):o=Array.from(t.code?.headers?.values()||[]).join(`
|
|
30
|
+
`),[o,r]},se=(e,t)=>`struct ${e} {
|
|
31
31
|
${Array.from(t.values()).join(`,
|
|
32
32
|
`)}
|
|
33
|
-
}`,
|
|
33
|
+
}`,k=(e,t)=>{if(d.str(e))return e.trim();t.code?.headers?.clear(),t.isFrag=!1;let[r,o]=Ye(e,t),n=[];if(t.isWebGL){n.push("#version 300 es");for(let i of t.code?.vertInputs?.values()||[])n.push(`in ${i}`);for(let i of t.code?.vertOutputs?.values()||[])n.push(`out ${i}`);n.push(r),n.push("void main() {"),n.push(` gl_Position = ${o};`);for(let[i,p]of t.code?.vertVaryings?.entries()||[])n.push(` ${i} = ${p};`)}else{t.code?.vertInputs?.size&&n.push(se("In",t.code.vertInputs)),t.code?.vertOutputs?.size&&n.push(se("Out",t.code.vertOutputs)),n.push(r),n.push("@vertex"),n.push(`fn main(${t.code?.vertInputs?.size?"in: In":""}) -> Out {`),n.push(" var out: Out;"),n.push(` out.position = ${o};`);for(let[i,p]of t.code?.vertVaryings?.entries()||[])n.push(` out.${i} = ${p};`);n.push(" return out;")}n.push("}");let s=n.filter(Boolean).join(`
|
|
34
34
|
`).trim();return console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
35
|
-
${s}`),s},
|
|
36
|
-
fragColor = ${
|
|
37
|
-
fn main(out: Out) -> @location(0) vec4f {`),
|
|
35
|
+
${s}`),s},q=(e,t)=>{if(d.str(e))return e.trim();t.code?.headers?.clear(),t.isFrag=!0;let[r,o]=Ye(e,t),n=[];if(t.isWebGL){n.push(wt);for(let i of t.code?.fragInputs?.values()||[])n.push(`in ${i}`);n.push(r),n.push(`void main() {
|
|
36
|
+
fragColor = ${o};`)}else t.code?.fragInputs?.size&&n.push(se("Out",t.code.fragInputs)),n.push(r),n.push(`@fragment
|
|
37
|
+
fn main(out: Out) -> @location(0) vec4f {`),n.push(` return ${o};`);n.push("}");let s=n.filter(Boolean).join(`
|
|
38
38
|
`).trim();return console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
39
|
-
${s}`),s},de=T("position"),me=T("vertex_index"),Dr=T("instance_index"),Mr=T("front_facing"),Wr=T("frag_depth"),Vr=T("sample_index"),zr=T("sample_mask"),kr=T("point_coord"),qr=T("normalLocal"),Yr=T("normalWorld"),Hr=T("normalView"),jr=T("position"),Kr=T("positionWorld"),Zr=T("positionView"),Qr=T("screenCoordinate"),Jr=T("screenUV"),H=e=>x("float",e),A=e=>x("int",e),eo=e=>x("uint",e),to=e=>x("bool",e),et=(e,t)=>x("vec2",e,t),Qe=(e,t,r)=>x("vec3",e,t,r),xe=(e,t,r,n)=>x("vec4",e,t,r,n),ro=(...e)=>x("mat2",...e),oo=(...e)=>x("mat3",...e),no=(...e)=>x("mat4",...e),so=(e,t)=>x("ivec2",e,t),io=(e,t,r)=>x("ivec3",e,t,r),ao=(e,t,r,n)=>x("ivec4",e,t,r,n),uo=(e,t)=>x("uvec2",e,t),po=(e,t,r)=>x("uvec3",e,t,r),co=(e,t,r,n)=>x("uvec4",e,t,r,n),fo=(e,t)=>x("bvec2",e,t),lo=(e,t,r)=>x("bvec3",e,t,r),mo=(e,t,r,n)=>x("bvec4",e,t,r,n),xo=e=>x("texture",e),go=()=>x("sampler2D"),bo=(e,t,r)=>l.num(e)&&l.und(t)&&l.und(r)?Qe(...$e(e)):Qe(e,t,r),ge=k(et(),"iResolution"),vo=k(et(),"iMouse"),yo=k(H(),"iTime"),ho=()=>de.xy.div(ge),Xo=(e,t,r)=>u("texture",e,t,r),To=(e,t,r)=>u("cubeTexture",e,t,r),_o=(e,t)=>u("textureSize",e,t),Eo=e=>u("abs",e),No=e=>u("acos",e),Po=e=>u("all",e),Co=e=>u("any",e),Lo=e=>u("asin",e),So=(e,t)=>t!==void 0?u("atan",e,t):u("atan",e),wo=(e,t)=>u("atan",e,t),$o=(e,t)=>u("bitcast",e,t),Go=e=>u("cbrt",e),Ro=e=>u("ceil",e),Oo=(e,t,r)=>u("clamp",e,t,r),Io=e=>u("cos",e),Uo=(e,t)=>u("cross",e,t),Fo=e=>u("dFdx",e),Ao=e=>u("dFdy",e),Bo=e=>u("degrees",e),Do=(e,t)=>u("difference",e,t),Mo=(e,t)=>u("distance",e,t),Wo=(e,t)=>u("dot",e,t),Vo=(e,t)=>u("equals",e,t),zo=e=>u("exp",e),ko=e=>u("exp2",e),qo=(e,t,r)=>u("faceforward",e,t,r),Yo=e=>u("floor",e),tt=e=>u("fract",e),Ho=e=>u("fwidth",e),jo=e=>u("inverseSqrt",e),Ko=e=>u("length",e),Zo=e=>u("lengthSq",e),Qo=e=>u("log",e),Jo=e=>u("log2",e),en=(e,t)=>u("max",e,t),tn=(e,t)=>u("min",e,t),rn=(e,t,r)=>u("mix",e,t,r),on=e=>u("negate",e),nn=e=>u("normalize",e),sn=e=>u("oneMinus",e),an=(e,t)=>u("pow",e,t),un=e=>u("pow2",e),pn=e=>u("pow3",e),cn=e=>u("pow4",e),fn=e=>u("radians",e),ln=e=>u("reciprocal",e),dn=(e,t)=>u("reflect",e,t),mn=(e,t,r)=>u("refract",e,t,r),xn=e=>u("round",e),gn=e=>u("saturate",e),bn=e=>u("sign",e),vn=e=>u("sin",e),yn=(e,t,r)=>u("smoothstep",e,t,r),hn=e=>u("sqrt",e),Xn=(e,t)=>u("step",e,t),Tn=e=>u("tan",e),_n=(e,t)=>u("transformDirection",e,t),En=e=>u("trunc",e);var rt=(e,t,r)=>{let n=e.createShader(r);if(!n)throw new Error("Failed to create shader");if(e.shaderSource(n,t.trim()),e.compileShader(n),e.getShaderParameter(n,e.COMPILE_STATUS))return n;let o=e.getShaderInfoLog(n);e.deleteShader(n),console.warn(`Could not compile shader: ${o}`)},ot=(e,t,r,n=()=>{})=>{let o=e.createProgram(),s=rt(e,r,e.FRAGMENT_SHADER),i=rt(e,t,e.VERTEX_SHADER);if(!s||!i)return n();if(e.attachShader(o,i),e.attachShader(o,s),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS))return o;let c=e.getProgramInfoLog(o);e.deleteProgram(o),n(),console.warn(`Could not link program: ${c}`)},nt=(e,t)=>{let r=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array(t),e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,null),r},st=(e,t)=>{let r=e.createBuffer();return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Int16Array(t),e.STATIC_DRAW),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),r},it=(e,t,r)=>{r&&(e=Math.max(...r)+1);let n=t.length/e;return Math.floor(n)},at=(e,t,r,n,o)=>{e.bindBuffer(e.ARRAY_BUFFER,n),e.enableVertexAttribArray(r),e.vertexAttribPointer(r,t,e.FLOAT,!1,0,0),o&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,o)},ut=(e,t,r,n)=>{let o=e.createTexture();e.bindTexture(e.TEXTURE_2D,o),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.generateMipmap(e.TEXTURE_2D),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),e.uniform1i(r,n),e.activeTexture(e.TEXTURE0+n),e.bindTexture(e.TEXTURE_2D,o)};var pt=async e=>{let t=e.el.getContext("webgl2"),r={isWebGL:!0,gl:e},n=Y(e.fs,r),o=q(e.vs,r),s=ot(t,o,n,()=>void(e.isLoop=!1));t.useProgram(s);let i=0,c=be(C=>t.getUniformLocation(s,C)),a=be(C=>t.getAttribLocation(s,C)),p=be(()=>i++);return{render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(s),_attribute:(C="",E,L)=>{let $=a(C,!0),M=nt(t,E),j=st(t,L),h=it(e.count,E,L);at(t,h,$,M,j)},_uniform:(C,E)=>{let L=c(C);if(l.num(E))return t.uniform1f(L,E);let $=E.length;if($<=4)return t[`uniform${$}fv`](L,E);$=Math.sqrt($)<<0,t[`uniformMatrix${$}fv`](L,!1,E)},_texture:(C,E)=>{let L=new Image;Object.assign(L,{src:E,crossOrigin:"anonymous"}),L.decode().then(()=>{let $=c(C),M=p(C);ut(t,L,$,M)})},webgl:{context:t,program:s}}};import{nested as ve}from"reev";var ct=async e=>{let t=navigator.gpu,r=t.getPreferredCanvasFormat(),o=await(await t.requestAdapter()).requestDevice();return e.configure({device:o,format:r,alphaMode:"opaque"}),{device:o,format:r}},ft=()=>{let e=0,t=0,r=0;return{uniform:()=>{let n=Math.floor(e/12),o=e%12;return e++,{group:n,binding:o}},texture:()=>{let o=Math.floor(e/12)+1+Math.floor(t/6),s=t%6*2;return t++,{group:o,binding:s}},attrib:()=>{let n=r;return r++,{location:n}}}},Ut=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",lt=e=>{let t=[],r=[];for(let{buffer:n,location:o,stride:s}of e)t[o]=n,r[o]={arrayStride:s*4,attributes:[{shaderLocation:o,offset:0,format:Ut(s)}]};return{vertexBuffers:t,bufferLayouts:r}},dt=(e,t,r)=>{let n=new Map,o={bindGroups:[],bindGroupLayouts:[]},s=(i,c,a)=>{n.has(i)||n.set(i,{layouts:[],bindings:[]});let{layouts:p,bindings:g}=n.get(i);p.push(c),g.push(a)};for(let{binding:i,buffer:c,group:a}of t)s(a,{binding:i,visibility:3,buffer:{type:"uniform"}},{binding:i,resource:{buffer:c}});for(let{binding:i,group:c,sampler:a,view:p}of r)s(c,{binding:i,visibility:2,sampler:{}},{binding:i,resource:a}),s(c,{binding:i+1,visibility:2,texture:{}},{binding:i+1,resource:p});for(let[i,{layouts:c,bindings:a}]of n)o.bindGroupLayouts[i]=e.createBindGroupLayout({entries:c}),o.bindGroups[i]=e.createBindGroup({layout:o.bindGroupLayouts[i],entries:a});return o},mt=(e,t,r,n,o,s)=>e.createRenderPipeline({vertex:{module:e.createShaderModule({label:"vert",code:o}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({label:"frag",code:s}),entryPoint:"main",targets:[{format:t}]},layout:e.createPipelineLayout({bindGroupLayouts:n}),primitive:{topology:"triangle-list"},depthStencil:{depthWriteEnabled:!0,depthCompare:"less",format:"depth24plus"}}),xt=(e,t)=>{let r=new Float32Array(t),n=Math.ceil(r.byteLength/256)*256,o=e.createBuffer({size:n,usage:72});return{array:r,buffer:o}},gt=(e,t)=>{let r=new Float32Array(t),n=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:n}},bt=(e,t)=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}],depthStencilAttachment:{view:t.createView(),depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}}),vt=(e,t=1280,r=800)=>{let n=e.createTexture({size:[t,r],format:"rgba8unorm",usage:22}),o=e.createSampler({magFilter:"linear",minFilter:"linear"});return{texture:n,sampler:o}},yt=(e,t,r)=>e.createTexture({size:[t,r],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT});var ht=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:n}=await ct(t),o=ft(),s,i,c=h=>{},a=0,p=!0,g,P=ve((h,b)=>{p=!0;let{array:X,buffer:_}=xt(r,b),{binding:G,group:N}=o.uniform();return{binding:G,group:N,array:X,buffer:_}}),v=ve((h,b=0,X=0)=>{p=!0;let{texture:_,sampler:G}=vt(r,b,X),{binding:N,group:W}=o.texture();return{binding:N,group:W,texture:_,sampler:G,view:_.createView()}}),m=ve((h,b)=>{p=!0;let X=b.length/e.count,{location:_}=o.attrib(),{array:G,buffer:N}=gt(r,b);return{array:G,buffer:N,location:_,stride:X}}),D=()=>{let{vertexBuffers:h,bufferLayouts:b}=lt(m.map.values()),{bindGroups:X,bindGroupLayouts:_}=dt(r,P.map.values(),v.map.values()),G=mt(r,n,b,_,i,s);c=N=>{N.setPipeline(G),X.forEach((W,K)=>N.setBindGroup(K,W)),h.forEach((W,K)=>N.setVertexBuffer(K,W)),N.draw(e.count,1,0,0),N.end()}},C=()=>{if(!s||!i){let b={isWebGL:!1,gl:e};s=Y(e.fs,b),i=q(e.vs,b)}if(a)return;p&&D(),p=!1;let h=r.createCommandEncoder();c(h.beginRenderPass(bt(t,g))),r.queue.submit([h.finish()])},E=()=>{let h=e.el;g?.destroy(),g=yt(r,h.width,h.height)},L=()=>{g?.destroy()},$=(h="",b)=>{let{array:X,buffer:_}=m(h,b);X.set(b),r.queue.writeBuffer(_,0,X)},M=(h,b)=>{l.num(b)&&(b=[b]);let{array:X,buffer:_}=P(h,b);X.set(b),r.queue.writeBuffer(_,0,X)},j=(h,b)=>{a++;let X=Object.assign(new Image,{src:b,crossOrigin:"anonymous"});X.decode().then(()=>{let{width:_,height:G}=X,{texture:N}=v(h,_,G);r.queue.copyExternalImageToTexture({source:X},{texture:N},{width:_,height:G}),a--})};return E(),{webgpu:{device:r,uniforms:P,textures:v,attribs:m},render:C,resize:E,clean:L,_attribute:$,_uniform:M,_texture:j}};var Xt=e=>l.obj(e)?"isGL"in e:!1,Dt=()=>typeof window>"u",Mt=()=>Dt()?!1:"gpu"in navigator,he=performance.now(),Wt=()=>xe(tt(de.xy.div(ge)),0,1),Vt=()=>xe(H(A(me).mod(A(2))).mul(4).sub(1),H(A(me).div(A(2))).mul(4).sub(1),0,1),Tt=e=>{let t=Ft({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=Bt(),t.frame=At(),t.attribute=ye((r,n,o)=>t.queue(()=>t._attribute?.(r,n,o)),t),t.uniform=ye((r,n,o)=>t.queue(()=>t._uniform?.(r,n,o)),t),t.texture=ye((r,n)=>t.queue(()=>t._texture?.(r,n)),t),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:he}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex||Vt(),t.fs=t.fs||t.frag||t.fragment||Wt(),Mt()||(t.isWebGL=!0),t.isWebGL?t(await pt(t)):t(await ht(t)),t.resize(),t.frame(()=>(t.loop(),t.queue.flush(),t.render(),t.isLoop)),!t.isNative&&(window.addEventListener("resize",t.resize),t.el.addEventListener("mousemove",t.mousemove))}),t("clean",()=>{t.frame.stop(),t.frame.clean(t.render),!t.isNative&&(window.removeEventListener("resize",t.resize),t.el.removeEventListener("mousemove",t.mousemove))}),t("resize",()=>{let r=t.width||window.innerWidth,n=t.height||window.innerHeight;t.size[0]=t.el.width=r,t.size[1]=t.el.height=n,t.uniform("iResolution",t.size)}),t("mousemove",(r,n=r.clientX,o=r.clientY)=>{let[s,i]=t.size,{top:c,left:a}=t.el.getBoundingClientRect();t.mouse[0]=(n-c-s/2)/(s/2),t.mouse[1]=-(o-a-i/2)/(i/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{he=performance.now()/1e3,t.uniform("iTime",he)}),t(e)};var ss=(e={})=>zt(()=>{let t=Xt(e)?e:Tt(e);return t.ref=r=>{t.el={},t({render(){r.flush(),r.endFrameEXP()}}),t.mount(),(()=>{t.width=r.drawingBufferWidth,t.height=r.drawingBufferHeight,t.resize()})()},t({isNative:!0})})[0];export{Er as Fn,Xr as If,Tr as Loop,Gt as Return,_r as Switch,Eo as abs,No as acos,z as addDependency,Po as all,Co as any,Lo as asin,Ke as assign,So as atan,wo as atan2,wr as attribute,$o as bitcast,to as bool,T as builtin,fo as bvec2,lo as bvec3,mo as bvec4,Go as cbrt,Ro as ceil,Oo as clamp,f as code,bo as color,$r as constant,x as conversion,Oe as conversionToConstant,Io as cos,at as createAttrib,gt as createAttribBuffer,dt as createBindGroup,ft as createBindings,yt as createDepthTexture,bt as createDescriptor,ct as createDevice,Tt as createGL,st as createIbo,mt as createPipeline,ot as createProgram,ut as createTexture,vt as createTextureSampler,xt as createUniformBuffer,nt as createVbo,lt as createVertexBuffers,Uo as cross,To as cubeTexture,Fo as dFdx,Ao as dFdy,Bo as degrees,Do as difference,jt as dig,Mo as distance,Wo as dot,_t as each,Vo as equals,zo as exp,ko as exp2,Yt as ext,qo as faceforward,Ht as fig,H as float,Yo as floor,kt as flush,w as formatConversions,tt as fract,Wr as fragDepth,Y as fragment,Mr as frontFacing,u as function_,Ho as fwidth,Re as getBluiltin,pe as getEventFun,S as getId,Ge as getOperator,it as getStride,$e as hex2rgb,vo as iMouse,ge as iResolution,yo as iTime,Ie as initNodeContext,Dr as instanceIndex,A as int,jo as inverseSqrt,l as is,ue as isConstants,we as isConversion,Se as isFunction,Xt as isGL,V as isNodeProxy,Le as isOperator,Dt as isServer,Ce as isSwizzle,Mt as isWebGPUSupported,so as ivec2,io as ivec3,ao as ivec4,Ko as length,Zo as lengthSq,Qo as log,Jo as log2,ro as mat2,oo as mat3,no as mat4,en as max,Ze as member,tn as min,rn as mix,on as negate,d as node,qr as normalLocal,Hr as normalView,Yr as normalWorld,nn as normalize,sn as oneMinus,Ot as operator,kr as pointCoord,de as position,jr as positionLocal,Zr as positionView,Kr as positionWorld,an as pow,un as pow2,pn as pow3,cn as pow4,fn as radians,ln as reciprocal,dn as reflect,mn as refract,qt as replace,xn as round,ce as safeEventCall,Vr as sampleIndex,zr as sampleMask,go as sampler2D,gn as saturate,Qr as screenCoordinate,Jr as screenUV,Or as select,Kt as sig,bn as sign,vn as sin,yn as smoothstep,Ue as sortHeadersByDependencies,hn as sqrt,Xn as step,hr as struct,Tn as tan,Xo as texture,xo as texture2D,_o as textureSize,je as toVar,_n as transformDirection,En as trunc,eo as uint,k as uniform,ss as useGL,ho as uv,uo as uvec2,po as uvec3,co as uvec4,Gr as variable,et as vec2,Qe as vec3,xe as vec4,q as vertex,me as vertexIndex,Rr as vertexStage,pt as webgl,ht as webgpu};
|
|
39
|
+
${s}`),s},ie=C("position"),ae=C("vertex_index"),Gr=C("instance_index"),Lr=C("front_facing"),Sr=C("frag_depth"),Rr=C("sample_index"),Or=C("sample_mask"),Fr=C("point_coord"),Ir=C("position"),Ur=C("positionWorld"),Ar=C("positionView"),Br=C("normalLocal"),Dr=C("normalWorld"),Mr=C("normalView"),Wr=C("screenCoordinate"),Vr=C("screenUV"),Y=e=>T("float",e),M=e=>T("int",e),zr=e=>T("uint",e),kr=e=>T("bool",e),He=(e,t)=>T("vec2",e,t),qe=(e,t,r)=>T("vec3",e,t,r),ue=(e,t,r,o)=>T("vec4",e,t,r,o),qr=(...e)=>T("mat2",...e),Yr=(...e)=>T("mat3",...e),Hr=(...e)=>T("mat4",...e),jr=(e,t)=>T("ivec2",e,t),Kr=(e,t,r)=>T("ivec3",e,t,r),Zr=(e,t,r,o)=>T("ivec4",e,t,r,o),Qr=(e,t)=>T("uvec2",e,t),Jr=(e,t,r)=>T("uvec3",e,t,r),en=(e,t,r,o)=>T("uvec4",e,t,r,o),tn=(e,t)=>T("bvec2",e,t),rn=(e,t,r)=>T("bvec3",e,t,r),nn=(e,t,r,o)=>T("bvec4",e,t,r,o),on=e=>T("texture",e),sn=()=>T("sampler2D"),an=(e,t,r)=>d.num(e)&&d.und(t)&&d.und(r)?qe(...Pe(e)):qe(e,t,r),pe=z(He(),"iResolution"),un=z(He(),"iMouse"),pn=z(Y(),"iTime"),cn=ie.xy.div(pe),fn=(e,t,r)=>u("texture",e,t,r),dn=(e,t,r)=>u("cubeTexture",e,t,r),ln=(e,t)=>u("textureSize",e,t),xn=e=>u("length",e),mn=e=>u("lengthSq",e),Tn=(e,t)=>u("distance",e,t),gn=(e,t)=>u("dot",e,t),bn=e=>u("all",e),vn=e=>u("any",e),hn=(e,t)=>u("cross",e,t),yn=e=>u("abs",e),Cn=e=>u("sign",e),Xn=e=>u("floor",e),_n=e=>u("ceil",e),Pn=e=>u("round",e),je=e=>u("fract",e),En=e=>u("trunc",e),wn=e=>u("sin",e),Nn=e=>u("cos",e),$n=e=>u("tan",e),Gn=e=>u("asin",e),Ln=e=>u("acos",e),Sn=e=>u("atan",e),Rn=e=>u("sinh",e),On=e=>u("cosh",e),Fn=e=>u("tanh",e),In=e=>u("asinh",e),Un=e=>u("acosh",e),An=e=>u("atanh",e),Bn=e=>u("exp",e),Dn=e=>u("exp2",e),Mn=e=>u("log",e),Wn=e=>u("log2",e),Vn=e=>u("sqrt",e),zn=e=>u("inverseSqrt",e),kn=e=>u("normalize",e),qn=e=>u("oneMinus",e),Yn=e=>u("saturate",e),Hn=e=>u("negate",e),jn=e=>u("reciprocal",e),Kn=e=>u("dFdx",e),Zn=e=>u("dFdy",e),Qn=e=>u("fwidth",e),Jn=e=>u("degrees",e),eo=e=>u("radians",e),to=(e,t)=>u("reflect",e,t),ro=(e,t,r)=>u("refract",e,t,r),no=(e,t)=>u("min",e,t),oo=(e,t)=>u("max",e,t),so=(e,t,r)=>u("mix",e,t,r),io=(e,t,r)=>u("clamp",e,t,r),ao=(e,t)=>u("step",e,t),uo=(e,t,r)=>u("smoothstep",e,t,r),po=(e,t)=>u("atan2",e,t),co=(e,t)=>u("pow",e,t),fo=e=>u("pow2",e),lo=e=>u("pow3",e),xo=e=>u("pow4",e),mo=(e,t)=>u("bitcast",e,t),To=e=>u("cbrt",e),go=(e,t)=>u("difference",e,t),bo=(e,t)=>u("equals",e,t),vo=(e,t,r)=>u("faceforward",e,t,r),ho=(e,t)=>u("transformDirection",e,t);var Ke=(e,t,r)=>{let o=e.createShader(r);if(!o)throw new Error("Failed to create shader");if(e.shaderSource(o,t.trim()),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS))return o;let n=e.getShaderInfoLog(o);e.deleteShader(o),console.warn(`Could not compile shader: ${n}`)},Ze=(e,t,r,o=()=>{})=>{let n=e.createProgram(),s=Ke(e,r,e.FRAGMENT_SHADER),i=Ke(e,t,e.VERTEX_SHADER);if(!s||!i)return o();if(e.attachShader(n,i),e.attachShader(n,s),e.linkProgram(n),e.getProgramParameter(n,e.LINK_STATUS))return n;let p=e.getProgramInfoLog(n);e.deleteProgram(n),o(),console.warn(`Could not link program: ${p}`)},Qe=(e,t)=>{let r=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array(t),e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,null),r},Je=(e,t)=>{let r=e.createBuffer();return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Int16Array(t),e.STATIC_DRAW),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),r},et=(e,t,r)=>{r&&(e=Math.max(...r)+1);let o=t.length/e;return Math.floor(o)},tt=(e,t,r,o,n)=>{e.bindBuffer(e.ARRAY_BUFFER,o),e.enableVertexAttribArray(r),e.vertexAttribPointer(r,t,e.FLOAT,!1,0,0),n&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,n)},rt=(e,t,r,o)=>{let n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.generateMipmap(e.TEXTURE_2D),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),e.uniform1i(r,o),e.activeTexture(e.TEXTURE0+o),e.bindTexture(e.TEXTURE_2D,n)};var nt=async e=>{let t=e.el.getContext("webgl2"),r={isWebGL:!0,gl:e},o=q(e.fs,r),n=k(e.vs,r),s=Ze(t,n,o,()=>void(e.isLoop=!1));t.useProgram(s);let i=0,p=ce(w=>t.getUniformLocation(s,w)),a=ce(w=>t.getAttribLocation(s,w)),c=ce(()=>i++);return{render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(s),_attribute:(w="",_,N)=>{let L=a(w,!0),B=Qe(t,_),H=Je(t,N),h=et(e.count,_,N);tt(t,h,L,B,H)},_uniform:(w,_)=>{let N=p(w);if(d.num(_))return t.uniform1f(N,_);let L=_.length;if(L<=4)return t[`uniform${L}fv`](N,_);L=Math.sqrt(L)<<0,t[`uniformMatrix${L}fv`](N,!1,_)},_texture:(w,_)=>{let N=new Image;Object.assign(N,{src:_,crossOrigin:"anonymous"}),N.decode().then(()=>{let L=p(w),B=c(w);rt(t,N,L,B)})},webgl:{context:t,program:s}}};import{nested as fe}from"reev";var ot=async e=>{let t=navigator.gpu,r=t.getPreferredCanvasFormat(),n=await(await t.requestAdapter()).requestDevice();return e.configure({device:n,format:r,alphaMode:"opaque"}),{device:n,format:r}},st=()=>{let e=0,t=0,r=0;return{uniform:()=>{let o=Math.floor(e/12),n=e%12;return e++,{group:o,binding:n}},texture:()=>{let n=Math.floor(e/12)+1+Math.floor(t/6),s=t%6*2;return t++,{group:n,binding:s}},attrib:()=>{let o=r;return r++,{location:o}}}},Nt=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",it=e=>{let t=[],r=[];for(let{buffer:o,location:n,stride:s}of e)t[n]=o,r[n]={arrayStride:s*4,attributes:[{shaderLocation:n,offset:0,format:Nt(s)}]};return{vertexBuffers:t,bufferLayouts:r}},at=(e,t,r)=>{let o=new Map,n={bindGroups:[],bindGroupLayouts:[]},s=(i,p,a)=>{o.has(i)||o.set(i,{layouts:[],bindings:[]});let{layouts:c,bindings:l}=o.get(i);c.push(p),l.push(a)};for(let{binding:i,buffer:p,group:a}of t)s(a,{binding:i,visibility:3,buffer:{type:"uniform"}},{binding:i,resource:{buffer:p}});for(let{binding:i,group:p,sampler:a,view:c}of r)s(p,{binding:i,visibility:2,sampler:{}},{binding:i,resource:a}),s(p,{binding:i+1,visibility:2,texture:{}},{binding:i+1,resource:c});for(let[i,{layouts:p,bindings:a}]of o)n.bindGroupLayouts[i]=e.createBindGroupLayout({entries:p}),n.bindGroups[i]=e.createBindGroup({layout:n.bindGroupLayouts[i],entries:a});return n},ut=(e,t,r,o,n,s)=>e.createRenderPipeline({vertex:{module:e.createShaderModule({label:"vert",code:n}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({label:"frag",code:s}),entryPoint:"main",targets:[{format:t}]},layout:e.createPipelineLayout({bindGroupLayouts:o}),primitive:{topology:"triangle-list"},depthStencil:{depthWriteEnabled:!0,depthCompare:"less",format:"depth24plus"}}),pt=(e,t)=>{let r=new Float32Array(t),o=Math.ceil(r.byteLength/256)*256,n=e.createBuffer({size:o,usage:72});return{array:r,buffer:n}},ct=(e,t)=>{let r=new Float32Array(t),o=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:o}},ft=(e,t)=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}],depthStencilAttachment:{view:t.createView(),depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}}),dt=(e,t=1280,r=800)=>{let o=e.createTexture({size:[t,r],format:"rgba8unorm",usage:22}),n=e.createSampler({magFilter:"linear",minFilter:"linear"});return{texture:o,sampler:n}},lt=(e,t,r)=>e.createTexture({size:[t,r],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT});var xt=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:o}=await ot(t),n=st(),s,i,p=h=>{},a=0,c=!0,l,E=fe((h,g)=>{c=!0;let{array:y,buffer:X}=pt(r,g),{binding:S,group:P}=n.uniform();return{binding:S,group:P,array:y,buffer:X}}),b=fe((h,g=0,y=0)=>{c=!0;let{texture:X,sampler:S}=dt(r,g,y),{binding:P,group:D}=n.texture();return{binding:P,group:D,texture:X,sampler:S,view:X.createView()}}),m=fe((h,g)=>{c=!0;let y=g.length/e.count,{location:X}=n.attrib(),{array:S,buffer:P}=ct(r,g);return{array:S,buffer:P,location:X,stride:y}}),A=()=>{let{vertexBuffers:h,bufferLayouts:g}=it(m.map.values()),{bindGroups:y,bindGroupLayouts:X}=at(r,E.map.values(),b.map.values()),S=ut(r,o,g,X,i,s);p=P=>{P.setPipeline(S),y.forEach((D,j)=>P.setBindGroup(j,D)),h.forEach((D,j)=>P.setVertexBuffer(j,D)),P.draw(e.count,1,0,0),P.end()}},w=()=>{if(!s||!i){let g={isWebGL:!1,gl:e};s=q(e.fs,g),i=k(e.vs,g)}if(a)return;c&&A(),c=!1;let h=r.createCommandEncoder();p(h.beginRenderPass(ft(t,l))),r.queue.submit([h.finish()])},_=()=>{let h=e.el;l?.destroy(),l=lt(r,h.width,h.height)},N=()=>{l?.destroy()},L=(h="",g)=>{let{array:y,buffer:X}=m(h,g);y.set(g),r.queue.writeBuffer(X,0,y)},B=(h,g)=>{d.num(g)&&(g=[g]);let{array:y,buffer:X}=E(h,g);y.set(g),r.queue.writeBuffer(X,0,y)},H=(h,g)=>{a++;let y=Object.assign(new Image,{src:g,crossOrigin:"anonymous"});y.decode().then(()=>{let{width:X,height:S}=y,{texture:P}=b(h,X,S);r.queue.copyExternalImageToTexture({source:y},{texture:P},{width:X,height:S}),a--})};return _(),{webgpu:{device:r,uniforms:E,textures:b,attribs:m},render:w,resize:_,clean:N,_attribute:L,_uniform:B,_texture:H}};var mt=e=>d.obj(e)?"isGL"in e:!1,St=()=>typeof window>"u",Rt=()=>St()?!1:"gpu"in navigator,le=performance.now(),Ot=()=>ue(je(ie.xy.div(pe)),0,1),Ft=()=>ue(Y(M(ae).mod(M(2))).mul(4).sub(1),Y(M(ae).div(M(2))).mul(4).sub(1),0,1),Tt=e=>{let t=$t({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=Lt(),t.frame=Gt(),t.attribute=de((r,o,n)=>t.queue(()=>t._attribute?.(r,o,n)),t),t.uniform=de((r,o,n)=>t.queue(()=>t._uniform?.(r,o,n)),t),t.texture=de((r,o)=>t.queue(()=>t._texture?.(r,o)),t),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:le}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex||Ft(),t.fs=t.fs||t.frag||t.fragment||Ot(),Rt()||(t.isWebGL=!0),t.isWebGL?t(await nt(t)):t(await xt(t)),t.resize(),t.frame(()=>(t.loop(),t.queue.flush(),t.render(),t.isLoop)),!t.isNative&&(window.addEventListener("resize",t.resize),t.el.addEventListener("mousemove",t.mousemove))}),t("clean",()=>{t.frame.stop(),t.frame.clean(t.render),!t.isNative&&(window.removeEventListener("resize",t.resize),t.el.removeEventListener("mousemove",t.mousemove))}),t("resize",()=>{let r=t.width||window.innerWidth,o=t.height||window.innerHeight;t.size[0]=t.el.width=r,t.size[1]=t.el.height=o,t.uniform("iResolution",t.size)}),t("mousemove",(r,o=r.clientX,n=r.clientY)=>{let[s,i]=t.size,{top:p,left:a}=t.el.getBoundingClientRect();t.mouse[0]=(o-p-s/2)/(s/2),t.mouse[1]=-(n-a-i/2)/(i/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{le=performance.now()/1e3,t.uniform("iTime",le)}),t(e)};var ts=(e={})=>It(()=>{let t=mt(e)?e:Tt(e);return t.ref=r=>{t.el={},t({render(){r.flush(),r.endFrameEXP()}}),t.mount(),(()=>{t.width=r.drawingBufferWidth,t.height=r.drawingBufferHeight,t.resize()})()},t({isNative:!0})})[0];export{xr as Fn,fr as If,dr as Loop,_t as Return,lr as Switch,yn as abs,Ln as acos,Un as acosh,V as addDependency,bn as all,vn as any,Gn as asin,In as asinh,ze as assign,Sn as atan,po as atan2,An as atanh,hr as attribute,mo as bitcast,kr as bool,C as builtin,tn as bvec2,rn as bvec3,nn as bvec4,To as cbrt,_n as ceil,io as clamp,f as code,an as color,yr as constant,T as conversion,Ne as conversionToConstant,Nn as cos,On as cosh,tt as createAttrib,ct as createAttribBuffer,at as createBindGroup,st as createBindings,lt as createDepthTexture,ft as createDescriptor,ot as createDevice,Tt as createGL,Je as createIbo,ut as createPipeline,Ze as createProgram,rt as createTexture,dt as createTextureSampler,pt as createUniformBuffer,Qe as createVbo,it as createVertexBuffers,hn as cross,dn as cubeTexture,Kn as dFdx,Zn as dFdy,Jn as degrees,go as difference,Mt as dig,Tn as distance,gn as dot,gt as each,bo as equals,Bn as exp,Dn as exp2,Bt as ext,vo as faceforward,Dt as fig,Y as float,Xn as floor,Ut as flush,G as formatConversions,je as fract,Sr as fragDepth,q as fragment,Lr as frontFacing,u as function_,Qn as fwidth,we as getBluiltin,re as getEventFun,$ as getId,Ee as getOperator,et as getStride,Pe as hex2rgb,un as iMouse,pe as iResolution,pn as iTime,$e as initNodeContext,Gr as instanceIndex,M as int,zn as inverseSqrt,d as is,te as isConstants,_e as isConversion,Xe as isFunction,mt as isGL,W as isNodeProxy,Ce as isOperator,St as isServer,ye as isSwizzle,Rt as isWebGPUSupported,jr as ivec2,Kr as ivec3,Zr as ivec4,xn as length,mn as lengthSq,Mn as log,Wn as log2,qr as mat2,Yr as mat3,Hr as mat4,oo as max,ke as member,no as min,so as mix,Hn as negate,x as node,Br as normalLocal,Mr as normalView,Dr as normalWorld,kn as normalize,qn as oneMinus,Et as operator,Fr as pointCoord,ie as position,Ir as positionLocal,Ar as positionView,Ur as positionWorld,co as pow,fo as pow2,lo as pow3,xo as pow4,eo as radians,jn as reciprocal,to as reflect,ro as refract,At as replace,Pn as round,ne as safeEventCall,Rr as sampleIndex,Or as sampleMask,sn as sampler2D,Yn as saturate,Wr as screenCoordinate,Vr as screenUV,_r as select,Wt as sig,Cn as sign,wn as sin,Rn as sinh,uo as smoothstep,Ge as sortHeadersByDependencies,Vn as sqrt,ao as step,cr as struct,$n as tan,Fn as tanh,fn as texture,on as texture2D,ln as textureSize,Ve as toVar,ho as transformDirection,En as trunc,zr as uint,z as uniform,ts as useGL,cn as uv,Qr as uvec2,Jr as uvec3,en as uvec4,Cr as variable,He as vec2,qe as vec3,ue as vec4,k as vertex,ae as vertexIndex,Xr as vertexStage,nt as webgl,xt as webgpu};
|
|
40
40
|
//# sourceMappingURL=native.js.map
|