glre 0.32.0 → 0.33.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 +31 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +71 -34
- package/dist/index.js +31 -27
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +31 -27
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.ts +1 -1
- package/dist/native.js +31 -27
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +31 -27
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +31 -27
- package/dist/react.js.map +1 -1
- package/dist/solid.cjs +31 -27
- package/dist/solid.cjs.map +1 -1
- package/dist/solid.d.ts +1 -1
- package/dist/solid.js +31 -27
- package/dist/solid.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/node/code.ts +39 -34
- package/src/node/const.ts +27 -46
- package/src/node/index.ts +39 -23
- package/src/node/infer.ts +19 -7
- package/src/node/node.ts +11 -10
- package/src/node/parse.ts +70 -28
- package/src/node/scope.ts +11 -5
- package/src/node/types.ts +21 -12
- package/src/node/utils.ts +65 -13
- package/src/types.ts +1 -0
- package/src/utils/pipeline.ts +65 -76
- package/src/utils/program.ts +7 -14
- package/src/webgl.ts +6 -1
- package/src/webgpu.ts +39 -24
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,32 @@ import { Queue, Frame } from 'refr';
|
|
|
3
3
|
export { Frame, Fun, Queue } from 'refr';
|
|
4
4
|
import { Nested, EventState } from 'reev';
|
|
5
5
|
|
|
6
|
-
declare const
|
|
6
|
+
declare const TYPE_MAPPING: {
|
|
7
|
+
readonly bool: "bool";
|
|
8
|
+
readonly uint: "u32";
|
|
9
|
+
readonly int: "i32";
|
|
10
|
+
readonly float: "f32";
|
|
11
|
+
readonly bvec2: "vec2<bool>";
|
|
12
|
+
readonly ivec2: "vec2i";
|
|
13
|
+
readonly uvec2: "vec2u";
|
|
14
|
+
readonly vec2: "vec2f";
|
|
15
|
+
readonly bvec3: "vec3<bool>";
|
|
16
|
+
readonly ivec3: "vec3i";
|
|
17
|
+
readonly uvec3: "vec3u";
|
|
18
|
+
readonly vec3: "vec3f";
|
|
19
|
+
readonly bvec4: "vec4<bool>";
|
|
20
|
+
readonly ivec4: "vec4i";
|
|
21
|
+
readonly uvec4: "vec4u";
|
|
22
|
+
readonly vec4: "vec4f";
|
|
23
|
+
readonly color: "color";
|
|
24
|
+
readonly mat2: "mat2x2f";
|
|
25
|
+
readonly mat3: "mat3x3f";
|
|
26
|
+
readonly mat4: "mat4x4f";
|
|
27
|
+
readonly texture: "texture_2d<f32>";
|
|
28
|
+
readonly sampler2D: "sampler";
|
|
29
|
+
readonly struct: "struct";
|
|
30
|
+
};
|
|
31
|
+
declare const CONSTANTS: keyof typeof TYPE_MAPPING;
|
|
7
32
|
declare const CONVERSIONS: readonly ["toBool", "toUint", "toInt", "toFloat", "toBvec2", "toIvec2", "toUvec2", "toVec2", "toBvec3", "toIvec3", "toUvec3", "toVec3", "toBvec4", "toIvec4", "toUvec4", "toVec4", "toColor", "toMat2", "toMat3", "toMat4"];
|
|
8
33
|
declare const OPERATORS: {
|
|
9
34
|
readonly add: "+";
|
|
@@ -43,7 +68,7 @@ interface FnLayout {
|
|
|
43
68
|
/**
|
|
44
69
|
* Node
|
|
45
70
|
*/
|
|
46
|
-
type NodeTypes = 'attribute' | 'uniform' | 'constant' | 'variable' | 'varying' | '
|
|
71
|
+
type NodeTypes = 'attribute' | 'uniform' | 'constant' | 'variable' | 'varying' | 'ternary' | 'builtin' | 'conversion' | 'operator' | 'function' | 'struct' | 'member' | 'scope' | 'assign' | 'loop' | 'define' | 'if' | 'switch' | 'declare' | 'return';
|
|
47
72
|
interface NodeProps {
|
|
48
73
|
id?: string;
|
|
49
74
|
args?: X[];
|
|
@@ -52,19 +77,24 @@ interface NodeProps {
|
|
|
52
77
|
inferFrom?: X[];
|
|
53
78
|
layout?: FnLayout;
|
|
54
79
|
parent?: NodeProxy;
|
|
80
|
+
fields?: Record<string, NodeProxy>;
|
|
81
|
+
initialValues?: Record<string, NodeProxy>;
|
|
55
82
|
}
|
|
56
83
|
interface NodeContext {
|
|
84
|
+
gl?: Partial<GL>;
|
|
57
85
|
isFrag?: boolean;
|
|
58
86
|
isWebGL?: boolean;
|
|
59
87
|
binding?: number;
|
|
60
88
|
infers?: WeakMap<NodeProxy, Constants>;
|
|
61
89
|
onMount?: (name: string) => void;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
90
|
+
code?: {
|
|
91
|
+
headers: Map<string, string>;
|
|
92
|
+
fragInputs: Map<string, string>;
|
|
93
|
+
vertInputs: Map<string, string>;
|
|
94
|
+
vertOutputs: Map<string, string>;
|
|
95
|
+
vertVaryings: Map<string, string>;
|
|
96
|
+
dependencies: Map<string, Set<string>>;
|
|
97
|
+
};
|
|
68
98
|
}
|
|
69
99
|
/**
|
|
70
100
|
* NodeProxy
|
|
@@ -72,8 +102,8 @@ interface NodeContext {
|
|
|
72
102
|
type _Swizzles<T extends string> = T | `${T}${T}` | `${T}${T}${T}` | `${T}${T}${T}${T}`;
|
|
73
103
|
type Swizzles = _Swizzles<'x' | 'y' | 'z' | 'w'> | _Swizzles<'r' | 'g' | 'b' | 'a'> | _Swizzles<'p' | 'q'> | _Swizzles<'s' | 't'>;
|
|
74
104
|
type NodeProxyMethods = Functions | Operators | Conversions | Swizzles | 'type' | 'props' | 'isProxy' | 'assign' | 'toVar' | 'toString';
|
|
75
|
-
type
|
|
76
|
-
[K in string as K extends NodeProxyMethods ? never : K]:
|
|
105
|
+
type ReadNodeProxy = {
|
|
106
|
+
[K in string as K extends NodeProxyMethods ? never : K]: X;
|
|
77
107
|
};
|
|
78
108
|
interface BaseNodeProxy extends Record<Swizzles, NodeProxy> {
|
|
79
109
|
assign(n: X): NodeProxy;
|
|
@@ -82,6 +112,7 @@ interface BaseNodeProxy extends Record<Swizzles, NodeProxy> {
|
|
|
82
112
|
type: NodeTypes;
|
|
83
113
|
props: NodeProps;
|
|
84
114
|
isProxy: true;
|
|
115
|
+
listeners: Set<(value: any) => void>;
|
|
85
116
|
add(n: X): NodeProxy;
|
|
86
117
|
sub(n: X): NodeProxy;
|
|
87
118
|
mul(n: X): NodeProxy;
|
|
@@ -161,8 +192,8 @@ interface BaseNodeProxy extends Record<Swizzles, NodeProxy> {
|
|
|
161
192
|
dFdy(): NodeProxy;
|
|
162
193
|
fwidth(): NodeProxy;
|
|
163
194
|
}
|
|
164
|
-
type NodeProxy = BaseNodeProxy &
|
|
165
|
-
type X = NodeProxy | number | string | boolean | undefined;
|
|
195
|
+
type NodeProxy = BaseNodeProxy & ReadNodeProxy;
|
|
196
|
+
type X = X[] | (NodeProxy | number | string | boolean | undefined);
|
|
166
197
|
|
|
167
198
|
declare const code: (target: X, c?: NodeContext | null) => string;
|
|
168
199
|
|
|
@@ -173,15 +204,16 @@ declare const uniform: (x: X, id?: string) => NodeProxy;
|
|
|
173
204
|
declare const variable: (id?: string) => NodeProxy;
|
|
174
205
|
declare const builtin: (id?: string) => NodeProxy;
|
|
175
206
|
declare const vertexStage: (x: X, id?: string) => NodeProxy;
|
|
176
|
-
declare const swizzle: (key: Swizzles, x: X) => NodeProxy;
|
|
177
207
|
declare const operator: (key: Operators, ...x: X[]) => NodeProxy;
|
|
178
208
|
declare const function_: (key: Functions, ...x: X[]) => NodeProxy;
|
|
179
209
|
declare const conversion: (key: string, ...x: X[]) => NodeProxy;
|
|
210
|
+
declare const member: (key: string, x: X) => NodeProxy;
|
|
180
211
|
declare const select: (x: X, y: X, z: X) => NodeProxy;
|
|
181
212
|
|
|
182
213
|
declare const toVar: (x: X, id?: string) => NodeProxy;
|
|
183
214
|
declare const assign: (x: X, y: X) => X;
|
|
184
215
|
declare const Return: (x: X) => NodeProxy;
|
|
216
|
+
declare const struct: (fields: Record<string, NodeProxy>, id?: string) => (initialValues?: Record<string, NodeProxy>, instanceId?: string) => NodeProxy;
|
|
185
217
|
declare const If: (x: X, fun: () => void) => {
|
|
186
218
|
ElseIf: (_x: X, _fun: () => void) => /*elided*/ any;
|
|
187
219
|
Else: (_fun: () => void) => void;
|
|
@@ -195,7 +227,7 @@ declare const Switch: (x: X) => {
|
|
|
195
227
|
};
|
|
196
228
|
declare const Fn: (fun: (paramVars: NodeProxy[]) => NodeProxy) => {
|
|
197
229
|
(...args: X[]): NodeProxy;
|
|
198
|
-
setLayout(
|
|
230
|
+
setLayout(_layout: FnLayout): undefined;
|
|
199
231
|
};
|
|
200
232
|
|
|
201
233
|
declare const isSwizzle: (key: unknown) => key is Swizzles;
|
|
@@ -203,14 +235,18 @@ declare const isOperator: (key: unknown) => key is Operators;
|
|
|
203
235
|
declare const isFunction: (key: unknown) => key is Functions;
|
|
204
236
|
declare const isConversion: (key: unknown) => key is Conversions;
|
|
205
237
|
declare const isNodeProxy: (x: unknown) => x is NodeProxy;
|
|
206
|
-
declare const
|
|
238
|
+
declare const isConstants: (type?: unknown) => type is Constants;
|
|
207
239
|
declare const hex2rgb: (hex: number) => number[];
|
|
208
240
|
declare const getId: () => string;
|
|
209
|
-
declare const joins: (children: X[], c: NodeContext) => string;
|
|
210
241
|
declare const formatConversions: (x: X, c?: NodeContext) => string;
|
|
211
242
|
declare const getOperator: (op: X) => "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | "<=" | ">" | ">=" | "&&" | "||" | "&" | "|" | "^" | "<<" | ">>";
|
|
212
243
|
declare const getBluiltin: (id: string) => "gl_FragCoord" | "gl_VertexID" | "gl_InstanceID" | "gl_FrontFacing" | "gl_FragDepth" | "gl_SampleID" | "gl_SampleMask" | "gl_PointCoord" | "gl_FragCoord.xy";
|
|
213
244
|
declare const conversionToConstant: (conversionKey: string) => Constants;
|
|
245
|
+
declare const getEventFun: (c: NodeContext, id: string, isAttribute?: boolean, isTexture?: boolean) => (value: any) => GL | undefined;
|
|
246
|
+
declare const safeEventCall: (x: X, fun: (value: unknown) => void) => void;
|
|
247
|
+
declare const initNodeContext: (c: NodeContext) => NodeContext;
|
|
248
|
+
declare const addDependency: (c: NodeContext, id: string | undefined, type: string) => void;
|
|
249
|
+
declare const sortHeadersByDependencies: (headers: Map<string, string>, dependencies: Map<string, Set<string>>) => [string, string][];
|
|
214
250
|
|
|
215
251
|
declare const vertex: (x: X, c: NodeContext) => string;
|
|
216
252
|
declare const fragment: (x: X, c: NodeContext) => string;
|
|
@@ -230,10 +266,10 @@ declare const positionWorld: NodeProxy;
|
|
|
230
266
|
declare const positionView: NodeProxy;
|
|
231
267
|
declare const screenCoordinate: NodeProxy;
|
|
232
268
|
declare const screenUV: NodeProxy;
|
|
233
|
-
declare const float: (x
|
|
234
|
-
declare const int: (x
|
|
235
|
-
declare const uint: (x
|
|
236
|
-
declare const bool: (x
|
|
269
|
+
declare const float: (x?: X) => NodeProxy;
|
|
270
|
+
declare const int: (x?: X) => NodeProxy;
|
|
271
|
+
declare const uint: (x?: X) => NodeProxy;
|
|
272
|
+
declare const bool: (x?: X) => NodeProxy;
|
|
237
273
|
declare const vec2: (x?: X, y?: X) => NodeProxy;
|
|
238
274
|
declare const vec3: (x?: X, y?: X, z?: X) => NodeProxy;
|
|
239
275
|
declare const vec4: (x?: X, y?: X, z?: X, w?: X) => NodeProxy;
|
|
@@ -249,7 +285,7 @@ declare const uvec4: (x?: X, y?: X, z?: X, w?: X) => NodeProxy;
|
|
|
249
285
|
declare const bvec2: (x?: X, y?: X) => NodeProxy;
|
|
250
286
|
declare const bvec3: (x?: X, y?: X, z?: X) => NodeProxy;
|
|
251
287
|
declare const bvec4: (x?: X, y?: X, z?: X, w?: X) => NodeProxy;
|
|
252
|
-
declare const texture2D: () => NodeProxy;
|
|
288
|
+
declare const texture2D: (x?: X) => NodeProxy;
|
|
253
289
|
declare const sampler2D: () => NodeProxy;
|
|
254
290
|
declare const color: (r?: X, g?: X, b?: X) => NodeProxy;
|
|
255
291
|
declare const iResolution: NodeProxy;
|
|
@@ -330,6 +366,7 @@ interface TextureData {
|
|
|
330
366
|
group: number;
|
|
331
367
|
texture: GPUTexture;
|
|
332
368
|
sampler: GPUSampler;
|
|
369
|
+
view: GPUTextureView;
|
|
333
370
|
}
|
|
334
371
|
interface AttribData {
|
|
335
372
|
array: Float32Array;
|
|
@@ -462,7 +499,15 @@ declare const createBindings: () => {
|
|
|
462
499
|
location: number;
|
|
463
500
|
};
|
|
464
501
|
};
|
|
465
|
-
declare const
|
|
502
|
+
declare const createVertexBuffers: (attribs: Iterable<AttribData>) => {
|
|
503
|
+
vertexBuffers: GPUBuffer[];
|
|
504
|
+
bufferLayouts: GPUVertexBufferLayout[];
|
|
505
|
+
};
|
|
506
|
+
declare const createBindGroup: (device: GPUDevice, uniforms: Iterable<UniformData>, textures: Iterable<TextureData>) => {
|
|
507
|
+
bindGroups: GPUBindGroup[];
|
|
508
|
+
bindGroupLayouts: GPUBindGroupLayout[];
|
|
509
|
+
};
|
|
510
|
+
declare const createPipeline: (device: GPUDevice, format: GPUTextureFormat, bufferLayouts: GPUVertexBufferLayout[], bindGroupLayouts: GPUBindGroupLayout[], vs: string, fs: string) => GPURenderPipeline;
|
|
466
511
|
/**
|
|
467
512
|
* buffers
|
|
468
513
|
*/
|
|
@@ -474,25 +519,17 @@ declare const createAttribBuffer: (device: GPUDevice, value: number[]) => {
|
|
|
474
519
|
array: Float32Array<ArrayBuffer>;
|
|
475
520
|
buffer: GPUBuffer;
|
|
476
521
|
};
|
|
522
|
+
declare const createDescriptor: (c: GPUCanvasContext, depthTexture: GPUTexture) => GPURenderPassDescriptor;
|
|
477
523
|
/**
|
|
478
|
-
*
|
|
524
|
+
* textures
|
|
479
525
|
*/
|
|
480
|
-
declare const createBindGroup: (device: GPUDevice, uniforms: Map<string, UniformData>, textures: Map<string, TextureData>) => {
|
|
481
|
-
bindGroups: GPUBindGroup[];
|
|
482
|
-
bindGroupLayouts: GPUBindGroupLayout[];
|
|
483
|
-
};
|
|
484
|
-
declare const createDescriptor: (c: GPUCanvasContext, depthTexture: GPUTexture) => GPURenderPassDescriptor;
|
|
485
526
|
declare const createTextureSampler: (device: GPUDevice, width?: number, height?: number) => {
|
|
486
527
|
texture: GPUTexture;
|
|
487
528
|
sampler: GPUSampler;
|
|
488
529
|
};
|
|
489
530
|
declare const createDepthTexture: (device: GPUDevice, width: number, height: number) => GPUTexture;
|
|
490
|
-
declare const createVertexBuffers: (attribs: Map<string, AttribData>) => {
|
|
491
|
-
vertexBuffers: GPUBuffer[];
|
|
492
|
-
bufferLayouts: GPUVertexBufferLayout[];
|
|
493
|
-
};
|
|
494
531
|
|
|
495
|
-
declare const createProgram: (c: WebGLRenderingContext,
|
|
532
|
+
declare const createProgram: (c: WebGLRenderingContext, vert: string, frag: string, onError?: () => void) => void | WebGLProgram;
|
|
496
533
|
declare const createVbo: (c: WebGLRenderingContext, data: number[]) => WebGLBuffer;
|
|
497
534
|
declare const createIbo: (c: WebGLRenderingContext, data: number[]) => WebGLBuffer;
|
|
498
535
|
declare const getStride: (count: number, value: number[], iboValue?: number[]) => number;
|
|
@@ -568,4 +605,4 @@ declare const createGL: (props?: Partial<GL>) => EventState<{
|
|
|
568
605
|
}): GL;
|
|
569
606
|
}, any[] | unknown[]>;
|
|
570
607
|
|
|
571
|
-
export { AttribData, Attribute, Attributes, BaseNodeProxy, Constants, Conversions,
|
|
608
|
+
export { AttribData, Attribute, Attributes, BaseNodeProxy, Constants, Conversions, Fn, FnLayout, Functions, GL, GLClearMode, GLDrawMode, GLDrawType, If, Loop, NodeContext, NodeProps, NodeProxy, NodeTypes, Operators, PrecisionMode, ReadNodeProxy, Return, Switch, Swizzles, TextureData, Uniform, UniformData, Uniforms, WebGLState, WebGPUState, X, abs, acos, addDependency, all, any, asin, assign, atan, atan2, attribute, bitcast, bool, builtin, bvec2, bvec3, bvec4, cbrt, ceil, clamp, code, color, constant, conversion, conversionToConstant, cos, createAttrib, createAttribBuffer, createBindGroup, createBindings, createDepthTexture, createDescriptor, createDevice, createGL, createIbo, createPipeline, createProgram, createTexture, createTextureSampler, createUniformBuffer, createVbo, createVertexBuffers, cross, cubeTexture, dFdx, dFdy, createGL as default, 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, smoothstep, sortHeadersByDependencies, sqrt, step, struct, tan, texture, texture2D, textureSize, toVar, transformDirection, trunc, uint, uniform, uv, uvec2, uvec3, uvec4, variable, vec2, vec3, vec4, vertex, vertexIndex, vertexStage, webgl, webgpu };
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,40 @@
|
|
|
1
|
-
import{durable as
|
|
2
|
-
${
|
|
3
|
-
}`;for(let
|
|
4
|
-
${
|
|
5
|
-
}`:` else if (${
|
|
6
|
-
${
|
|
7
|
-
}`}return o},
|
|
1
|
+
import{durable as ye,event as It}from"reev";import{createFrame as Ut,createQueue as Ft}from"refr";import{nested as be}from"reev";var l={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)},Xt=(e,t)=>e.forEach(t),Vt=(e,...t)=>{Xt(e,r=>r(...t))},zt=(e="",t="_",r="/")=>e.split(t).join(r),kt=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",qt=(e=0)=>`${e}`.split(".")[1]?.length??0,Yt=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),Ht=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var Z={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"},O=Object.keys(Z),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),ee=["dot","distance","length","lengthSq","determinant","luminance"],te=["all","any"],re=["abs","sign","floor","ceil","round","fract","trunc","sin","cos","tan","asin","acos","atan","exp","exp2","log","log2","sqrt","inverseSqrt","normalize","oneMinus","saturate","negate","reciprocal","dFdx","dFdy","fwidth"],oe=["cross"],ne=["reflect","refract"],se=["min","max","mix","clamp","step","smoothstep"],ie=["texture","textureLod","textureSize","cubeTexture"],Tt=["atan2","degrees","faceforward","bitcast","cbrt","difference","equals","pow","pow2","pow3","pow4","radians","transformDirection"],Te=[...ee,...te,...re,...oe,...ne,...se,...ie,...Tt],ae={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},_e={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"},Ee=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],Ne=["and","or"],Ce={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 Pe=e=>l.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),Se=e=>Xe.includes(e),Le=e=>Te.includes(e),we=e=>Q.includes(e),V=e=>!e||typeof e!="object"?!1:e.isProxy,ue=e=>l.str(e)?O.includes(e):!1,$e=e=>{let t=(e>>16&255)/255,r=(e>>8&255)/255,n=(e&255)/255;return[t,r,n]},_t=0,L=()=>`i${_t++}`,w=(e,t)=>l.str(e)?t?.isWebGL?e:Z[e]||e:"",Ge=e=>J[e]||e,Re=e=>Ce[e],Oe=e=>{let t=Q.indexOf(e);return t!==-1?O[t]:"float"},pe=(e,t,r=!1,n=!1)=>e.isWebGL?r?o=>e.gl?.attribute?.(t,o):n?o=>e.gl?.texture?.(t,o):o=>e.gl?.uniform?.(t,o):r?o=>e.gl?._attribute?.(t,o):n?o=>e.gl?._texture?.(t,o):o=>e.gl?._uniform?.(t,o),ce=(e,t)=>{if(!e)return;if(!V(e))return t(e);if(e.type!=="conversion")return;let r=e.props.children?.slice(1).filter(Boolean);r?.length&&t(r)},Ie=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),z=(e,t="",r)=>{e.code?.dependencies?.has(t)||e.code.dependencies.set(t,new Set),ue(r)||e.code.dependencies.get(t).add(r)},Ue=(e,t)=>{let r=[],n=new Set,o=new Set,s=i=>{if(o.has(i)||n.has(i))return;o.add(i);let c=t.get(i)||new Set;for(let a of c)e.has(a)&&s(a);o.delete(i),n.add(i),e.has(i)&&r.push([i,e.get(i)])};for(let[i]of e)s(i);return r};var Et=(e,t)=>e.reduce((r,n)=>{let o=y(n,t),s=O.indexOf(r);return O.indexOf(o)>s?o:r},"float"),Nt=e=>_e[e],Ct=(e,t,r)=>{let n=t.length>0?y(t[0],r):"float";return ne.includes(e)?n:ee.includes(e)?"float":te.includes(e)?"bool":re.includes(e)?n:oe.includes(e)?"vec3":ie.includes(e)?"vec4":se.includes(e)?Et(t,r):n},Fe=(e,t,r)=>{if(Ee.includes(r)||Ne.includes(r))return"bool";if(e===t||e.includes("vec")&&!t.includes("vec"))return e;if(t.includes("vec")&&!e.includes("vec"))return t;let n=O.indexOf(e),o=O.indexOf(t);return n>=o?e:t},Pt=e=>l.bol(e)?"bool":l.str(e)?"texture":l.num(e)?Number.isInteger(e)?"int":"float":l.arr(e)&&ae[e.length]||"float",fe=e=>ae[e],St=(e,t)=>{if(e.length===0)return"void";let[r]=e;if(l.str(r))return r;let n=y(r,t);for(let o of e.slice(1))if(n!==y(o,t))throw new Error("glre node system error: defined scope return mismatch");return n},Lt=(e,t)=>{let{type:r,props:n}=e,{id:o,children:s=[],layout:i,inferFrom:c}=n,[a,p,g]=s;if(r==="conversion")return a;if(r==="operator")return Fe(y(p,t),y(g,t),a);if(r==="function")return Ct(a,s.slice(1),t);if(r==="ternary")return Fe(y(p,t),y(g,t),"add");if(r==="builtin")return Nt(o);if(r==="define"&&ue(i?.type))return i?.type;if(r==="attribute"&&l.arr(a)&&t.gl?.count)return fe(a.length/t.gl.count);if(r==="member"){if(Pe(a))return fe(a.length);if(V(p)&&l.str(a)){let C=p.props.fields?.[a];if(C)return y(C,t)}return"float"}return c?St(c,t):y(a,t)},y=(e,t)=>{if(t||(t={}),!V(e))return Pt(e);if(l.arr(e))return fe(e.length);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=Lt(e,t);return t.infers.set(e,r),r};var R=(e,t)=>e.filter(r=>!l.und(r)&&!l.nul(r)).map(r=>f(r,t)).join(", "),Ae=(e,t,r,n)=>{if(e.isWebGL)return`texture(${R(n?[t,r,n]:[t,r],e)})`;let o=f(t,e),s=[o,o+"Sampler",f(r,e)];return n?(s.push(f(n,e)),`textureSampleLevel(${s})`):`textureSample(${s})`},Be=(e,t,r,n)=>{let o=`if (${f(t,e)}) {
|
|
2
|
+
${f(r,e)}
|
|
3
|
+
}`;for(let s=2;s<n.length;s+=2){let i=s>=n.length-1;o+=i?` else {
|
|
4
|
+
${f(n[s],e)}
|
|
5
|
+
}`:` else if (${f(n[s],e)}) {
|
|
6
|
+
${f(n[s+1],e)}
|
|
7
|
+
}`}return o},De=(e,t,r)=>{let n=`switch (${f(t,e)}) {
|
|
8
8
|
`;for(let o=1;o<r.length;o+=2)o>=r.length-1&&r.length%2===0?n+=`default:
|
|
9
|
-
${
|
|
9
|
+
${f(r[o],e)}
|
|
10
10
|
break;
|
|
11
|
-
`:o+1<r.length&&(n+=`case ${
|
|
12
|
-
${
|
|
11
|
+
`:o+1<r.length&&(n+=`case ${f(r[o],e)}:
|
|
12
|
+
${f(r[o+1],e)}
|
|
13
13
|
break;
|
|
14
|
-
`);return n+="}",n}
|
|
15
|
-
`)},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
${
|
|
19
|
-
}
|
|
20
|
-
${
|
|
21
|
-
|
|
14
|
+
`);return n+="}",n},Me=(e,t,r)=>{let n=y(t,e),o=r?.props?.id;if(e.isWebGL)return`${n} ${o} = ${f(t,e)};`;let s=w(n);return`var ${o}: ${s} = ${f(t,e)};`},We=(e,t,r)=>{let{id:n,children:o=[],layout:s}=t,[i,...c]=o,a=[],p=[];if(s?.inputs)for(let v of s.inputs)a.push([v.name,v.type]);else for(let v=0;v<c.length;v++)a.push([`p${v}`,y(c[v],e)]);let g=[];if(e?.isWebGL){for(let[v,m]of a)z(e,n,m),p.push(`${m} ${v}`);z(e,n,r),g.push(`${r} ${n}(${p}) {`)}else{for(let[v,m]of a)p.push(`${v}: ${w(m,e)}`);g.push(`fn ${n}(${p}) -> ${w(r,e)} {`)}let C=f(i,e);return C&&g.push(C),g.push("}"),g.join(`
|
|
15
|
+
`)},Ve=(e,t,r={})=>{let n=[];for(let s in r){let i=r[s],c=y(i,e);e.isWebGL&&z(e,t,c),n.push(e.isWebGL?`${c} ${s};`:`${s}: ${w(c,e)},`)}let o=n.join(`
|
|
16
|
+
`);return`struct ${t} {
|
|
17
|
+
${o}
|
|
18
|
+
};`},ze=(e,t,r="",n,o)=>{if(e.isWebGL)if(o){let s=[];for(let i in n)s.push(o[i]);return`${t} ${r} = ${t}(${R(s,e)});`}else return`${t} ${r};`;else if(o){let s=[];for(let i in n)s.push(o[i]);return`var ${r}: ${t} = ${t}(${R(s,e)});`}else return`var ${r}: ${t};`},ke=(e,t,r)=>e.isWebGL?`${r} ${t};`:`@location(${e.code?.vertVaryings?.size||0}) ${t}: ${w(r,e)}`,qe=(e,t,r)=>{let n=r==="sampler2D"||r==="texture";if(e.isWebGL)return n?`uniform sampler2D ${t};`:`uniform ${r} ${t};`;if(n){let{group:c=1,binding:a=0}=e.gl?.webgpu?.textures.map.get(t)||{};return`@group(${c}) @binding(${a}) var ${t}Sampler: sampler;
|
|
19
|
+
@group(${c}) @binding(${a+1}) var ${t}: texture_2d<f32>;`}let{group:o=0,binding:s=0}=e.gl?.webgpu?.uniforms.map.get(t)||{},i=w(r,e);return`@group(${o}) @binding(${s}) var<uniform> ${t}: ${i};`},Ye=(e,t,r)=>{if(e.isWebGL)return`${r} ${t};`;let{location:n=0}=e.gl?.webgpu?.attribs.map.get(t)||{},o=w(r,e);return`@location(${n}) ${t}: ${o}`},He=(e,t,r,n)=>e.isWebGL?`const ${r} ${t} = ${n};`:`const ${t}: ${w(r,e)} = ${n};`;var f=(e,t)=>{if(t||(t={}),Ie(t),l.arr(e))return R(e,t);if(l.str(e))return e;if(l.num(e)){let m=`${e}`;return m.includes(".")?m:m+".0"}if(l.bol(e))return e?"true":"false";if(!e)return"";let{type:r,props:n}=e,{id:o="",children:s=[],fields:i,initialValues:c}=n,[a,p,g,C]=s;if(r==="variable")return o;if(r==="member")return`${f(p,t)}.${f(a,t)}`;if(r==="ternary")return t.isWebGL?`(${f(a,t)} ? ${f(p,t)} : ${f(g,t)})`:`select(${f(g,t)}, ${f(p,t)}, ${f(a,t)})`;if(r==="conversion")return`${w(a,t)}(${R(s.slice(1),t)})`;if(r==="operator")return a==="not"||a==="bitNot"?`!${f(p,t)}`:`(${f(p,t)} ${Ge(a)} ${f(g,t)})`;if(r==="function")return a==="negate"?`(-${R(s.slice(1),t)})`:a==="texture"?Ae(t,p,g,C):`${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(p,t)};`;if(r==="return")return`return ${f(a,t)};`;if(r==="loop")return t.isWebGL?`for (int i = 0; i < ${a}; i += 1) {
|
|
21
|
+
${f(p,t)}
|
|
22
|
+
}`:`for (var i: i32 = 0; i < ${a}; i++) {
|
|
23
|
+
${f(p,t)}
|
|
24
|
+
}`;if(r==="if")return Be(t,a,p,s);if(r==="switch")return De(t,a,s);if(r==="declare")return Me(t,a,p);if(r==="define")return t.code?.headers.has(o)||t.code?.headers.set(o,We(t,n,y(e,t))),`${o}(${R(s.slice(1),t)})`;if(r==="struct")return t.code?.headers.has(o)||t.code?.headers.set(o,Ve(t,o,i)),ze(t,o,a.props.id,i,c);if(r==="varying"){if(t.code?.vertOutputs.has(o))return t.isWebGL?`${o}`:`out.${o}`;let m=ke(t,o,y(e,t));return t.code?.fragInputs.set(o,m),t.code?.vertOutputs.set(o,m),t.code?.vertVaryings.set(o,f(a,t)),t.isWebGL?`${o}`:`out.${o}`}if(r==="builtin"){if(t.isWebGL)return Re(o);if(o==="position")return"out.position";let m=`@builtin(${o}) ${o}: ${w(y(e,t),t)}`;return t.isFrag?t.code?.fragInputs.set(o,m):t.code?.vertInputs.set(o,m),`in.${o}`}if(r==="attribute"){let m=pe(t,o,!0);return ce(a,m),e.listeners.add(m),t.code?.vertInputs.set(o,Ye(t,o,y(e,t))),t.isWebGL?`${o}`:`in.${o}`}if(t.code?.headers.has(o))return o;let v="";if(r==="uniform"){let m=y(e,t),D=pe(t,o,!1,m==="texture");ce(a,D),e.listeners.add(D),v=qe(t,o,m)}return r==="constant"&&(v=He(t,o,y(e,t),f(a,t))),v?(t.code?.headers.set(o,v),o):f(a,t)};var I=null,B=null,F=e=>{if(!I||(I.props.children||(I.props.children=[]),I.props.children.push(e),e.type!=="return"||!B))return;let{props:t}=B;t.inferFrom||(t.inferFrom=[]),t.inferFrom.push(e)},je=(e,t)=>{t||(t=L());let r=d("variable",{id:t,inferFrom:[e]}),n=d("declare",null,e,r);return F(n),r},Ke=(e,t)=>{let r=d("assign",null,e,t);return F(r),e},wt=e=>{let t=d("return",{inferFrom:[e]},e);return F(t),t},vr=(e,t=L())=>(r={},n=L())=>{let o=d("variable",{id:n,inferFrom:[t]}),s=d("struct",{id:t,fields:e,initialValues:r},o);return F(s),o},U=(e,t,r=B)=>{let n=I,o=B;I=e,B=r,n&&(e.props.parent=n);let s=t();s&&wt(s),I=n,B=o},yr=(e,t)=>{let r=d("scope");U(r,t);let n=d("if",null,e,r);F(n);let o=()=>({ElseIf:(s,i)=>{let c=d("scope");return U(c,i),n.props.children.push(s,c),o()},Else:s=>{let i=d("scope");U(i,s),n.props.children.push(i)}});return o()},hr=(e,t)=>{let r=d("scope");U(r,()=>t({i:d("variable",{id:"i",inferFrom:[A(0)]})}));let n=d("loop",null,e,r);return F(n),n},Xr=e=>{let t=d("switch",null,e);F(t);let r=()=>({Case:(...n)=>o=>{let s=d("scope");U(s,o);for(let i of n)t.props.children.push(i,s);return r()},Default:n=>{let o=d("scope");U(o,n),t.props.children.push(o)}});return r()},Tr=e=>{let t,r=(...n)=>{let o=t?.name||L(),s=d("scope"),i=[],c=[];if(t?.inputs)for(let p of t.inputs)c.push({id:p.name,inferFrom:[x(p.type)]});else for(let p=0;p<n.length;p++)c.push({id:`p${p}`,inferFrom:[n[p]]});for(let p of c)i.push(d("variable",p));let a=d("define",{id:o,layout:t},s,...n);return U(s,()=>e(i),a),a};return r.setLayout=n=>void(t=n),r};var $t=(e,t)=>{if(t==="string")return f(e)},d=(e,t,...r)=>{t||(t={}),r.length&&(t.children=r);let n=new Set,o=(c,a)=>{if(a==="type")return e;if(a==="props")return t;if(a==="toVar")return je.bind(null,i);if(a==="assign")return Ke.bind(null,i);if(a==="isProxy")return!0;if(a==="toString")return f.bind(null,i);if(a===Symbol.toPrimitive)return $t.bind(null,i);if(a==="listeners")return n;if(Se(a))return(...p)=>Gt(a,i,...p);if(Le(a))return(...p)=>u(a,i,...p);if(we(a))return()=>x(Oe(a),i);if(l.str(a))return Ze(a,i)},s=(c,a,p)=>(a==="value"&&n.forEach(g=>g(p)),l.str(a)&&Ze(a,i).assign(p),!0),i=new Proxy({},{get:o,set:s});return i},Sr=(e,t=L())=>d("attribute",{id:t},e),Lr=(e,t=L())=>d("constant",{id:t},e),k=(e,t=L())=>d("uniform",{id:t},e),wr=(e=L())=>d("variable",{id:e}),T=(e=L())=>d("builtin",{id:e}),$r=(e,t=L())=>d("varying",{id:t,inferFrom:[e]},e),Gt=(e,...t)=>d("operator",null,e,...t),u=(e,...t)=>d("function",null,e,...t),x=(e,...t)=>d("conversion",null,e,...t),Ze=(e,t)=>d("member",null,e,t),Gr=(e,t,r)=>d("ternary",null,e,t,r);var Rt=`
|
|
22
25
|
#version 300 es
|
|
23
26
|
precision mediump float;
|
|
24
27
|
out vec4 fragColor;
|
|
25
|
-
`.trim(),
|
|
26
|
-
`)
|
|
28
|
+
`.trim(),Je=(e,t)=>{let r=f(e,t),n="";return t.isWebGL&&t.code?.dependencies?n=Ue(t.code.headers,t.code.dependencies).map(([,s])=>s).join(`
|
|
29
|
+
`):n=Array.from(t.code?.headers?.values()||[]).join(`
|
|
30
|
+
`),[n,r]},le=(e,t)=>`struct ${e} {
|
|
27
31
|
${Array.from(t.values()).join(`,
|
|
28
32
|
`)}
|
|
29
|
-
}`,
|
|
30
|
-
`);return console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
31
|
-
${
|
|
32
|
-
fragColor = ${n};`)}else t.fragInputs?.size&&o.push(
|
|
33
|
-
fn main(out: Out) -> @location(0) vec4f {`),o.push(` return ${n};`);o.push("}");let
|
|
34
|
-
`);return console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
35
|
-
${i}`),i},se=T("position"),ie=T("vertex_index"),Sr=T("instance_index"),wr=T("front_facing"),Lr=T("frag_depth"),Rr=T("sample_index"),Or=T("sample_mask"),Gr=T("point_coord"),$r=T("normalLocal"),Ir=T("normalWorld"),Ur=T("normalView"),Fr=T("position"),Ar=T("positionWorld"),Dr=T("positionView"),Br=T("screenCoordinate"),Mr=T("screenUV"),z=e=>d("float",e),I=e=>d("int",e),Vr=e=>d("uint",e),zr=e=>d("bool",e),qe=(e,t)=>d("vec2",e,t),ze=(e,t,r)=>d("vec3",e,t,r),ae=(e,t,r,n)=>d("vec4",e,t,r,n),Wr=(...e)=>d("mat2",...e),qr=(...e)=>d("mat3",...e),kr=(...e)=>d("mat4",...e),Yr=(e,t)=>d("ivec2",e,t),Hr=(e,t,r)=>d("ivec3",e,t,r),jr=(e,t,r,n)=>d("ivec4",e,t,r,n),Kr=(e,t)=>d("uvec2",e,t),Zr=(e,t,r)=>d("uvec3",e,t,r),Qr=(e,t,r,n)=>d("uvec4",e,t,r,n),Jr=(e,t)=>d("bvec2",e,t),eo=(e,t,r)=>d("bvec3",e,t,r),to=(e,t,r,n)=>d("bvec4",e,t,r,n),ro=()=>d("texture"),oo=()=>d("sampler2D"),no=(e,t,r)=>l.num(e)&&l.und(t)&&l.und(r)?ze(...Ne(e)):ze(e,t,r),ue=B(qe(1280,800),"iResolution"),so=B(qe(0,0),"iMouse"),io=B(z(0),"iTime"),ao=()=>se.xy.div(ue),uo=(e,t,r)=>u("texture",e,t,r),po=(e,t,r)=>u("cubeTexture",e,t,r),co=(e,t)=>u("textureSize",e,t),fo=e=>u("abs",e),lo=e=>u("acos",e),mo=e=>u("all",e),xo=e=>u("any",e),go=e=>u("asin",e),bo=(e,t)=>t!==void 0?u("atan",e,t):u("atan",e),vo=(e,t)=>u("atan",e,t),ho=(e,t)=>u("bitcast",e,t),Xo=e=>u("cbrt",e),yo=e=>u("ceil",e),To=(e,t,r)=>u("clamp",e,t,r),_o=e=>u("cos",e),Eo=(e,t)=>u("cross",e,t),Co=e=>u("dFdx",e),No=e=>u("dFdy",e),Po=e=>u("degrees",e),So=(e,t)=>u("difference",e,t),wo=(e,t)=>u("distance",e,t),Lo=(e,t)=>u("dot",e,t),Ro=(e,t)=>u("equals",e,t),Oo=e=>u("exp",e),Go=e=>u("exp2",e),$o=(e,t,r)=>u("faceforward",e,t,r),Io=e=>u("floor",e),ke=e=>u("fract",e),Uo=e=>u("fwidth",e),Fo=e=>u("inverseSqrt",e),Ao=e=>u("length",e),Do=e=>u("lengthSq",e),Bo=e=>u("log",e),Mo=e=>u("log2",e),Vo=(e,t)=>u("max",e,t),zo=(e,t)=>u("min",e,t),Wo=(e,t,r)=>u("mix",e,t,r),qo=e=>u("negate",e),ko=e=>u("normalize",e),Yo=e=>u("oneMinus",e),Ho=(e,t)=>u("pow",e,t),jo=e=>u("pow2",e),Ko=e=>u("pow3",e),Zo=e=>u("pow4",e),Qo=e=>u("radians",e),Jo=e=>u("reciprocal",e),en=(e,t)=>u("reflect",e,t),tn=(e,t,r)=>u("refract",e,t,r),rn=e=>u("round",e),on=e=>u("saturate",e),nn=e=>u("sign",e),sn=e=>u("sin",e),an=(e,t,r)=>u("smoothstep",e,t,r),un=e=>u("sqrt",e),pn=(e,t)=>u("step",e,t),cn=e=>u("tan",e),fn=(e,t)=>u("transformDirection",e,t),ln=e=>u("trunc",e);var Ye=(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}`)},He=(e,t,r,n=()=>{},o)=>{let i={isWebGL:!0,gl:o};l.str(r)||(r=V(r,i)),l.str(t)||(t=M(t,i));let s=e.createProgram(),a=Ye(e,t,e.VERTEX_SHADER),p=Ye(e,r,e.FRAGMENT_SHADER);if(!a||!p)return n();if(e.attachShader(s,a),e.attachShader(s,p),e.linkProgram(s),e.getProgramParameter(s,e.LINK_STATUS))return s;let f=e.getProgramInfoLog(s);e.deleteProgram(s),n(),console.warn(`Could not link pg: ${f}`)},je=(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},Ke=(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},Ze=(e,t,r)=>{r&&(e=Math.max(...r)+1);let n=t.length/e;return Math.floor(n)},Qe=(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)},Je=(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 et=async e=>{let t=e.el.getContext("webgl2"),r=He(t,e.vs,e.fs,()=>void(e.isLoop=!1),e);t.useProgram(r);let n=0,o=pe(g=>t.getUniformLocation(r,g)),i=pe(g=>t.getAttribLocation(r,g)),s=pe(()=>n++);return{render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(r),_attribute:(g="",_,E)=>{let N=i(g,!0),A=je(t,_),W=Ke(t,E),q=Ze(e.count,_,E);Qe(t,q,N,A,W)},_uniform:(g,_)=>{let E=o(g);if(l.num(_))return t.uniform1f(E,_);let N=_.length;if(N<=4)return t[`uniform${N}fv`](E,_);N=Math.sqrt(N)<<0,t[`uniformMatrix${N}fv`](E,!1,_)},_texture:(g,_)=>{let E=new Image;Object.assign(E,{src:_,crossOrigin:"anonymous"}),E.decode().then(()=>{let N=o(g),A=s(g);Je(t,E,N,A)})},webgl:{context:t,program:r}}};import{nested as ce}from"reev";var tt=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}},rt=()=>{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),i=t%6*2;return t++,{group:o,binding:i}},attrib:()=>{let n=r;return r++,{location:n}}}},ot=(e,t,r,n,o,i,s)=>{let a={isWebGL:!1,webgpu:o};l.str(s)||(s=V(s,a)),l.str(i)||(i=M(i,a));let p=e.createPipelineLayout({bindGroupLayouts:n});return e.createRenderPipeline({vertex:{module:e.createShaderModule({code:i.trim()}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({code:s.trim()}),entryPoint:"main",targets:[{format:t}]},layout:p,primitive:{topology:"triangle-list"},depthStencil:{depthWriteEnabled:!0,depthCompare:"less",format:"depth24plus"}})},nt=(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}},st=(e,t)=>{let r=new Float32Array(t),n=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:n}},it=(e,t,r)=>{let n=new Map,o=(s=0)=>(n.has(s)||n.set(s,{entries0:[],entries1:[]}),n.get(s));for(let{binding:s,buffer:a,group:p}of t.values()){let{entries0:f,entries1:b}=o(p);f.push({binding:s,visibility:3,buffer:{type:"uniform"}}),b.push({binding:s,resource:{buffer:a}})}for(let{binding:s,group:a,sampler:p,texture:f}of r.values()){let{entries0:b,entries1:x}=o(a);b.push({binding:s,visibility:2,sampler:{}}),b.push({binding:s+1,visibility:2,texture:{}}),x.push({binding:s,resource:p}),x.push({binding:s+1,resource:f.createView()})}let i={bindGroups:[],bindGroupLayouts:[]};for(let[s,{entries0:a,entries1:p}]of n)i.bindGroupLayouts[s]=e.createBindGroupLayout({entries:a}),i.bindGroups[s]=e.createBindGroup({layout:i.bindGroupLayouts[s],entries:p});return i},at=(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"}}),ut=(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}},pt=(e,t,r)=>e.createTexture({size:[t,r],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT}),Nt=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",ct=e=>{let t=[],r=[];for(let[,{buffer:n,location:o,stride:i}]of e)t[o]=n,r[o]={arrayStride:i*4,attributes:[{shaderLocation:o,offset:0,format:Nt(i)}]};return{vertexBuffers:t,bufferLayouts:r}};var ft=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:n}=await tt(t),o=rt(),i=0,s=!0,a,p=y=>{},f=ce((y,v)=>{s=!0;let{group:h,binding:C}=o.uniform(),{array:L,buffer:P}=nt(r,v);return{array:L,buffer:P,binding:C,group:h}}),b=ce((y,{width:v,height:h})=>{s=!0;let{group:C,binding:L}=o.texture(),{texture:P,sampler:D}=ut(r,v,h);return{texture:P,sampler:D,binding:L,group:C}}),x=ce((y,v)=>{s=!0;let h=v.length/e.count,{location:C}=o.attrib(),{array:L,buffer:P}=st(r,v);return{array:L,buffer:P,location:C,stride:h}}),g=()=>{let{vertexBuffers:y,bufferLayouts:v}=ct(x.map),{bindGroups:h,bindGroupLayouts:C}=it(r,f.map,b.map),L=ot(r,n,v,C,me,e.vs,e.fs);p=P=>{P.setPipeline(L),h.forEach((D,k)=>P.setBindGroup(k,D)),y.forEach((D,k)=>P.setVertexBuffer(k,D)),P.draw(e.count,1,0,0),P.end()}},_=()=>{if(i)return;s&&g(),s=!1;let y=r.createCommandEncoder();p(y.beginRenderPass(at(t,a))),r.queue.submit([y.finish()])},E=()=>{let y=e.el;a?.destroy(),a=pt(r,y.width,y.height)},N=()=>{a?.destroy()},A=(y="",v)=>{let{array:h,buffer:C}=x(y,v);h.set(v),r.queue.writeBuffer(C,0,h)},W=(y,v)=>{l.num(v)&&(v=[v]);let{array:h,buffer:C}=f(y,v);h.set(v),r.queue.writeBuffer(C,0,h)},q=(y,v)=>{i++;let h=Object.assign(new Image,{src:v,crossOrigin:"anonymous"});h.decode().then(()=>{let C=b(y,h);r.queue.copyExternalImageToTexture({source:h},{texture:C.texture},{width:h.width,height:h.height}),i--})};E();let me={device:r,uniforms:f,textures:b,attribs:x};return{webgpu:me,render:_,resize:E,clean:N,_attribute:A,_uniform:W,_texture:q}};var Bn=e=>l.obj(e)?"isGL"in e:!1,Lt=()=>typeof window>"u",Rt=()=>Lt()?!1:"gpu"in navigator,le=performance.now(),Ot=()=>ae(ke(se.xy.div(ue)),0,1),Gt=()=>ae(z(I(ie).mod(I(2))).mul(4).sub(1),z(I(ie).div(I(2))).mul(4).sub(1),0,1),$t=e=>{let t=Pt({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=wt(),t.frame=St(),t.attribute=fe((r,n,o)=>t.queue(()=>t._attribute?.(r,n,o)),t),t.uniform=fe((r,n,o)=>t.queue(()=>t._uniform?.(r,n,o)),t),t.texture=fe((r,n)=>t.queue(()=>t._texture?.(r,n)),t),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:le}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex||Gt(),t.fs=t.fs||t.frag||t.fragment||Ot(),Rt()||(t.isWebGL=!0),t.isWebGL?t(await et(t)):t(await ft(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[i,s]=t.size,{top:a,left:p}=t.el.getBoundingClientRect();t.mouse[0]=(n-a-i/2)/(i/2),t.mouse[1]=-(o-p-s/2)/(s/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{le=performance.now()/1e3,t.uniform("iTime",le)}),t(e)},Mn=$t;export{lr as Fn,pr as If,cr as Loop,Tt as Return,fr as Switch,fo as abs,lo as acos,mo as all,xo as any,go as asin,Me as assign,bo as atan,vo as atan2,vr as attribute,ho as bitcast,zr as bool,T as builtin,Jr as bvec2,eo as bvec3,to as bvec4,Xo as cbrt,yo as ceil,To as clamp,c as code,no as color,hr as constant,d as conversion,we as conversionToConstant,_o as cos,Qe as createAttrib,st as createAttribBuffer,it as createBindGroup,rt as createBindings,pt as createDepthTexture,at as createDescriptor,tt as createDevice,$t as createGL,Ke as createIbo,ot as createPipeline,He as createProgram,Je as createTexture,ut as createTextureSampler,nt as createUniformBuffer,je as createVbo,ct as createVertexBuffers,Eo as cross,po as cubeTexture,Co as dFdx,No as dFdy,Mn as default,Po as degrees,So as difference,Dt as dig,wo as distance,Lo as dot,lt as each,Ro as equals,Oo as exp,Go as exp2,Ft as ext,$o as faceforward,At as fig,z as float,Io as floor,It as flush,S as formatConversions,ke as fract,Lr as fragDepth,V as fragment,wr as frontFacing,u as function_,Uo as fwidth,Se as getBluiltin,w as getId,Pe as getOperator,Ze as getStride,Ne as hex2rgb,so as iMouse,ue as iResolution,io as iTime,Sr as instanceIndex,I as int,Fo as inverseSqrt,l as is,Ce as isConstantsType,_e as isConversion,Te as isFunction,Bn as isGL,Ee as isNodeProxy,ye as isOperator,Lt as isServer,oe as isSwizzle,Rt as isWebGPUSupported,Yr as ivec2,Hr as ivec3,jr as ivec4,O as joins,Ao as length,Do as lengthSq,Bo as log,Mo as log2,Wr as mat2,qr as mat3,kr as mat4,Vo as max,zo as min,Wo as mix,qo as negate,m as node,$r as normalLocal,Ur as normalView,Ir as normalWorld,ko as normalize,Yo as oneMinus,Et as operator,Gr as pointCoord,se as position,Fr as positionLocal,Dr as positionView,Ar as positionWorld,Ho as pow,jo as pow2,Ko as pow3,Zo as pow4,Qo as radians,Jo as reciprocal,en as reflect,tn as refract,Ut as replace,rn as round,Rr as sampleIndex,Or as sampleMask,oo as sampler2D,on as saturate,Br as screenCoordinate,Mr as screenUV,Tr as select,Bt as sig,nn as sign,sn as sin,an as smoothstep,un as sqrt,pn as step,Ve as swizzle,cn as tan,uo as texture,ro as texture2D,co as textureSize,Be as toVar,fn as transformDirection,ln as trunc,Vr as uint,B as uniform,ao as uv,Kr as uvec2,Zr as uvec3,Qr as uvec4,Xr as variable,qe as vec2,ze as vec3,ae as vec4,M as vertex,ie as vertexIndex,yr as vertexStage,et as webgl,ft as webgpu};
|
|
33
|
+
}`,q=(e,t)=>{if(l.str(e))return e.trim();t.code?.headers?.clear(),t.isFrag=!1;let[r,n]=Je(e,t),o=[];if(t.isWebGL){o.push("#version 300 es");for(let i of t.code?.vertInputs?.values()||[])o.push(`in ${i}`);for(let i of t.code?.vertOutputs?.values()||[])o.push(`out ${i}`);o.push(r),o.push("void main() {"),o.push(` gl_Position = ${n};`);for(let[i,c]of t.code?.vertVaryings?.entries()||[])o.push(` ${i} = ${c};`)}else{t.code?.vertInputs?.size&&o.push(le("In",t.code.vertInputs)),t.code?.vertOutputs?.size&&o.push(le("Out",t.code.vertOutputs)),o.push(r),o.push("@vertex"),o.push(`fn main(${t.code?.vertInputs?.size?"in: In":""}) -> Out {`),o.push(" var out: Out;"),o.push(` out.position = ${n};`);for(let[i,c]of t.code?.vertVaryings?.entries()||[])o.push(` out.${i} = ${c};`);o.push(" return out;")}o.push("}");let s=o.filter(Boolean).join(`
|
|
34
|
+
`).trim();return console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
35
|
+
${s}`),s},Y=(e,t)=>{if(l.str(e))return e.trim();t.code?.headers?.clear(),t.isFrag=!0;let[r,n]=Je(e,t),o=[];if(t.isWebGL){o.push(Rt);for(let i of t.code?.fragInputs?.values()||[])o.push(`in ${i}`);o.push(r),o.push(`void main() {
|
|
36
|
+
fragColor = ${n};`)}else t.code?.fragInputs?.size&&o.push(le("Out",t.code.fragInputs)),o.push(r),o.push(`@fragment
|
|
37
|
+
fn main(out: Out) -> @location(0) vec4f {`),o.push(` return ${n};`);o.push("}");let s=o.filter(Boolean).join(`
|
|
38
|
+
`).trim();return console.log(`\u2193\u2193\u2193generated\u2193\u2193\u2193
|
|
39
|
+
${s}`),s},de=T("position"),me=T("vertex_index"),Ar=T("instance_index"),Br=T("front_facing"),Dr=T("frag_depth"),Mr=T("sample_index"),Wr=T("sample_mask"),Vr=T("point_coord"),zr=T("normalLocal"),kr=T("normalWorld"),qr=T("normalView"),Yr=T("position"),Hr=T("positionWorld"),jr=T("positionView"),Kr=T("screenCoordinate"),Zr=T("screenUV"),H=e=>x("float",e),A=e=>x("int",e),Qr=e=>x("uint",e),Jr=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),eo=(...e)=>x("mat2",...e),to=(...e)=>x("mat3",...e),ro=(...e)=>x("mat4",...e),oo=(e,t)=>x("ivec2",e,t),no=(e,t,r)=>x("ivec3",e,t,r),so=(e,t,r,n)=>x("ivec4",e,t,r,n),io=(e,t)=>x("uvec2",e,t),ao=(e,t,r)=>x("uvec3",e,t,r),uo=(e,t,r,n)=>x("uvec4",e,t,r,n),po=(e,t)=>x("bvec2",e,t),co=(e,t,r)=>x("bvec3",e,t,r),fo=(e,t,r,n)=>x("bvec4",e,t,r,n),lo=e=>x("texture",e),mo=()=>x("sampler2D"),xo=(e,t,r)=>l.num(e)&&l.und(t)&&l.und(r)?Qe(...$e(e)):Qe(e,t,r),ge=k(et(),"iResolution"),go=k(et(),"iMouse"),bo=k(H(),"iTime"),vo=()=>de.xy.div(ge),yo=(e,t,r)=>u("texture",e,t,r),ho=(e,t,r)=>u("cubeTexture",e,t,r),Xo=(e,t)=>u("textureSize",e,t),To=e=>u("abs",e),_o=e=>u("acos",e),Eo=e=>u("all",e),No=e=>u("any",e),Co=e=>u("asin",e),Po=(e,t)=>t!==void 0?u("atan",e,t):u("atan",e),So=(e,t)=>u("atan",e,t),Lo=(e,t)=>u("bitcast",e,t),wo=e=>u("cbrt",e),$o=e=>u("ceil",e),Go=(e,t,r)=>u("clamp",e,t,r),Ro=e=>u("cos",e),Oo=(e,t)=>u("cross",e,t),Io=e=>u("dFdx",e),Uo=e=>u("dFdy",e),Fo=e=>u("degrees",e),Ao=(e,t)=>u("difference",e,t),Bo=(e,t)=>u("distance",e,t),Do=(e,t)=>u("dot",e,t),Mo=(e,t)=>u("equals",e,t),Wo=e=>u("exp",e),Vo=e=>u("exp2",e),zo=(e,t,r)=>u("faceforward",e,t,r),ko=e=>u("floor",e),tt=e=>u("fract",e),qo=e=>u("fwidth",e),Yo=e=>u("inverseSqrt",e),Ho=e=>u("length",e),jo=e=>u("lengthSq",e),Ko=e=>u("log",e),Zo=e=>u("log2",e),Qo=(e,t)=>u("max",e,t),Jo=(e,t)=>u("min",e,t),en=(e,t,r)=>u("mix",e,t,r),tn=e=>u("negate",e),rn=e=>u("normalize",e),on=e=>u("oneMinus",e),nn=(e,t)=>u("pow",e,t),sn=e=>u("pow2",e),an=e=>u("pow3",e),un=e=>u("pow4",e),pn=e=>u("radians",e),cn=e=>u("reciprocal",e),fn=(e,t)=>u("reflect",e,t),ln=(e,t,r)=>u("refract",e,t,r),dn=e=>u("round",e),mn=e=>u("saturate",e),xn=e=>u("sign",e),gn=e=>u("sin",e),bn=(e,t,r)=>u("smoothstep",e,t,r),vn=e=>u("sqrt",e),yn=(e,t)=>u("step",e,t),hn=e=>u("tan",e),Xn=(e,t)=>u("transformDirection",e,t),Tn=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(P=>t.getUniformLocation(s,P)),a=be(P=>t.getAttribLocation(s,P)),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:(P="",E,S)=>{let $=a(P,!0),M=nt(t,E),j=st(t,S),h=it(e.count,E,S);at(t,h,$,M,j)},_uniform:(P,E)=>{let S=c(P);if(l.num(E))return t.uniform1f(S,E);let $=E.length;if($<=4)return t[`uniform${$}fv`](S,E);$=Math.sqrt($)<<0,t[`uniformMatrix${$}fv`](S,!1,E)},_texture:(P,E)=>{let S=new Image;Object.assign(S,{src:E,crossOrigin:"anonymous"}),S.decode().then(()=>{let $=c(P),M=p(P);ut(t,S,$,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}}}},Ot=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:Ot(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,C=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,C.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()}},P=()=>{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)},S=()=>{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:_}=C(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:C,textures:v,attribs:m},render:P,resize:E,clean:S,_attribute:$,_uniform:M,_texture:j}};var Yn=e=>l.obj(e)?"isGL"in e:!1,At=()=>typeof window>"u",Bt=()=>At()?!1:"gpu"in navigator,he=performance.now(),Dt=()=>xe(tt(de.xy.div(ge)),0,1),Mt=()=>xe(H(A(me).mod(A(2))).mul(4).sub(1),H(A(me).div(A(2))).mul(4).sub(1),0,1),Wt=e=>{let t=It({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=Ft(),t.frame=Ut(),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||Mt(),t.fs=t.fs||t.frag||t.fragment||Dt(),Bt()||(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)},Hn=Wt;export{Tr as Fn,yr as If,hr as Loop,wt as Return,Xr as Switch,To as abs,_o as acos,z as addDependency,Eo as all,No as any,Co as asin,Ke as assign,Po as atan,So as atan2,Sr as attribute,Lo as bitcast,Jr as bool,T as builtin,po as bvec2,co as bvec3,fo as bvec4,wo as cbrt,$o as ceil,Go as clamp,f as code,xo as color,Lr as constant,x as conversion,Oe as conversionToConstant,Ro as cos,at as createAttrib,gt as createAttribBuffer,dt as createBindGroup,ft as createBindings,yt as createDepthTexture,bt as createDescriptor,ct as createDevice,Wt 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,Oo as cross,ho as cubeTexture,Io as dFdx,Uo as dFdy,Hn as default,Fo as degrees,Ao as difference,Yt as dig,Bo as distance,Do as dot,Xt as each,Mo as equals,Wo as exp,Vo as exp2,kt as ext,zo as faceforward,qt as fig,H as float,ko as floor,Vt as flush,w as formatConversions,tt as fract,Dr as fragDepth,Y as fragment,Br as frontFacing,u as function_,qo as fwidth,Re as getBluiltin,pe as getEventFun,L as getId,Ge as getOperator,it as getStride,$e as hex2rgb,go as iMouse,ge as iResolution,bo as iTime,Ie as initNodeContext,Ar as instanceIndex,A as int,Yo as inverseSqrt,l as is,ue as isConstants,we as isConversion,Le as isFunction,Yn as isGL,V as isNodeProxy,Se as isOperator,At as isServer,Pe as isSwizzle,Bt as isWebGPUSupported,oo as ivec2,no as ivec3,so as ivec4,Ho as length,jo as lengthSq,Ko as log,Zo as log2,eo as mat2,to as mat3,ro as mat4,Qo as max,Ze as member,Jo as min,en as mix,tn as negate,d as node,zr as normalLocal,qr as normalView,kr as normalWorld,rn as normalize,on as oneMinus,Gt as operator,Vr as pointCoord,de as position,Yr as positionLocal,jr as positionView,Hr as positionWorld,nn as pow,sn as pow2,an as pow3,un as pow4,pn as radians,cn as reciprocal,fn as reflect,ln as refract,zt as replace,dn as round,ce as safeEventCall,Mr as sampleIndex,Wr as sampleMask,mo as sampler2D,mn as saturate,Kr as screenCoordinate,Zr as screenUV,Gr as select,Ht as sig,xn as sign,gn as sin,bn as smoothstep,Ue as sortHeadersByDependencies,vn as sqrt,yn as step,vr as struct,hn as tan,yo as texture,lo as texture2D,Xo as textureSize,je as toVar,Xn as transformDirection,Tn as trunc,Qr as uint,k as uniform,vo as uv,io as uvec2,ao as uvec3,uo as uvec4,wr as variable,et as vec2,Qe as vec3,xe as vec4,q as vertex,me as vertexIndex,$r as vertexStage,pt as webgl,ht as webgpu};
|
|
36
40
|
//# sourceMappingURL=index.js.map
|