glre 0.23.0 → 0.25.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 +11 -13
- package/dist/index.d.ts +39 -22
- package/dist/index.js +17 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -15
- package/dist/index.mjs.map +1 -1
- package/dist/native.d.ts +1 -1
- package/dist/native.js +17 -15
- package/dist/native.js.map +1 -1
- package/dist/native.mjs +17 -15
- package/dist/native.mjs.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +17 -15
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +17 -15
- package/dist/react.mjs.map +1 -1
- package/dist/solid.d.ts +1 -1
- package/dist/solid.js +17 -15
- package/dist/solid.js.map +1 -1
- package/dist/solid.mjs +17 -15
- package/dist/solid.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +14 -14
- package/src/node/index.ts +2 -2
- package/src/types.ts +7 -0
- package/src/utils/pipeline.ts +59 -75
- package/src/utils/program.ts +23 -17
- package/src/webgl.ts +34 -58
- package/src/webgpu.ts +72 -50
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
3
|
import { GL, X, WebGPUState, WebGLState, Uniform, Attribute } from './index.js';
|
|
4
|
-
export { Attributes, CACHE_BOOLS, CACHE_FLOATS, CACHE_INTS, ConditionalNode, ConversionContext, FUNCTIONS, Fn, FunctionNode, GLClearMode, GLDrawMode, GLDrawType, GPUBuffer, GPUContext, GPUDevice, GPUPipeline, If, MathFunction, MathMethods, Node, NodeCreator, NodeType, OPERATORS, Operator, OperatorMethods, PrecisionMode, ProxyCallback, SWIZZLES, Swillzes, SwizzleProperties, TYPES, UniformNode, Uniforms, abs,
|
|
4
|
+
export { Attributes, CACHE_BOOLS, CACHE_FLOATS, CACHE_INTS, ConditionalNode, ConversionContext, FUNCTIONS, Fn, FunctionNode, GLClearMode, GLDrawMode, GLDrawType, GPUBindGroup, GPUBuffer, GPUContext, GPUDevice, GPUPipeline, If, MathFunction, MathMethods, Node, NodeCreator, NodeType, OPERATORS, Operator, OperatorMethods, PrecisionMode, ProxyCallback, SWIZZLES, Swillzes, SwizzleProperties, TYPES, UniformNode, Uniforms, abs, alignTo256, bool, ceil, color, convertToNode, cos, createAttrib, createBindGroup, createDescriptor, createDevive, default as createGL, createIbo, createNode, createPipeline, createProgram, createTexture, createTextureSampler, createUniformBuffer, createVbo, defaultFragmentGLSL, defaultVertexGLSL, dig, each, ext, fig, findDuplicateNodes, float, floor, flush, fract, fragCoord, getCachedBool, getCachedFloat, getCachedInt, getStride, glsl, iDeltaTime, iMouse, iPrevTime, iResolution, iTime, int, is, isGL, isServer, isWebGPUSupported, length, node, nodeToGLSL, nodeToWGSL, normalize, position, replace, sig, sin, sqrt, tan, uniform, updateUniforms, vec2, vec3, vec4, webgl, webgpu, wgsl } from './index.js';
|
|
5
5
|
export { Frame, Fun, Queue } from 'refr';
|
|
6
6
|
|
|
7
7
|
declare const useGL: (props?: Partial<GL>) => reev.EventState<{
|
package/dist/native.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var P=Object.defineProperty;var
|
|
2
|
-
`),u+=`precision ${
|
|
1
|
+
"use strict";var P=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var Se=Object.prototype.hasOwnProperty;var Ce=(e,t)=>{for(var r in t)P(e,r,{get:t[r],enumerable:!0})},Ge=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ne(t))!Se.call(e,o)&&o!==r&&P(e,o,{get:()=>t[o],enumerable:!(n=Le(t,o))||n.enumerable});return e};var Re=e=>Ge(P({},"__esModule",{value:!0}),e);var _t={};Ce(_t,{CACHE_BOOLS:()=>J,CACHE_FLOATS:()=>te,CACHE_INTS:()=>ee,FUNCTIONS:()=>Q,Fn:()=>lt,If:()=>dt,OPERATORS:()=>Z,SWIZZLES:()=>K,TYPES:()=>He,abs:()=>Tt,alignTo256:()=>de,bool:()=>et,ceil:()=>Nt,color:()=>nt,convertToNode:()=>Ze,cos:()=>Et,createAttrib:()=>z,createBindGroup:()=>V,createDescriptor:()=>j,createDevive:()=>D,createGL:()=>se,createIbo:()=>I,createNode:()=>$,createPipeline:()=>q,createProgram:()=>F,createTexture:()=>O,createTextureSampler:()=>Y,createUniformBuffer:()=>H,createVbo:()=>M,defaultFragmentGLSL:()=>me,defaultVertexGLSL:()=>pe,dig:()=>Pe,each:()=>ue,ext:()=>Xe,fig:()=>Ae,findDuplicateNodes:()=>ke,float:()=>_,floor:()=>Lt,flush:()=>_e,fract:()=>St,fragCoord:()=>gt,getCachedBool:()=>C,getCachedFloat:()=>R,getCachedInt:()=>G,getStride:()=>B,glsl:()=>L,iDeltaTime:()=>ye,iMouse:()=>yt,iPrevTime:()=>xe,iResolution:()=>xt,iTime:()=>bt,int:()=>Je,is:()=>i,isGL:()=>ae,isServer:()=>Te,isWebGPUSupported:()=>ve,length:()=>Gt,node:()=>s,nodeToGLSL:()=>fe,nodeToWGSL:()=>le,normalize:()=>Ct,position:()=>ht,replace:()=>Ue,sig:()=>Fe,sin:()=>vt,sqrt:()=>$t,tan:()=>wt,uniform:()=>h,updateUniforms:()=>mt,useGL:()=>Rt,vec2:()=>tt,vec3:()=>he,vec4:()=>rt,webgl:()=>W,webgpu:()=>k,wgsl:()=>S});module.exports=Re(_t);var Ee=require("react"),we=require("react-native");var v=require("reev"),X=require("refr");var N=require("reev");var i={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)},ue=(e,t)=>e.forEach(t),_e=(e,...t)=>{ue(e,r=>r(...t))},Ue=(e="",t="_",r="/")=>e.split(t).join(r),Xe=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",Ae=(e=0)=>`${e}`.split(".")[1]?.length??0,Pe=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),Fe=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var fe=(e,t)=>{let r={target:"webgl",precision:"mediump",version:"300 es",nodes:new Map,variables:new Map,functions:new Map,...t};return E(e,r)},E=(e,t)=>e?i.und(e.value)?e.property&&e.parent?`${E(e.parent,t)}.${e.property}`:e.operator&&e.children&&e.children.length>=2?Ie(e,t):e.mathFunction&&e.children&&e.children.length>=1?Be(e,t):"0.0":Me(e.value,e.type):"0.0",Me=(e,t)=>{if(t==="float"){let r=Number(e);return r%1===0?`${r}.0`:`${r}`}if(t==="int")return`${Math.floor(Number(e))}`;if(t==="bool")return e?"true":"false";if(i.arr(e)){let r=e.map(n=>{let o=Number(n);return o%1===0?`${o}.0`:`${o}`}).join(", ");if(t==="vec2")return`vec2(${r})`;if(t==="vec3")return`vec3(${r})`;if(t==="vec4")return`vec4(${r})`;if(t==="color")return`vec3(${r})`}return"0.0"},Ie=(e,t)=>{if(!e.children||e.children.length<2)return"0.0";let r=E(e.children[0],t),n=E(e.children[1],t);return e.operator==="add"?`(${r} + ${n})`:e.operator==="sub"?`(${r} - ${n})`:e.operator==="mul"?`(${r} * ${n})`:e.operator==="div"?`(${r} / ${n})`:e.operator==="mod"?`mod(${r}, ${n})`:e.operator==="equal"?`(${r} == ${n})`:e.operator==="notEqual"?`(${r} != ${n})`:e.operator==="lessThan"?`(${r} < ${n})`:e.operator==="lessThanEqual"?`(${r} <= ${n})`:e.operator==="greaterThan"?`(${r} > ${n})`:e.operator==="greaterThanEqual"?`(${r} >= ${n})`:e.operator==="and"?`(${r} && ${n})`:e.operator==="or"?`(${r} || ${n})`:`(${r} + ${n})`},Be=(e,t)=>{if(!e.children||e.children.length<1)return"0.0";let r=e.mathFunction,n=e.children.map(l=>E(l,t)),[o,a,u]=n;return n.length===1?`${r}(${o})`:n.length===2?`${r}(${o}, ${a})`:n.length===3?`${r}(${o}, ${a}, ${u})`:o||"0.0"},ze=e=>{if(i.num(e))return"float";if(i.bol(e))return"bool";if(i.arr(e)){let t=e.length;if(t===2)return"vec2";if(t===3)return"vec3";if(t===4)return"vec4"}return"float"},L=(e,t)=>{let r=t?.precision||"mediump",o=(t?.version||"300 es")==="300 es",a=fe(e),u="";return o&&(u+=`#version 300 es
|
|
2
|
+
`),u+=`precision ${r} float;
|
|
3
3
|
|
|
4
|
-
`,
|
|
4
|
+
`,t?.uniforms&&(Object.entries(t.uniforms).forEach(([l,b])=>{let x=ze(b);u+=`uniform ${x} ${l};
|
|
5
5
|
`}),u+=`
|
|
6
6
|
`),o&&(u+=`out vec4 fragColor;
|
|
7
7
|
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
`,u+=o?` fragColor = ${a};
|
|
10
10
|
`:` gl_FragColor = ${a};
|
|
11
11
|
`,u+=`}
|
|
12
|
-
`,u};var
|
|
12
|
+
`,u};var pe=`
|
|
13
13
|
#version 300 es
|
|
14
14
|
void main() {
|
|
15
15
|
float x = float(gl_VertexID % 2) * 4.0 - 1.0;
|
|
16
16
|
float y = float(gl_VertexID / 2) * 4.0 - 1.0;
|
|
17
17
|
gl_Position = vec4(x, y, 0.0, 1.0);
|
|
18
18
|
}
|
|
19
|
-
`,
|
|
19
|
+
`,me=`
|
|
20
20
|
#version 300 es
|
|
21
21
|
precision mediump float;
|
|
22
22
|
uniform vec2 iResolution;
|
|
@@ -24,23 +24,25 @@ out vec4 fragColor;
|
|
|
24
24
|
void main() {
|
|
25
25
|
fragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
|
|
26
26
|
}
|
|
27
|
-
`,
|
|
28
|
-
`}),
|
|
29
|
-
`),
|
|
30
|
-
`,
|
|
31
|
-
`;let n=
|
|
32
|
-
`,
|
|
33
|
-
`,
|
|
27
|
+
`,ce=(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);throw e.deleteShader(n),new Error(`Could not compile shader: ${o}`)},F=(e,t=pe,r=me)=>{i.obj(r)&&(r=L(r)),i.obj(t)&&(t=L(t));let n=e.createProgram();if(e.attachShader(n,ce(e,t,e.VERTEX_SHADER)),e.attachShader(n,ce(e,r,e.FRAGMENT_SHADER)),e.linkProgram(n),e.getProgramParameter(n,e.LINK_STATUS))return n;let o=e.getProgramInfoLog(n);throw e.deleteProgram(n),new Error(`Could not link pg: ${o}`)},M=(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},I=(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},B=(e,t,r)=>{r&&(e=Math.max(...r)+1);let n=t.length/e;return Math.floor(n)},z=(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)},O=(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 W=async e=>{let t=e.el.getContext("webgl2"),r=F(t,e.vs,e.fs),n={context:t,program:r};t.useProgram(r);let o=0,a=(0,N.nested)(()=>o++),u=(0,N.nested)(p=>t.getUniformLocation(r,p)),l=(0,N.nested)(p=>t.getAttribLocation(r,p));return{webgl:n,render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(r),_attribute:(p="",f,c)=>{let m=l(p,!0),T=M(t,f),A=I(t,c),$e=B(e.count,f,c);z(t,$e,m,T,A)},_uniform:(p,f)=>{let c=u(p);if(i.num(f))return t.uniform1f(c,f);let m=f.length;if(m<=4)return t[`uniform${m}fv`](c,f);m=Math.sqrt(m)<<0,t[`uniformMatrix${m}fv`](c,!1,f)},_texture:(p,f)=>{let c=new Image;Object.assign(c,{src:f,alt:p,crossOrigin:"anonymous"}),c.decode().then(()=>{let m=u(c.alt),T=a(c.alt);O(t,c,m,T)})}}};var le=(e,t)=>{let r={target:"webgpu",nodes:new Map,variables:new Map,functions:new Map,...t};return w(e,r)},w=(e,t)=>e?e.value!==void 0?Oe(e.value,e.type):e.property&&e.parent?`${w(e.parent,t)}.${e.property}`:e.operator&&e.children&&e.children.length>=2?We(e,t):e.mathFunction&&e.children&&e.children.length>=1?De(e,t):"0.0":"0.0",Oe=(e,t)=>{if(t==="float"){let r=Number(e);return r%1===0?`${r}.0`:`${r}`}if(t==="int")return`${Math.floor(Number(e))}`;if(t==="bool")return e?"true":"false";if(i.arr(e)){let r=e.map(n=>{let o=Number(n);return o%1===0?`${o}.0`:`${o}`}).join(", ");if(t==="vec2")return`vec2<f32>(${r})`;if(t==="vec3")return`vec3<f32>(${r})`;if(t==="vec4")return`vec4<f32>(${r})`;if(t==="color")return`vec3<f32>(${r})`}return"0.0"},We=(e,t)=>{if(!e.children||e.children.length<2)return"0.0";let r=w(e.children[0],t),n=w(e.children[1],t);return e.operator==="add"?`(${r} + ${n})`:e.operator==="sub"?`(${r} - ${n})`:e.operator==="mul"?`(${r} * ${n})`:e.operator==="div"?`(${r} / ${n})`:e.operator==="mod"?`(${r} % ${n})`:e.operator==="equal"?`(${r} == ${n})`:e.operator==="notEqual"?`(${r} != ${n})`:e.operator==="lessThan"?`(${r} < ${n})`:e.operator==="lessThanEqual"?`(${r} <= ${n})`:e.operator==="greaterThan"?`(${r} > ${n})`:e.operator==="greaterThanEqual"?`(${r} >= ${n})`:e.operator==="and"?`(${r} && ${n})`:e.operator==="or"?`(${r} || ${n})`:`(${r} + ${n})`},De=(e,t)=>{if(!e.children||e.children.length<1)return"0.0";let r=e.mathFunction,n=e.children.map(l=>w(l,t)),[o,a,u]=n;return n.length===1?`${r}(${o})`:n.length===2?`${r}(${o}, ${a})`:n.length===3?`${r}(${o}, ${a}, ${u})`:o||"0.0"},S=(e,t)=>{let r="";t?.uniforms&&(Object.entries(t.uniforms).forEach(([o,a])=>{let u=qe(a);r+=`@group(0) @binding(0) var<uniform> ${o}: ${u};
|
|
28
|
+
`}),r+=`
|
|
29
|
+
`),r+=`@fragment
|
|
30
|
+
`,r+=`fn main() -> @location(0) vec4<f32> {
|
|
31
|
+
`;let n=le(e);return r+=` return ${n};
|
|
32
|
+
`,r+=`}
|
|
33
|
+
`,r},qe=e=>{if(i.num(e))return"f32";if(i.bol(e))return"bool";if(i.arr(e)){let t=e.length;if(t===2)return"vec2<f32>";if(t===3)return"vec3<f32>";if(t===4)return"vec4<f32>"}return"f32"};var Ve=`
|
|
34
34
|
@vertex
|
|
35
35
|
fn main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4f {
|
|
36
36
|
let x = f32(vertex_index % 2u) * 4.0 - 1.0;
|
|
37
37
|
let y = f32(vertex_index / 2u) * 4.0 - 1.0;
|
|
38
38
|
return vec4f(x, y, 0.0, 1.0);
|
|
39
39
|
}
|
|
40
|
-
`,
|
|
40
|
+
`,je=`
|
|
41
|
+
@group(0) @binding(0) var<uniform> iResolution: vec2f;
|
|
42
|
+
|
|
41
43
|
@fragment
|
|
42
44
|
fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
|
43
|
-
return vec4f(position.xy /
|
|
45
|
+
return vec4f(position.xy / iResolution, 0.0, 1.0);
|
|
44
46
|
}
|
|
45
|
-
`,W=(e,r,t=Oe,n=qe,o)=>e.createRenderPipeline({vertex:{module:e.createShaderModule({code:t.trim()}),entryPoint:"main",buffers:o},fragment:{module:e.createShaderModule({code:n.trim()}),entryPoint:"main",targets:[{format:r}]},layout:"auto",primitive:{topology:"triangle-list"}}),O=e=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),ue=e=>Math.ceil(e/256)*256,Ve=(e,r)=>e.createBuffer({size:ue(r),usage:68}),ke=(e,r)=>{let t=new Float32Array(r),n=e.createBuffer({size:t.byteLength,usage:36});return e.queue.writeBuffer(n,0,t),n},fe=(e,r,t)=>{let n=r.getBindGroupLayout(0);return e.createBindGroup({layout:n,entries:t})},He=(e,r,t,n={},o=null)=>{let a=[{binding:0,resource:{buffer:t}}],u=1;return Object.values(n).forEach(p=>{a.push({binding:u++,resource:p.createView()})}),o&&Object.keys(n).length>0&&a.push({binding:u++,resource:o}),fe(e,r,a)},je=(e,r,t,n=0)=>{e.queue.writeBuffer(r,n,t)},Ye=(e,r)=>{let t=e.createTexture({size:{width:r.width,height:r.height},format:"rgba8unorm",usage:6});return e.queue.copyExternalImageToTexture({source:r},{texture:t},{width:r.width,height:r.height}),t},Ke=e=>e.createSampler({magFilter:"linear",minFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}),Ze=()=>new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]);var Qe=3,q=async e=>{let r=e.vs||e.vert||e.vertex,t=e.fs||e.frag||e.fragment;i.obj(r)&&(r=L(r)),i.obj(t)&&(t=L(t));let n=e.el.getContext("webgpu"),o=navigator.gpu,u=await(await o.requestAdapter()).requestDevice(),p=o.getPreferredCanvasFormat();n.configure({device:u,format:p,alphaMode:"opaque"}),e("clean",()=>{});let g;return e("render",()=>{g||(g=W(u,p,r,t,[]));let h=u.createCommandEncoder(),l=h.beginRenderPass(O(n));l.setPipeline(g),l.draw(Qe,1,0,0),l.end(),u.queue.submit([h.finish()])}),e("_attribute",(h="",l)=>{}),e("_uniform",(h,l=0)=>{}),e("_texture",(h,l)=>{}),e};var Je=["float","int","uint","bool","color","vec2","vec3","vec4","mat2","mat3","mat4","ivec2","ivec3","ivec4","uvec2","uvec3","uvec4","bvec2","bvec3","bvec4"],V=["x","y","z","w","r","g","b","a","s","t","p","q"],k=["add","sub","mul","div","mod","equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual","and","or","not","assign","xor","bitAnd","bitNot","bitOr","bitXor","shiftLeft","shiftRight"],H=["abs","acos","asin","atan","atan2","ceil","clamp","cos","cross","degrees","distance","dot","exp","exp2","faceforward","floor","fract","length","all","any","bitcast","cbrt","dFdx","dFdy","difference","equals","fwidth","inverseSqrt","lengthSq","log","log2","max","min","mix","negate","normalize","oneMinus","pow","pow2","pow3","pow4","radians","reciprocal","reflect","refract","round","saturate","sign","sin","smoothstep","sqrt","step","tan","transformDirection","trunc"],j=[!0,!1],Y=[0,1,2,3,4,5],K=[0,1,.5,2];var Z=new Map,Q=new Map,J=new Map,er=()=>{j.forEach(e=>{Z.set(e,s("bool",e))}),Y.forEach(e=>{Q.set(e,s("int",e))}),K.forEach(e=>{J.set(e,s("float",e))})},N=e=>(Z.has(e)||er(),Z.get(e)||s("bool",e)),C=e=>Q.has(e)?Q.get(e):s("int",e),G=e=>J.has(e)?J.get(e):s("float",e),rr=e=>{let r=new Map,t=new Map;return e.forEach(n=>{let o=tr(n);t.has(o)?(r.has(o)||r.set(o,[t.get(o)]),r.get(o).push(n)):t.set(o,n)}),r},tr=e=>[e.type,`${e.value}`,e.property||""].join("|");var nr=e=>i.bol(e)?N(e):i.num(e)?i.int(e)?C(e):G(e):i.arr(e)?ce(e):i.obj(e)?or(e):s("float",0),ce=e=>{let r=e.length;return r===2?s("vec2",e):r===3?s("vec3",e):r===4?s("vec4",e):r===9?s("mat3",e):r===16?s("mat4",e):s("float",e[0])},or=e=>{if("r"in e&&"g"in e&&"b"in e){let r=[e.r,e.g,e.b];return"a"in e&&r.push(e.a),s("color",r)}if("x"in e&&"y"in e){let r=[e.x,e.y];return"z"in e&&r.push(e.z),"w"in e&&r.push(e.w),ce(r)}return s("float",0)},S=e=>i.num(e)?G(e):s("float",Number(e)),ir=e=>i.num(e)&&Number.isInteger(e)?C(e):s("int",Math.floor(Number(e))),ar=e=>N(!!e),sr=(e,r)=>i.und(e)?s("vec2",[0,0]):i.und(r)?i.arr(e)?s("vec2",e.slice(0,2)):i.obj(e)&&"x"in e&&"y"in e?s("vec2",[e.x,e.y]):s("vec2",[Number(e),Number(e)]):s("vec2",[Number(e),Number(r)]),pe=(e,r,t)=>i.und(e)?s("vec3",[0,0,0]):i.und(r)?i.arr(e)?s("vec3",e.slice(0,3)):i.obj(e)&&"x"in e&&"y"in e&&"z"in e?s("vec3",[e.x,e.y,e.z]):s("vec3",[Number(e),Number(e),Number(e)]):t===void 0?s("vec3",[Number(e),Number(r),0]):s("vec3",[Number(e),Number(r),Number(t)]),ur=(e,r,t,n)=>i.und(e)?s("vec4",[0,0,0,1]):i.und(r)?i.arr(e)?s("vec4",e.slice(0,4)):i.obj(e)&&"x"in e&&"y"in e&&"z"in e&&"w"in e?s("vec4",[e.x,e.y,e.z,e.w]):s("vec4",[Number(e),Number(e),Number(e),1]):s("vec4",[Number(e),Number(r),Number(t),Number(n)]),fr=(e,r,t)=>{if(e===void 0)return s("color",[1,1,1]);if(i.str(e)&&e.startsWith("#")){let n=e.slice(1),o=parseInt(n,16);return s("color",[(o>>16&255)/255,(o>>8&255)/255,(o&255)/255])}return i.num(e)&&r===void 0&&t===void 0?s("color",[(e>>16&255)/255,(e>>8&255)/255,(e&255)/255]):pe(e,r,t)};var cr=0,pr=()=>`node_${++cr}`,w=(e,r,t)=>({id:pr(),type:e,value:r,children:[],...t}),lr=(e="")=>V.includes(e),mr=(e="")=>k.includes(e),dr=(e="")=>H.includes(e),R=(e,r)=>{let t=(o,a)=>{if(!(!i.str(a)||a==="then"))return a==="id"?e.id:a==="type"?e.type:a==="value"?e.value:a==="property"?e.property:lr(a)?R(w(gr(a),void 0,{parent:e,property:a}),r):mr(a)?(...u)=>R(w(e.type,void 0,{operator:a,children:[e,...u]}),r):dr(a)?(...u)=>R(w(hr(a,e.type),void 0,{mathFunction:a,children:[e,...u]}),r):r?.({path:[a],args:[]})},n=(o,a,u)=>r?.({path:[],args:u});return new Proxy(()=>{},{get:t,apply:n})},gr=e=>e.length===1?"float":e.length===2?"vec2":e.length===3?"vec3":e.length===4?"vec4":"float",hr=(e,r)=>e==="length"?"float":r,s=(e,r,t)=>{let n=w(e,r,t);return R(n)};var br=e=>{if(i.num(e))return"float";if(i.bol(e))return"bool";if(i.arr(e)){let r=e.length;if(r===2)return"vec2";if(r===3)return"vec3";if(r===4)return"vec4";if(r===9)return"mat3";if(r===16)return"mat4"}return i.obj(e)&&"r"in e&&"g"in e&&"b"in e?"color":"float"},x=e=>{let r=br(e),t=e,n=null,o=null,a=s(r,t),u=f=>{t=f,a.value=f},p=f=>(n=f,l),g=f=>(o=f,l),h=f=>{if(n){let c=n(f);c!==void 0&&u(c)}if(o){let c=o(f);c!==void 0&&u(c)}},l=Object.create(a);return l.set=u,l.onObjectUpdate=p,l.onRenderUpdate=g,l._updateFromContext=h,l.isUniform=!0,l},le=x(0),me=x(0),de=x(0),mt=x([1920,1080]),dt=x([0,0]),xr=e=>{if(e.time!==void 0){let r=le.value||0;le.set(e.time),me.set(r),de.set(e.time-r)}};var yr=e=>{let r=(...t)=>{let n=t.map(a=>i.obj(a)&&"type"in a&&a.type?a:S(a));return e(n)||S(0)};return r.call=t=>e(t),r},vr=(e,r)=>{r();let t={ElseIf(n,o){return o(),t},Else(n){n()}};return t},Tr=s("vec4",void 0),Er=s("vec4",void 0),wr=x(0),$r=x([1920,1080]),Lr=x([0,0]),Nr=e=>e.abs(),Cr=e=>e.sin(),Gr=e=>e.cos(),Sr=e=>e.tan(),Rr=e=>e.sqrt(),Ur=e=>e.floor(),_r=e=>e.ceil(),Pr=e=>e.fract(),Ar=e=>e.normalize(),Xr=e=>e.length();var re=e=>i.obj(e)?"isGL"in e:!1,he=()=>typeof window>"u",be=()=>he()?!1:"gpu"in navigator,U=performance.now(),ee=0,ge=0,te=e=>{let r=(0,y.event)({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:3,webgl:{},webgpu:{}});return r.queue=(0,_.createQueue)(),r.frame=(0,_.createFrame)(),r.attribute=(0,y.durable)((t,n,o)=>r.queue(()=>r._attribute?.(t,n,o))),r.uniform=(0,y.durable)((t,n,o)=>r.queue(()=>r._uniform?.(t,n,o))),r.texture=(0,y.durable)((t,n)=>r.queue(()=>r._texture?.(t,n))),r("mount",async()=>{be()||(r.isWebGL=!0),r.isWebGL?await z(r):await q(r),r.resize(),r.frame(()=>(r.loop(),r.render(),r.isLoop)),!r.isNative&&(window.addEventListener("resize",r.resize),r.el.addEventListener("mousemove",r.mousemove))}),r("clean",()=>{r.frame.stop(),r.frame.clean(r.render),!r.isNative&&(window.removeEventListener("resize",r.resize),r.el.removeEventListener("mousemove",r.mousemove))}),r("loop",()=>{ee=U,U=performance.now()/1e3,ge=U-ee,r.uniform({iPrevTime:ee,iTime:U,iDeltaTime:ge})}),r("resize",()=>{let t=r.width||window.innerWidth,n=r.height||window.innerHeight;r.size[0]=r.el.width=t,r.size[1]=r.el.height=n,r.uniform("iResolution",r.size)}),r("mousemove",(t,n=t.clientX,o=t.clientY)=>{let[a,u]=r.size,{top:p,left:g}=r.el.getBoundingClientRect();r.mouse[0]=(n-p-a/2)/(a/2),r.mouse[1]=-(o-g-u/2)/(u/2),r.uniform("iMouse",r.mouse)}),r(e)};var Fr=(e={})=>(0,xe.useState)(()=>{let r=re(e)?e:te(e);return r.ref=t=>{r.el={},r({render(){t.flush(),t.endFrameEXP()}}),r.mount();let n=()=>{r.width=t.drawingBufferWidth,r.height=t.drawingBufferHeight,r.resize()};n(),ye.Dimensions.addEventListener("change",n)},r({isNative:!0})})[0];0&&(module.exports={CACHE_BOOLS,CACHE_FLOATS,CACHE_INTS,FUNCTIONS,Fn,If,OPERATORS,SWIZZLES,TYPES,abs,activeTexture,alignTo256,bool,ceil,color,convertToNode,cos,createAttrib,createBindGroup,createDescriptor,createDeviceTexture,createGL,createIbo,createNode,createProgram,createRenderPipeline,createSampler,createShader,createTexture,createUniform,createUniformBuffer,createVbo,createVertexBuffer,defaultFragmentGLSL,defaultVertexGLSL,dig,each,ext,fig,findDuplicateNodes,float,floor,flush,fract,getCachedBool,getCachedFloat,getCachedInt,getDefaultVertices,gl_FragCoord,gl_Position,glsl,iDeltaTime,iMouse,iPrevTime,iResolution,iTime,initWebGPUDevice,int,is,isGL,isServer,isWebGPUSupported,length,node,nodeToGLSL,nodeToWGSL,normalize,replace,sig,sin,sqrt,tan,uniform,updateBindGroup,updateUniforms,useGL,vec2,vec3,vec4,webgl,webgpu,wgsl});
|
|
47
|
+
`,D=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}},q=(e,t,r,n,o=Ve,a=je)=>{i.obj(a)&&(a=S(a)),i.obj(o)&&(o=S(o));let u=e.createPipelineLayout({bindGroupLayouts:n});return e.createRenderPipeline({vertex:{module:e.createShaderModule({code:o.trim()}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({code:a.trim()}),entryPoint:"main",targets:[{format:t}]},layout:u,primitive:{topology:"triangle-list"}})},V=(e,t)=>{let r=[],n=[];t.forEach((u,l)=>{if(!u)return;let b="buffer"in u,x=u instanceof GPUTextureView,d=u instanceof GPUSampler;if(b)r.push({binding:l,visibility:3,buffer:{type:"uniform"}});else if(x)r.push({binding:l,visibility:2,texture:{}});else if(d)r.push({binding:l,visibility:2,sampler:{}});else return;n.push({binding:l,resource:u})});let o=e.createBindGroupLayout({entries:r}),a=e.createBindGroup({layout:o,entries:n});return[o,a]},j=e=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),de=e=>Math.ceil(e/256)*256,H=(e,t)=>{let r=new Float32Array(t),n=de(r.byteLength),o=e.createBuffer({size:n,usage:72});return{array:r,buffer:o}},Y=(e,t=1280,r=800)=>{let n=e.createTexture({size:[t,r],format:"rgba8unorm",usage:22}),o=e.createSampler({magFilter:"linear",minFilter:"linear"});return[n,o]};var k=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:n}=await D(t),o={device:r,context:t,uniforms:{},textures:{},resources:[[],[]],loadingImg:0,needsUpdate:!0},a=p=>{let{array:f,buffer:c}=H(r,p);return o.resources[0].push({buffer:c}),o.needsUpdate=!0,{array:f,buffer:c}},u=p=>{let{width:f,height:c}=p,[m,T]=Y(r,f,c);return o.resources[1].push(T,m.createView()),o.needsUpdate=!0,{texture:m,width:f,height:c}},l=()=>{let p=[];o.groups=[],o.resources.forEach(f=>{if(!f.length)return;let[c,m]=V(r,f);p.push(c),o.groups.push(m)}),o.pipeline=q(r,n,[],p,e.vs,e.fs)};return{webgpu:o,render:()=>{if(o.loadingImg)return;o.needsUpdate&&l(),o.needsUpdate=!1;let p=r.createCommandEncoder(),f=p.beginRenderPass(j(t));f.setPipeline(o.pipeline),o.groups.forEach((c,m)=>f.setBindGroup(m,c)),f.draw(e.count,1,0,0),f.end(),r.queue.submit([p.finish()])},clean:()=>{},_attribute:(p="",f)=>{},_uniform:(p,f)=>{i.num(f)&&(f=[f]),o.uniforms[p]||(o.uniforms[p]=a(f));let{array:c,buffer:m}=o.uniforms[p];c.set(f),r.queue.writeBuffer(m,0,c)},_texture:(p,f)=>{o.loadingImg++;let c=Object.assign(new Image,{src:f,crossOrigin:"anonymous"});c.decode().then(()=>{o.textures[p]||(o.textures[p]=u(c));let{texture:m,width:T,height:A}=o.textures[p];r.queue.copyExternalImageToTexture({source:c},{texture:m},{width:T,height:A}),o.loadingImg--})}}};var He=["float","int","uint","bool","color","vec2","vec3","vec4","mat2","mat3","mat4","ivec2","ivec3","ivec4","uvec2","uvec3","uvec4","bvec2","bvec3","bvec4"],K=["x","y","z","w","r","g","b","a","s","t","p","q"],Z=["add","sub","mul","div","mod","equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual","and","or","not","assign","xor","bitAnd","bitNot","bitOr","bitXor","shiftLeft","shiftRight"],Q=["abs","acos","asin","atan","atan2","ceil","clamp","cos","cross","degrees","distance","dot","exp","exp2","faceforward","floor","fract","length","all","any","bitcast","cbrt","dFdx","dFdy","difference","equals","fwidth","inverseSqrt","lengthSq","log","log2","max","min","mix","negate","normalize","oneMinus","pow","pow2","pow3","pow4","radians","reciprocal","reflect","refract","round","saturate","sign","sin","smoothstep","sqrt","step","tan","transformDirection","trunc"],J=[!0,!1],ee=[0,1,2,3,4,5],te=[0,1,.5,2];var re=new Map,ne=new Map,oe=new Map,Ye=()=>{J.forEach(e=>{re.set(e,s("bool",e))}),ee.forEach(e=>{ne.set(e,s("int",e))}),te.forEach(e=>{oe.set(e,s("float",e))})},C=e=>(re.has(e)||Ye(),re.get(e)||s("bool",e)),G=e=>ne.has(e)?ne.get(e):s("int",e),R=e=>oe.has(e)?oe.get(e):s("float",e),ke=e=>{let t=new Map,r=new Map;return e.forEach(n=>{let o=Ke(n);r.has(o)?(t.has(o)||t.set(o,[r.get(o)]),t.get(o).push(n)):r.set(o,n)}),t},Ke=e=>[e.type,`${e.value}`,e.property||""].join("|");var Ze=e=>i.bol(e)?C(e):i.num(e)?i.int(e)?G(e):R(e):i.arr(e)?ge(e):i.obj(e)?Qe(e):s("float",0),ge=e=>{let t=e.length;return t===2?s("vec2",e):t===3?s("vec3",e):t===4?s("vec4",e):t===9?s("mat3",e):t===16?s("mat4",e):s("float",e[0])},Qe=e=>{if("r"in e&&"g"in e&&"b"in e){let t=[e.r,e.g,e.b];return"a"in e&&t.push(e.a),s("color",t)}if("x"in e&&"y"in e){let t=[e.x,e.y];return"z"in e&&t.push(e.z),"w"in e&&t.push(e.w),ge(t)}return s("float",0)},_=e=>i.num(e)?R(e):s("float",Number(e)),Je=e=>i.num(e)&&Number.isInteger(e)?G(e):s("int",Math.floor(Number(e))),et=e=>C(!!e),tt=(e,t)=>i.und(e)?s("vec2",[0,0]):i.und(t)?i.arr(e)?s("vec2",e.slice(0,2)):i.obj(e)&&"x"in e&&"y"in e?s("vec2",[e.x,e.y]):s("vec2",[Number(e),Number(e)]):s("vec2",[Number(e),Number(t)]),he=(e,t,r)=>i.und(e)?s("vec3",[0,0,0]):i.und(t)?i.arr(e)?s("vec3",e.slice(0,3)):i.obj(e)&&"x"in e&&"y"in e&&"z"in e?s("vec3",[e.x,e.y,e.z]):s("vec3",[Number(e),Number(e),Number(e)]):r===void 0?s("vec3",[Number(e),Number(t),0]):s("vec3",[Number(e),Number(t),Number(r)]),rt=(e,t,r,n)=>i.und(e)?s("vec4",[0,0,0,1]):i.und(t)?i.arr(e)?s("vec4",e.slice(0,4)):i.obj(e)&&"x"in e&&"y"in e&&"z"in e&&"w"in e?s("vec4",[e.x,e.y,e.z,e.w]):s("vec4",[Number(e),Number(e),Number(e),1]):s("vec4",[Number(e),Number(t),Number(r),Number(n)]),nt=(e,t,r)=>{if(e===void 0)return s("color",[1,1,1]);if(i.str(e)&&e.startsWith("#")){let n=e.slice(1),o=parseInt(n,16);return s("color",[(o>>16&255)/255,(o>>8&255)/255,(o&255)/255])}return i.num(e)&&t===void 0&&r===void 0?s("color",[(e>>16&255)/255,(e>>8&255)/255,(e&255)/255]):he(e,t,r)};var ot=0,it=()=>`node_${++ot}`,$=(e,t,r)=>({id:it(),type:e,value:t,children:[],...r}),at=(e="")=>K.includes(e),st=(e="")=>Z.includes(e),ut=(e="")=>Q.includes(e),U=(e,t)=>{let r=(o,a)=>{if(!(!i.str(a)||a==="then"))return a==="id"?e.id:a==="type"?e.type:a==="value"?e.value:a==="property"?e.property:at(a)?U($(ft(a),void 0,{parent:e,property:a}),t):st(a)?(...u)=>U($(e.type,void 0,{operator:a,children:[e,...u]}),t):ut(a)?(...u)=>U($(ct(a,e.type),void 0,{mathFunction:a,children:[e,...u]}),t):t?.({path:[a],args:[]})},n=(o,a,u)=>t?.({path:[],args:u});return new Proxy(()=>{},{get:r,apply:n})},ft=e=>e.length===1?"float":e.length===2?"vec2":e.length===3?"vec3":e.length===4?"vec4":"float",ct=(e,t)=>e==="length"?"float":t,s=(e,t,r)=>{let n=$(e,t,r);return U(n)};var pt=e=>{if(i.num(e))return"float";if(i.bol(e))return"bool";if(i.arr(e)){let t=e.length;if(t===2)return"vec2";if(t===3)return"vec3";if(t===4)return"vec4";if(t===9)return"mat3";if(t===16)return"mat4"}return i.obj(e)&&"r"in e&&"g"in e&&"b"in e?"color":"float"},h=e=>{let t=pt(e),r=e,n=null,o=null,a=s(t,r),u=g=>{r=g,a.value=g},l=g=>(n=g,d),b=g=>(o=g,d),x=g=>{if(n){let y=n(g);y!==void 0&&u(y)}if(o){let y=o(g);y!==void 0&&u(y)}},d=Object.create(a);return d.set=u,d.onObjectUpdate=l,d.onRenderUpdate=b,d._updateFromContext=x,d.isUniform=!0,d},be=h(0),xe=h(0),ye=h(0),fr=h([1920,1080]),cr=h([0,0]),mt=e=>{if(e.time!==void 0){let t=be.value||0;be.set(e.time),xe.set(t),ye.set(e.time-t)}};var lt=e=>{let t=(...r)=>{let n=r.map(a=>i.obj(a)&&"type"in a&&a.type?a:_(a));return e(n)||_(0)};return t.call=r=>e(r),t},dt=(e,t)=>{t();let r={ElseIf(n,o){return o(),r},Else(n){n()}};return r},gt=s("vec4",void 0),ht=s("vec4",void 0),bt=h(0),xt=h([1920,1080]),yt=h([0,0]),Tt=e=>e.abs(),vt=e=>e.sin(),Et=e=>e.cos(),wt=e=>e.tan(),$t=e=>e.sqrt(),Lt=e=>e.floor(),Nt=e=>e.ceil(),St=e=>e.fract(),Ct=e=>e.normalize(),Gt=e=>e.length();var ae=e=>i.obj(e)?"isGL"in e:!1,Te=()=>typeof window>"u",ve=()=>Te()?!1:"gpu"in navigator,ie=performance.now(),se=e=>{let t=(0,v.event)({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:3,webgl:{},webgpu:{}});return t.queue=(0,X.createQueue)(),t.frame=(0,X.createFrame)(),t.attribute=(0,v.durable)((r,n,o)=>t.queue(()=>t._attribute?.(r,n,o))),t.texture=(0,v.durable)((r,n)=>t.queue(()=>t._texture?.(r,n))),t.uniform=(0,v.durable)((r,n,o)=>t.queue(()=>t._uniform?.(r,n,o))),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:ie}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex,t.fs=t.fs||t.frag||t.fragment,ve()||(t.isWebGL=!0),t.isWebGL?t(await W(t)):t(await k(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[a,u]=t.size,{top:l,left:b}=t.el.getBoundingClientRect();t.mouse[0]=(n-l-a/2)/(a/2),t.mouse[1]=-(o-b-u/2)/(u/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{ie=performance.now()/1e3,t.uniform("iTime",ie)}),t(e)};var Rt=(e={})=>(0,Ee.useState)(()=>{let t=ae(e)?e:se(e);return t.ref=r=>{t.el={},t({render(){r.flush(),r.endFrameEXP()}}),t.mount();let n=()=>{t.width=r.drawingBufferWidth,t.height=r.drawingBufferHeight,t.resize()};n(),we.Dimensions.addEventListener("change",n)},t({isNative:!0})})[0];0&&(module.exports={CACHE_BOOLS,CACHE_FLOATS,CACHE_INTS,FUNCTIONS,Fn,If,OPERATORS,SWIZZLES,TYPES,abs,alignTo256,bool,ceil,color,convertToNode,cos,createAttrib,createBindGroup,createDescriptor,createDevive,createGL,createIbo,createNode,createPipeline,createProgram,createTexture,createTextureSampler,createUniformBuffer,createVbo,defaultFragmentGLSL,defaultVertexGLSL,dig,each,ext,fig,findDuplicateNodes,float,floor,flush,fract,fragCoord,getCachedBool,getCachedFloat,getCachedInt,getStride,glsl,iDeltaTime,iMouse,iPrevTime,iResolution,iTime,int,is,isGL,isServer,isWebGPUSupported,length,node,nodeToGLSL,nodeToWGSL,normalize,position,replace,sig,sin,sqrt,tan,uniform,updateUniforms,useGL,vec2,vec3,vec4,webgl,webgpu,wgsl});
|
|
46
48
|
//# sourceMappingURL=native.js.map
|