glre 0.29.0 → 0.31.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 +34 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -30
- package/dist/index.js +35 -35
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +34 -34
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.cts +1 -2
- package/dist/native.js +35 -35
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +34 -34
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -2
- package/dist/react.js +35 -35
- package/dist/react.js.map +1 -1
- package/dist/solid.cjs +34 -34
- package/dist/solid.cjs.map +1 -1
- package/dist/solid.d.cts +1 -2
- package/dist/solid.js +35 -35
- package/dist/solid.js.map +1 -1
- package/package.json +23 -23
- package/src/node/code.ts +36 -25
- package/src/node/const.ts +19 -18
- package/src/node/index.ts +22 -36
- package/src/node/infer.ts +46 -50
- package/src/node/node.ts +15 -5
- package/src/node/scope.ts +48 -39
- package/src/node/types.ts +45 -13
- package/src/node/utils.ts +77 -27
package/dist/index.d.cts
CHANGED
|
@@ -2,11 +2,10 @@ import * as refr from 'refr';
|
|
|
2
2
|
import { Queue, Frame } from 'refr';
|
|
3
3
|
export { Frame, Fun, Queue } from 'refr';
|
|
4
4
|
import { EventState } from 'reev';
|
|
5
|
-
import { NodeProps as NodeProps$1 } from './../../../../node_modules/glre/src/node/types';
|
|
6
5
|
|
|
7
6
|
declare const SWIZZLES: readonly ["x", "y", "z", "w", "r", "g", "b", "a", "s", "t", "p", "q"];
|
|
8
|
-
declare const CONSTANTS: readonly ["bool", "uint", "int", "float", "bvec2", "
|
|
9
|
-
declare const CONVERSIONS: readonly ["
|
|
7
|
+
declare const CONSTANTS: readonly ["bool", "uint", "int", "float", "bvec2", "ivec2", "uvec2", "vec2", "bvec3", "ivec3", "uvec3", "vec3", "bvec4", "ivec4", "uvec4", "vec4", "color", "mat2", "mat3", "mat4"];
|
|
8
|
+
declare const CONVERSIONS: readonly ["toBool", "toUint", "toInt", "toFloat", "toBvec2", "toIvec2", "toUvec2", "toVec2", "toBvec3", "toIvec3", "toUvec3", "toVec3", "toBvec4", "toIvec4", "toUvec4", "toVec4", "toColor", "toMat2", "toMat3", "toMat4"];
|
|
10
9
|
declare const OPERATORS: {
|
|
11
10
|
readonly add: "+";
|
|
12
11
|
readonly sub: "-";
|
|
@@ -106,30 +105,40 @@ declare const WGSL_TO_GLSL_BUILTIN: {
|
|
|
106
105
|
readonly sample_index: "gl_SampleID";
|
|
107
106
|
readonly sample_mask: "gl_SampleMask";
|
|
108
107
|
readonly point_coord: "gl_PointCoord";
|
|
108
|
+
readonly uv: "gl_FragCoord.xy";
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
type Constants = (typeof CONSTANTS)[number] | 'void';
|
|
112
112
|
type Conversions = (typeof CONVERSIONS)[number];
|
|
113
113
|
type Functions = (typeof FUNCTIONS)[number];
|
|
114
114
|
type Operators = (typeof OPERATOR_KEYS)[number];
|
|
115
|
+
interface FnLayout {
|
|
116
|
+
name: string;
|
|
117
|
+
type: Constants | 'auto';
|
|
118
|
+
inputs?: Array<{
|
|
119
|
+
name: string;
|
|
120
|
+
type: Constants;
|
|
121
|
+
}>;
|
|
122
|
+
}
|
|
115
123
|
interface NodeProps {
|
|
116
124
|
id?: string;
|
|
117
125
|
args?: X[];
|
|
118
126
|
type?: string;
|
|
119
127
|
children?: X[];
|
|
120
|
-
|
|
128
|
+
inferFrom?: X;
|
|
129
|
+
layout?: FnLayout;
|
|
121
130
|
}
|
|
122
131
|
interface NodeConfig {
|
|
123
132
|
isWebGL?: boolean;
|
|
124
133
|
binding?: number;
|
|
125
134
|
infers?: WeakMap<NodeProxy, Constants>;
|
|
126
135
|
headers?: Map<string, string>;
|
|
127
|
-
onMount?: (name: string
|
|
136
|
+
onMount?: (name: string) => void;
|
|
128
137
|
}
|
|
129
138
|
type _Swizzles<T extends string> = T | `${T}${T}` | `${T}${T}${T}` | `${T}${T}${T}${T}`;
|
|
130
139
|
type Swizzles = _Swizzles<'x' | 'y' | 'z' | 'w'> | _Swizzles<'r' | 'g' | 'b' | 'a'> | _Swizzles<'p' | 'q'> | _Swizzles<'s' | 't'>;
|
|
131
|
-
type NodeTypes = '
|
|
132
|
-
interface NodeProxy extends Record<Swizzles
|
|
140
|
+
type NodeTypes = 'attribute' | 'uniform' | 'varying' | 'constant' | 'variable' | 'swizzle' | 'ternary' | 'builtin' | 'conversion' | 'operator' | 'function' | 'scope' | 'assign' | 'loop' | 'define' | 'if' | 'switch' | 'declare';
|
|
141
|
+
interface NodeProxy extends Record<Swizzles, NodeProxy> {
|
|
133
142
|
add(n: X): NodeProxy;
|
|
134
143
|
sub(n: X): NodeProxy;
|
|
135
144
|
mul(n: X): NodeProxy;
|
|
@@ -146,7 +155,6 @@ interface NodeProxy extends Record<Swizzles | Conversions, NodeProxy> {
|
|
|
146
155
|
not(): NodeProxy;
|
|
147
156
|
assign(n: X): NodeProxy;
|
|
148
157
|
toVar(name?: string): NodeProxy;
|
|
149
|
-
toConst(name?: string): NodeProxy;
|
|
150
158
|
abs(): NodeProxy;
|
|
151
159
|
sin(): NodeProxy;
|
|
152
160
|
cos(): NodeProxy;
|
|
@@ -191,6 +199,26 @@ interface NodeProxy extends Record<Swizzles | Conversions, NodeProxy> {
|
|
|
191
199
|
dFdx(): NodeProxy;
|
|
192
200
|
dFdy(): NodeProxy;
|
|
193
201
|
fwidth(): NodeProxy;
|
|
202
|
+
toBool(): NodeProxy;
|
|
203
|
+
toUint(): NodeProxy;
|
|
204
|
+
toInt(): NodeProxy;
|
|
205
|
+
toFloat(): NodeProxy;
|
|
206
|
+
toBvec2(): NodeProxy;
|
|
207
|
+
toIvec2(): NodeProxy;
|
|
208
|
+
toUvec2(): NodeProxy;
|
|
209
|
+
toVec2(): NodeProxy;
|
|
210
|
+
toBvec3(): NodeProxy;
|
|
211
|
+
toIvec3(): NodeProxy;
|
|
212
|
+
toUvec3(): NodeProxy;
|
|
213
|
+
toVec3(): NodeProxy;
|
|
214
|
+
toBvec4(): NodeProxy;
|
|
215
|
+
toIvec4(): NodeProxy;
|
|
216
|
+
toUvec4(): NodeProxy;
|
|
217
|
+
toVec4(): NodeProxy;
|
|
218
|
+
toColor(): NodeProxy;
|
|
219
|
+
toMat2(): NodeProxy;
|
|
220
|
+
toMat3(): NodeProxy;
|
|
221
|
+
toMat4(): NodeProxy;
|
|
194
222
|
toString(c?: NodeConfig): string;
|
|
195
223
|
type: NodeTypes;
|
|
196
224
|
props: NodeProps;
|
|
@@ -201,28 +229,38 @@ type X = NodeProxy | number | string | boolean | undefined;
|
|
|
201
229
|
declare const code: (target: X, c?: NodeConfig | null) => string;
|
|
202
230
|
|
|
203
231
|
declare const inferImpl: (target: NodeProxy, c: NodeConfig) => Constants;
|
|
204
|
-
declare const infer: (target: X, c
|
|
232
|
+
declare const infer: (target: X, c?: NodeConfig | null) => Constants;
|
|
205
233
|
|
|
206
234
|
declare const node: (type: NodeTypes, props?: NodeProps | null, ...args: X[]) => NodeProxy;
|
|
235
|
+
declare const attribute: (x: X, id?: string) => NodeProxy;
|
|
236
|
+
declare const uniform: (x: X, id?: string) => NodeProxy;
|
|
237
|
+
declare const varying: (x: X, id?: string) => NodeProxy;
|
|
238
|
+
declare const constant: (x: X, id?: string) => NodeProxy;
|
|
239
|
+
declare const variable: (id: string) => NodeProxy;
|
|
240
|
+
declare const builtin: (id: string) => NodeProxy;
|
|
207
241
|
declare const swizzle: (key: Swizzles, arg: X) => NodeProxy;
|
|
208
242
|
declare const operator: (key: Operators, ...args: X[]) => NodeProxy;
|
|
209
243
|
declare const function_: (key: Functions, ...args: X[]) => NodeProxy;
|
|
210
244
|
declare const conversion: (key: string, ...args: X[]) => NodeProxy;
|
|
245
|
+
declare const select: (x: X, y: X, z: X) => NodeProxy;
|
|
211
246
|
|
|
212
247
|
declare const toVar: (x: X, id?: string) => NodeProxy;
|
|
213
248
|
declare const assign: (x: X, y: X) => X;
|
|
214
|
-
declare const If: (
|
|
215
|
-
ElseIf: (
|
|
249
|
+
declare const If: (x: X, fun: () => void) => {
|
|
250
|
+
ElseIf: (_x: X, _fun: () => void) => /*elided*/ any;
|
|
216
251
|
Else: (_fun: () => void) => void;
|
|
217
252
|
};
|
|
218
253
|
declare const Loop: (x: X, fun: (params: {
|
|
219
|
-
i
|
|
254
|
+
i: NodeProxy;
|
|
220
255
|
}) => void) => NodeProxy;
|
|
221
|
-
declare const Switch: (
|
|
256
|
+
declare const Switch: (x: X) => {
|
|
222
257
|
Case: (...values: X[]) => (fun: () => void) => /*elided*/ any;
|
|
223
258
|
Default: (fun: () => void) => void;
|
|
224
259
|
};
|
|
225
|
-
declare const Fn: (fun: (paramVars: NodeProxy[]) => NodeProxy) =>
|
|
260
|
+
declare const Fn: (fun: (paramVars: NodeProxy[]) => NodeProxy) => {
|
|
261
|
+
(...args: X[]): NodeProxy;
|
|
262
|
+
setLayout(newLayout: FnLayout): /*elided*/ any;
|
|
263
|
+
};
|
|
226
264
|
|
|
227
265
|
declare const isSwizzle: (key: unknown) => key is Swizzles;
|
|
228
266
|
declare const isOperator: (key: unknown) => key is Operators;
|
|
@@ -234,19 +272,12 @@ declare const getId: () => string;
|
|
|
234
272
|
declare const joins: (children: X[], c: NodeConfig) => string;
|
|
235
273
|
declare const formatConversions: (x: X, c?: NodeConfig) => string;
|
|
236
274
|
declare const getOperator: (op: X) => "/" | "+" | "-" | "*" | "%" | "==" | "!=" | "<" | "<=" | ">" | ">=" | "&&" | "||" | "&" | "|" | "^" | "<<" | ">>";
|
|
237
|
-
declare const
|
|
275
|
+
declare const getBluiltin: (id: string) => "gl_FragCoord" | "gl_VertexID" | "gl_InstanceID" | "gl_FrontFacing" | "gl_FragDepth" | "gl_SampleID" | "gl_SampleMask" | "gl_PointCoord" | "gl_FragCoord.xy";
|
|
276
|
+
declare const conversionToConstant: (conversionKey: string) => Constants;
|
|
277
|
+
declare const generateDefine: (props: NodeProps, c: NodeConfig) => string;
|
|
238
278
|
declare const fragment: (x: X, c?: NodeConfig) => string;
|
|
239
279
|
declare const vertex: (x: X, c: NodeConfig) => string;
|
|
240
280
|
|
|
241
|
-
declare const select: (x: X, y: X, z: X) => NodeProxy;
|
|
242
|
-
declare const uniform: (value: number | number[], id?: string) => NodeProxy;
|
|
243
|
-
declare const varying: (value: number | number[], id?: string) => NodeProxy;
|
|
244
|
-
declare const attribute: (value: number | number[], id?: string) => NodeProxy;
|
|
245
|
-
declare const variable: (id: string) => NodeProxy;
|
|
246
|
-
declare const builtin: (id: string) => NodeProxy;
|
|
247
|
-
declare const iResolution: NodeProxy;
|
|
248
|
-
declare const iMouse: NodeProxy;
|
|
249
|
-
declare const iTime: NodeProxy;
|
|
250
281
|
declare const position: NodeProxy;
|
|
251
282
|
declare const vertexIndex: NodeProxy;
|
|
252
283
|
declare const instanceIndex: NodeProxy;
|
|
@@ -255,16 +286,14 @@ declare const fragDepth: NodeProxy;
|
|
|
255
286
|
declare const sampleIndex: NodeProxy;
|
|
256
287
|
declare const sampleMask: NodeProxy;
|
|
257
288
|
declare const pointCoord: NodeProxy;
|
|
258
|
-
declare const positionLocal: NodeProxy;
|
|
259
|
-
declare const positionWorld: NodeProxy;
|
|
260
|
-
declare const positionView: NodeProxy;
|
|
261
289
|
declare const normalLocal: NodeProxy;
|
|
262
290
|
declare const normalWorld: NodeProxy;
|
|
263
291
|
declare const normalView: NodeProxy;
|
|
292
|
+
declare const positionLocal: NodeProxy;
|
|
293
|
+
declare const positionWorld: NodeProxy;
|
|
294
|
+
declare const positionView: NodeProxy;
|
|
264
295
|
declare const screenCoordinate: NodeProxy;
|
|
265
296
|
declare const screenUV: NodeProxy;
|
|
266
|
-
declare const fragCoord: NodeProxy;
|
|
267
|
-
declare const vertexId: NodeProxy;
|
|
268
297
|
declare const float: (x: X) => NodeProxy;
|
|
269
298
|
declare const int: (x: X) => NodeProxy;
|
|
270
299
|
declare const uint: (x: X) => NodeProxy;
|
|
@@ -285,6 +314,9 @@ declare const bvec2: (x?: X, y?: X) => NodeProxy;
|
|
|
285
314
|
declare const bvec3: (x?: X, y?: X, z?: X) => NodeProxy;
|
|
286
315
|
declare const bvec4: (x?: X, y?: X, z?: X, w?: X) => NodeProxy;
|
|
287
316
|
declare const color: (r?: X, g?: X, b?: X) => NodeProxy;
|
|
317
|
+
declare const iResolution: NodeProxy;
|
|
318
|
+
declare const iMouse: NodeProxy;
|
|
319
|
+
declare const iTime: NodeProxy;
|
|
288
320
|
declare const texture: (x: X, y: X, z?: X) => NodeProxy;
|
|
289
321
|
declare const cubeTexture: (x: X, y: X, z?: X) => NodeProxy;
|
|
290
322
|
declare const textureSize: (x: X, y?: X) => NodeProxy;
|
|
@@ -580,4 +612,4 @@ declare const createGL: (props?: Partial<GL>) => EventState<{
|
|
|
580
612
|
}): GL;
|
|
581
613
|
}, any[] | unknown[]>;
|
|
582
614
|
|
|
583
|
-
export { ADDITIONAL_FUNCTIONS, type Attribute, type Attributes, BOOL_RETURN_FUNCTIONS, BUILTIN_TYPES, COMPARISON_OPERATORS, COMPONENT_COUNT_TO_TYPE, CONSTANTS, CONVERSIONS, type Constants, type Conversions, FIRST_ARG_TYPE_FUNCTIONS, FUNCTIONS, Fn, type Functions, type GL, type GLClearMode, type GLDrawMode, type GLDrawType, type GPUBindGroup, type GPUBuffer, type GPUContext, type GPUDevice, type GPUPipeline, HIGHEST_TYPE_FUNCTIONS, If, LOGICAL_OPERATORS, Loop, type NodeConfig, type NodeProps, type NodeProxy, type NodeTypes, OPERATORS, OPERATOR_KEYS, type Operators, PRESERVE_TYPE_FUNCTIONS, type PrecisionMode, SCALAR_RETURN_FUNCTIONS, SWIZZLES, Switch, type Swizzles, TYPE_MAPPING, type Uniform, type Uniforms, VEC3_RETURN_FUNCTIONS, VEC4_RETURN_FUNCTIONS, WGSL_TO_GLSL_BUILTIN, type WebGLState, type WebGPUState, type X, abs, acos, alignTo256, all, any, asin, assign, atan, atan2, attribute, bitcast, bool, builtin, bvec2, bvec3, bvec4, cbrt, ceil, clamp, code, color, conversion, cos, createAttrib, createBindGroup, createBufferLayout, createDescriptor, createDevice, createGL, createIbo, createPipeline, createProgram, createTexture, createTextureSampler, createUniformBuffer, createVbo, createVertexBuffer, cross, cubeTexture, dFdx, dFdy, createGL as default, defaultFragmentGLSL, defaultVertexGLSL, degrees, difference, dig, distance, dot, each, equals, exp, exp2, ext, faceforward, fig, float, floor, flush, formatConversions, fract,
|
|
615
|
+
export { ADDITIONAL_FUNCTIONS, type Attribute, type Attributes, BOOL_RETURN_FUNCTIONS, BUILTIN_TYPES, COMPARISON_OPERATORS, COMPONENT_COUNT_TO_TYPE, CONSTANTS, CONVERSIONS, type Constants, type Conversions, FIRST_ARG_TYPE_FUNCTIONS, FUNCTIONS, Fn, type FnLayout, type Functions, type GL, type GLClearMode, type GLDrawMode, type GLDrawType, type GPUBindGroup, type GPUBuffer, type GPUContext, type GPUDevice, type GPUPipeline, HIGHEST_TYPE_FUNCTIONS, If, LOGICAL_OPERATORS, Loop, type NodeConfig, type NodeProps, type NodeProxy, type NodeTypes, OPERATORS, OPERATOR_KEYS, type Operators, PRESERVE_TYPE_FUNCTIONS, type PrecisionMode, SCALAR_RETURN_FUNCTIONS, SWIZZLES, Switch, type Swizzles, TYPE_MAPPING, type Uniform, type Uniforms, VEC3_RETURN_FUNCTIONS, VEC4_RETURN_FUNCTIONS, WGSL_TO_GLSL_BUILTIN, type WebGLState, type WebGPUState, type X, abs, acos, alignTo256, all, any, asin, assign, atan, atan2, attribute, bitcast, bool, builtin, bvec2, bvec3, bvec4, cbrt, ceil, clamp, code, color, constant, conversion, conversionToConstant, cos, createAttrib, createBindGroup, createBufferLayout, createDescriptor, createDevice, createGL, createIbo, createPipeline, createProgram, createTexture, createTextureSampler, createUniformBuffer, createVbo, createVertexBuffer, cross, cubeTexture, dFdx, dFdy, createGL as default, defaultFragmentGLSL, defaultVertexGLSL, degrees, difference, dig, distance, dot, each, equals, exp, exp2, ext, faceforward, fig, float, floor, flush, formatConversions, fract, fragDepth, fragment, frontFacing, function_, fwidth, generateDefine, getBluiltin, getId, getOperator, getStride, hex2rgb, iMouse, iResolution, iTime, infer, inferImpl, instanceIndex, int, inverseSqrt, is, isConversion, isFunction, isGL, isNodeProxy, isOperator, isServer, isSwizzle, isWebGPUSupported, ivec2, ivec3, ivec4, joins, length, lengthSq, log, log2, mat2, mat3, mat4, max, 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, sampleIndex, sampleMask, saturate, screenCoordinate, screenUV, select, sig, sign, sin, smoothstep, sqrt, step, swizzle, tan, texture, textureSize, toVar, transformDirection, trunc, uint, uniform, uvec2, uvec3, uvec4, variable, varying, vec2, vec3, vec4, vertex, vertexIndex, webgl, webgpu };
|
package/dist/index.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import{durable as
|
|
2
|
-
`),
|
|
3
|
-
|
|
4
|
-
`)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
`)}
|
|
8
|
-
}`},de=(e,t,r=!0)=>r?`
|
|
1
|
+
import{durable as J,event as ft}from"reev";import{createFrame as lt,createQueue as mt}from"refr";import{nested as Z}from"reev";var v={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)},Ve=(e,t)=>e.forEach(t),bt=(e,...t)=>{Ve(e,r=>r(...t))},vt=(e="",t="_",r="/")=>e.split(t).join(r),yt=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",Xt=(e=0)=>`${e}`.split(".")[1]?.length??0,_t=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),Tt=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var Et=["x","y","z","w","r","g","b","a","s","t","p","q"],C=["bool","uint","int","float","bvec2","ivec2","uvec2","vec2","bvec3","ivec3","uvec3","vec3","bvec4","ivec4","uvec4","vec4","color","mat2","mat3","mat4"],B=["toBool","toUint","toInt","toFloat","toBvec2","toIvec2","toUvec2","toVec2","toBvec3","toIvec3","toUvec3","toVec3","toBvec4","toIvec4","toUvec4","toVec4","toColor","toMat2","toMat3","toMat4"],D={add:"+",sub:"-",mul:"*",div:"/",mod:"%",equal:"==",notEqual:"!=",lessThan:"<",lessThanEqual:"<=",greaterThan:">",greaterThanEqual:">=",and:"&&",or:"||",bitAnd:"&",bitOr:"|",bitXor:"^",shiftLeft:"<<",shiftRight:">>"},te=Object.keys(D),M=["dot","distance","length","lengthSq","determinant","luminance"],V=["all","any"],z=["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"],W=["cross"],q=["reflect","refract"],k=["min","max","mix","clamp","step","smoothstep"],Y=["texture","textureLod","textureSize","cubeTexture"],ze=["atan2","degrees","faceforward","bitcast","cbrt","difference","equals","pow","pow2","pow3","pow4","radians","transformDirection"],re=[...M,...V,...z,...W,...q,...k,...Y,...ze],oe={float:"f32",int:"i32",uint:"u32",bool:"bool",vec2:"vec2f",vec3:"vec3f",vec4:"vec4f",mat2:"mat2x2f",mat3:"mat3x3f",mat4:"mat4x4f",ivec2:"vec2i",ivec3:"vec3i",ivec4:"vec4i",uvec2:"vec2u",uvec3:"vec3u",uvec4:"vec4u",bvec2:"vec2<bool>",bvec3:"vec3<bool>",bvec4:"vec4<bool>"},j={1:"float",2:"vec2",3:"vec3",4:"vec4",9:"mat3",16:"mat4"},ne={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"},se=["equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual"],ie=["and","or"],ae={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 H=e=>v.str(e)&&/^[xyzwrgbastpq]{1,4}$/.test(e),ue=e=>te.includes(e),ce=e=>re.includes(e),pe=e=>B.includes(e),R=e=>!e||typeof e!="object"?!1:e.isProxy,fe=e=>{let t=(e>>16&255)/255,r=(e>>8&255)/255,o=(e&255)/255;return[t,r,o]},We=0,K=()=>`i${We++}`,I=(e,t)=>e.filter(r=>!v.und(r)&&!v.nul(r)).map(r=>c(r,t)).join(", "),L=(e,t)=>v.str(e)?t?.isWebGL?e:oe[e]:"",le=e=>D[e]||e,me=e=>ae[e],de=e=>{let t=B.indexOf(e);return t!==-1?C[t]:"float"},xe=e=>Array.from(e.headers).map(([,t])=>t).join(`
|
|
2
|
+
`),ge=(e,t)=>{let{id:r,children:o=[],layout:n}=e,[s,a,...u]=o,d=n?.type&&n?.type!=="auto"?n?.type:a?T(a,t):"void",l=[],p=[];if(n?.inputs)for(let b of n.inputs)l.push([b.name,b.type]);else for(let b=0;b<u.length;b++)l.push([`p${b}`,T(u[b],t)]);let f="";if(t?.isWebGL){for(let[b,E]of l)p.push(`${E} ${b}`);f+=`${d} ${r}(${p}) {
|
|
3
|
+
`}else{for(let[b,E]of l)p.push(`${b}: ${L(E,t)}`);f+=`fn ${r}(${p}) -> ${L(d,t)} {
|
|
4
|
+
`}let N=c(s,t);return N&&(f+=N+`
|
|
5
|
+
`),a&&(f+=`return ${c(a,t)};`),f+=`
|
|
6
|
+
}`,f},qe=`
|
|
9
7
|
#version 300 es
|
|
10
8
|
precision mediump float;
|
|
11
9
|
out vec4 fragColor;
|
|
12
|
-
|
|
13
|
-
void main() {
|
|
14
|
-
fragColor = ${e};
|
|
15
|
-
}`.trim():`
|
|
16
|
-
${t}
|
|
10
|
+
`.trim(),ke=`
|
|
17
11
|
@fragment
|
|
18
12
|
fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
|
19
|
-
return
|
|
20
|
-
|
|
13
|
+
`.trim(),Ye=(e,t,r=!0)=>{let o="";return r&&(o+=qe),t&&(o+=`
|
|
14
|
+
`+t+`
|
|
15
|
+
`),r?o+=`void main() {
|
|
16
|
+
fragColor = ${e};`:(o+=ke+`
|
|
17
|
+
`,o+=` return ${e};`),o+=`
|
|
18
|
+
}`,o},je=(e,t,r=!0)=>"",F=(e,t={})=>{let r=c(e,t),o=xe(t),n=Ye(r,o,t.isWebGL);return console.log(`// \u2193\u2193\u2193 generated \u2193\u2193\u2193
|
|
21
19
|
|
|
22
|
-
${
|
|
20
|
+
${n}
|
|
23
21
|
|
|
24
|
-
`),
|
|
25
|
-
`);if(r==="assign")return`${
|
|
26
|
-
${
|
|
27
|
-
}
|
|
28
|
-
${
|
|
29
|
-
}`;
|
|
30
|
-
${
|
|
31
|
-
}
|
|
32
|
-
${
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
`),n},U=(e,t)=>{let r=c(e,t),o=xe(t);return je(r,o,t.isWebGL)};var He=(e,t)=>e.reduce((r,o)=>{let n=T(o,t),s=C.indexOf(r);return C.indexOf(n)>s?n:r},"float"),Ke=e=>ne[e],Ze=(e,t,r)=>{let o=t.length>0?T(t[0],r):"float";return q.includes(e)?o:M.includes(e)?"float":V.includes(e)?"bool":z.includes(e)?o:W.includes(e)?"vec3":Y.includes(e)?"vec4":k.includes(e)?He(t,r):o},be=(e,t,r)=>{if(se.includes(r)||ie.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 o=C.indexOf(e),n=C.indexOf(t);return o>=n?e:t},Qe=e=>v.bol(e)?"bool":v.num(e)?"float":v.arr(e)&&j[e.length]||"float",Je=e=>j[e],et=(e,t)=>{let{type:r,props:o}=e,{id:n,children:s=[],inferFrom:a}=o,[u,d,l]=s;return a?T(a,t):r==="conversion"?u:r==="operator"?be(T(d,t),T(l,t),u):r==="function"?Ze(u,s.slice(1),t):r==="swizzle"?Je(u.length):r==="ternary"?be(T(d,t),T(l,t),"add"):r==="builtin"?Ke(n):r==="define"?o.layout?.type&&o.layout?.type!=="auto"?o.layout.type:d?T(d,t):"void":T(u,t)},T=(e,t)=>{if(t||(t={}),!R(e))return Qe(e);if(t.infers||(t.infers=new WeakMap),t.infers.has(e))return t.infers.get(e);let r=et(e,t);return t.infers.set(e,r),r};var c=(e,t)=>{if(t||(t={}),t.headers||(t.headers=new Map),v.str(e))return e;if(v.num(e)){let p=`${e}`;return p.includes(".")?p:p+".0"}if(v.bol(e))return e?"true":"false";if(!e)return"";let{type:r,props:o}=e,{id:n="",children:s=[]}=o,[a,u,d]=s,l="";if(r==="attribute"){if(t.headers.has(n))return n;l=`${T(e,t)} ${n}`}if(r==="uniform"){if(t.headers.has(n))return n;t.binding||(t.binding=0);let p=T(e,t);l=t.isWebGL?`uniform ${p} ${n};`:`@group(0) @binding(${t.binding++}) var<uniform> ${n}: ${L(p,t)};`}if(r==="constant"){if(t.headers.has(n))return n;let p=T(e,t),f=c(a,t);l=t.isWebGL?`const ${p} ${n} = ${f};`:`const ${n}: ${L(p,t)} = ${f};`}if(r==="varying"){if(t.headers.has(n))return n;l=`${T(e,t)} ${n}`}if(l)return t.headers.set(n,l),t.onMount?.(n),n;if(r==="variable")return n;if(r==="swizzle")return`${c(u,t)}.${c(a,t)}`;if(r==="ternary")return`(${c(a,t)} ? ${c(u,t)} : ${c(d,t)})`;if(r==="builtin")return t?.isWebGL?me(n):n;if(r==="conversion")return`${L(a,t)}(${I(s.slice(1),t)})`;if(r==="operator")return a==="not"||a==="bitNot"?`!${c(u,t)}`:`(${c(u,t)} ${le(a)} ${c(d,t)})`;if(r==="function")return a==="negate"?`(-${I(s.slice(1),t)})`:`${a}(${I(s.slice(1),t)})`;if(r==="scope")return s.map(p=>c(p,t)).join(`
|
|
23
|
+
`);if(r==="assign")return`${c(a,t)} = ${c(u,t)};`;if(r==="loop")return t.isWebGL?`for (int i = 0; i < ${a}; i += 1) {
|
|
24
|
+
${c(u,t)}
|
|
25
|
+
}`:`for (var i: i32 = 0; i < ${a}; i++) {
|
|
26
|
+
${c(u,t)}
|
|
27
|
+
}`;if(r==="define"){let p=s.slice(2),f=`${n}(${p.map(N=>c(N,t))})`;return t.headers.has(n)||t.headers.set(n,ge(o,t)),f}if(r==="if"){let p=`if (${c(a,t)}) {
|
|
28
|
+
${c(u,t)}
|
|
29
|
+
}`;for(let f=2;f<s.length;f+=2){let N=f>=s.length-1;p+=N?` else {
|
|
30
|
+
${c(s[f],t)}
|
|
31
|
+
}`:` else if (${c(s[f],t)}) {
|
|
32
|
+
${c(s[f+1],t)}
|
|
33
|
+
}`}return p}if(r==="switch"){let p=`switch (${c(a,t)}) {
|
|
34
|
+
`;for(let f=1;f<s.length;f+=2)f>=s.length-1&&s.length%2===0?p+=`default:
|
|
35
|
+
${c(s[f],t)}
|
|
36
36
|
break;
|
|
37
|
-
`:
|
|
38
|
-
${
|
|
37
|
+
`:f+1<s.length&&(p+=`case ${c(s[f],t)}:
|
|
38
|
+
${c(s[f+1],t)}
|
|
39
39
|
break;
|
|
40
|
-
`);return
|
|
40
|
+
`);return p+="}",p}if(r==="declare"){let p=T(a,t),f=u?.props?.id;if(t.isWebGL)return`${p} ${f} = ${c(a,t)};`;let N=L(p);return`var ${f}: ${N} = ${c(a,t)};`}return c(a,t)};var w=null,O=(e,t=()=>{})=>{let r=w;w=e,t(),w=r},G=e=>{w&&(w.props.children||(w.props.children=[]),w.props.children.push(e))},ve=(e,t)=>{t||(t=K());let r=m("variable",{id:t,inferFrom:e}),o=m("declare",null,e,r);return G(o),r},ye=(e,t)=>{let r=m("assign",null,e,t);return G(r),e},Vt=(e,t)=>{let r=m("scope");O(r,t);let o=m("if",null,e,r);G(o);let n=()=>({ElseIf:(s,a)=>{let u=m("scope");return O(u,a),o.props.children.push(s,u),n()},Else:s=>{let a=m("scope");O(a,s),o.props.children.push(a)}});return n()},zt=(e,t)=>{let r=m("scope");O(r,()=>t({i:m("variable",{id:"i",inferFrom:Xe(0)})}));let o=m("loop",null,e,r);return G(o),o},Wt=e=>{let t=m("switch",null,e);G(t);let r=()=>({Case:(...o)=>n=>{let s=m("scope");O(s,n);for(let a of o)t.props.children.push(a,s);return r()},Default:o=>{let n=m("scope");O(n,o),t.props.children.push(n)}});return r()},qt=e=>{let t,r=(...o)=>{let n=t?.name||K(),s=m("scope"),a,u=[],d=[];if(t?.inputs)for(let l of t.inputs)d.push({id:l.name,inferFrom:y(l.type)});else for(let l=0;l<o.length;l++)d.push({id:`p${l}`,inferFrom:o[l]});for(let l of d)u.push(m("variable",l));return O(s,()=>a=e(u)),m("define",{id:n,layout:t},s,a,...o)};return r.setLayout=o=>(t=o,r),r};var tt=(e,t)=>{if(t==="string")return c(e)},m=(e,t,...r)=>{t||(t={}),r.length&&(t.children=r);let o=(a,u)=>{if(u==="type")return e;if(u==="props")return t;if(u==="toVar")return ve.bind(null,s);if(u==="assign")return ye.bind(null,s);if(u==="isProxy")return!0;if(u==="toString")return c.bind(null,s);if(u===Symbol.toPrimitive)return tt.bind(null,s);if(H(u))return _e(u,s);if(ue(u))return(...d)=>rt(u,s,...d);if(ce(u))return(...d)=>i(u,s,...d);if(pe(u))return()=>y(de(u),s)},n=(a,u,d)=>H(u)?(_e(u,s).assign(d),!0):!1,s=new Proxy({},{get:o,set:n});return s},Kt=(e,t)=>m("varying",{id:t},e),A=(e,t)=>m("uniform",{id:t},e),Zt=(e,t)=>m("varying",{id:t},e),Qt=(e,t)=>m("constant",{id:t},e),Jt=e=>m("variable",{id:e}),h=e=>m("builtin",{id:e}),_e=(e,t)=>m("swizzle",null,e,t),rt=(e,...t)=>m("operator",null,e,...t),i=(e,...t)=>m("function",null,e,...t),y=(e,...t)=>m("conversion",null,e,...t),er=(e,t,r)=>m("ternary",null,e,t,r);var sr=h("position"),ir=h("vertex_index"),ar=h("instance_index"),ur=h("front_facing"),cr=h("frag_depth"),pr=h("sample_index"),fr=h("sample_mask"),lr=h("point_coord"),mr=h("normalLocal"),dr=h("normalWorld"),xr=h("normalView"),gr=h("position"),br=h("positionWorld"),vr=h("positionView"),yr=h("screenCoordinate"),Xr=h("screenUV"),ot=e=>y("float",e),Xe=e=>y("int",e),_r=e=>y("uint",e),Tr=e=>y("bool",e),he=(e,t)=>y("vec2",e,t),Te=(e,t,r)=>y("vec3",e,t,r),hr=(e,t,r,o)=>y("vec4",e,t,r,o),Er=(...e)=>y("mat2",...e),Nr=(...e)=>y("mat3",...e),Pr=(...e)=>y("mat4",...e),Sr=(e,t)=>y("ivec2",e,t),Rr=(e,t,r)=>y("ivec3",e,t,r),Cr=(e,t,r,o)=>y("ivec4",e,t,r,o),Lr=(e,t)=>y("uvec2",e,t),wr=(e,t,r)=>y("uvec3",e,t,r),Or=(e,t,r,o)=>y("uvec4",e,t,r,o),Gr=(e,t)=>y("bvec2",e,t),Ir=(e,t,r)=>y("bvec3",e,t,r),Fr=(e,t,r,o)=>y("bvec4",e,t,r,o),Ur=(e,t,r)=>v.num(e)&&v.und(t)&&v.und(r)?Te(...fe(e)):Te(e,t,r),Ar=A(he(1280,800),"iResolution"),$r=A(he(0,0),"iMouse"),Br=A(ot(0),"iTime"),Dr=(e,t,r)=>i("texture",e,t,r),Mr=(e,t,r)=>i("cubeTexture",e,t,r),Vr=(e,t)=>i("textureSize",e,t),zr=e=>i("abs",e),Wr=e=>i("acos",e),qr=e=>i("all",e),kr=e=>i("any",e),Yr=e=>i("asin",e),jr=(e,t)=>t!==void 0?i("atan",e,t):i("atan",e),Hr=(e,t)=>i("atan",e,t),Kr=(e,t)=>i("bitcast",e,t),Zr=e=>i("cbrt",e),Qr=e=>i("ceil",e),Jr=(e,t,r)=>i("clamp",e,t,r),eo=e=>i("cos",e),to=(e,t)=>i("cross",e,t),ro=e=>i("dFdx",e),oo=e=>i("dFdy",e),no=e=>i("degrees",e),so=(e,t)=>i("difference",e,t),io=(e,t)=>i("distance",e,t),ao=(e,t)=>i("dot",e,t),uo=(e,t)=>i("equals",e,t),co=e=>i("exp",e),po=e=>i("exp2",e),fo=(e,t,r)=>i("faceforward",e,t,r),lo=e=>i("floor",e),mo=e=>i("fract",e),xo=e=>i("fwidth",e),go=e=>i("inverseSqrt",e),bo=e=>i("length",e),vo=e=>i("lengthSq",e),yo=e=>i("log",e),Xo=e=>i("log2",e),_o=(e,t)=>i("max",e,t),To=(e,t)=>i("min",e,t),ho=(e,t,r)=>i("mix",e,t,r),Eo=e=>i("negate",e),No=e=>i("normalize",e),Po=e=>i("oneMinus",e),So=(e,t)=>i("pow",e,t),Ro=e=>i("pow2",e),Co=e=>i("pow3",e),Lo=e=>i("pow4",e),wo=e=>i("radians",e),Oo=e=>i("reciprocal",e),Go=(e,t)=>i("reflect",e,t),Io=(e,t,r)=>i("refract",e,t,r),Fo=e=>i("round",e),Uo=e=>i("saturate",e),Ao=e=>i("sign",e),$o=e=>i("sin",e),Bo=(e,t,r)=>i("smoothstep",e,t,r),Do=e=>i("sqrt",e),Mo=(e,t)=>i("step",e,t),Vo=e=>i("tan",e),zo=(e,t)=>i("transformDirection",e,t),Wo=e=>i("trunc",e);var nt=`
|
|
41
41
|
#version 300 es
|
|
42
42
|
void main() {
|
|
43
43
|
float x = float(gl_VertexID % 2) * 4.0 - 1.0;
|
|
44
44
|
float y = float(gl_VertexID / 2) * 4.0 - 1.0;
|
|
45
45
|
gl_Position = vec4(x, y, 0.0, 1.0);
|
|
46
46
|
}
|
|
47
|
-
`,
|
|
47
|
+
`,st=`
|
|
48
48
|
#version 300 es
|
|
49
49
|
precision mediump float;
|
|
50
50
|
uniform vec2 iResolution;
|
|
@@ -52,19 +52,19 @@ out vec4 fragColor;
|
|
|
52
52
|
void main() {
|
|
53
53
|
fragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
|
|
54
54
|
}
|
|
55
|
-
`,
|
|
55
|
+
`,Ee=(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}`)},Ne=(e,t=nt,r=st,o=()=>{})=>{R(r)&&(r=F(r,{isWebGL:!0})),R(t)&&(t=U(r,{isWebGL:!0}));let n=e.createProgram(),s=Ee(e,t,e.VERTEX_SHADER),a=Ee(e,r,e.FRAGMENT_SHADER);if(!s||!a)return o();if(e.attachShader(n,s),e.attachShader(n,a),e.linkProgram(n),e.getProgramParameter(n,e.LINK_STATUS))return n;let u=e.getProgramInfoLog(n);e.deleteProgram(n),o(),console.warn(`Could not link pg: ${u}`)},Pe=(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},Se=(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},Re=(e,t,r)=>{r&&(e=Math.max(...r)+1);let o=t.length/e;return Math.floor(o)},Ce=(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)},Le=(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 we=async e=>{let t=e.el.getContext("webgl2"),r=Ne(t,e.vs,e.fs,()=>void(e.isLoop=!1));t.useProgram(r);let o=0,n=Z(b=>t.getUniformLocation(r,b)),s=Z(b=>t.getAttribLocation(r,b)),a=Z(()=>o++);return{webgl:{context:t,program:r},render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(r),_attribute:(b="",E,P)=>{let S=s(b,!0),_=Pe(t,E),x=Se(t,P),g=Re(e.count,E,P);Ce(t,g,S,_,x)},_uniform:(b,E)=>{let P=n(b);if(v.num(E))return t.uniform1f(P,E);let S=E.length;if(S<=4)return t[`uniform${S}fv`](P,E);S=Math.sqrt(S)<<0,t[`uniformMatrix${S}fv`](P,!1,E)},_texture:(b,E)=>{let P=new Image;Object.assign(P,{src:E,crossOrigin:"anonymous"}),P.decode().then(()=>{let S=n(b),_=a(b);Le(t,P,S,_)})}}};import{nested as Q}from"reev";var it=`
|
|
56
56
|
@vertex
|
|
57
57
|
fn main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4f {
|
|
58
58
|
let x = f32(vertex_index % 2u) * 4.0 - 1.0;
|
|
59
59
|
let y = f32(vertex_index / 2u) * 4.0 - 1.0;
|
|
60
60
|
return vec4f(x, y, 0.0, 1.0);
|
|
61
61
|
}
|
|
62
|
-
`,
|
|
62
|
+
`,at=`
|
|
63
63
|
@group(0) @binding(0) var<uniform> iResolution: vec2f;
|
|
64
64
|
|
|
65
65
|
@fragment
|
|
66
66
|
fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
|
67
67
|
return vec4f(position.xy / iResolution, 0.0, 1.0);
|
|
68
68
|
}
|
|
69
|
-
`,
|
|
69
|
+
`,Oe=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}},Ge=(e,t,r,o,n=it,s=at)=>{R(n)&&(n=U(n,{isWebGL:!1})),R(s)&&(s=F(s,{isWebGL:!1}));let a=e.createPipelineLayout({bindGroupLayouts:o});return e.createRenderPipeline({vertex:{module:e.createShaderModule({code:n.trim()}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({code:s.trim()}),entryPoint:"main",targets:[{format:t}]},layout:a,primitive:{topology:"triangle-list"}})},Ie=(e,t)=>{let r=[],o=[];t.forEach((a,u)=>{if(!a)return;let d="buffer"in a,l=a instanceof GPUTextureView,p=a instanceof GPUSampler;if(d)r.push({binding:u,visibility:3,buffer:{type:"uniform"}});else if(l)r.push({binding:u,visibility:2,texture:{}});else if(p)r.push({binding:u,visibility:2,sampler:{}});else return;o.push({binding:u,resource:a})});let n=e.createBindGroupLayout({entries:r}),s=e.createBindGroup({layout:n,entries:o});return{layout:n,bindGroup:s}},Fe=e=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),ut=e=>Math.ceil(e/256)*256,Ue=(e,t)=>{let r=new Float32Array(t),o=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:o}},Ae=(e,t)=>{let r=new Float32Array(t),o=ut(r.byteLength),n=e.createBuffer({size:o,usage:72});return{array:r,buffer:n}},$e=(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}},ct=(e,t)=>e/t,pt=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",Be=(e,t,r=6)=>{let o=ct(t,r);return{arrayStride:o*4,attributes:[{shaderLocation:e,offset:0,format:pt(o)}]}};var De=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:o}=await Oe(t),n={device:r,context:t,resources:[[],[]],loadingImg:0,needsUpdate:!0},s=[],a=[],u=[],d=Q((_,x)=>{let{array:g,buffer:X}=Ue(r,x);return a.push(X),u.push(Be(u.length,g.length,e.count)),n.needsUpdate=!0,{array:g,buffer:X}}),l=Q((_,x)=>{let{array:g,buffer:X}=Ae(r,x);return n.resources[0].push({buffer:X}),n.needsUpdate=!0,{array:g,buffer:X}}),p=Q((_,{width:x,height:g})=>{let{texture:X,sampler:$}=$e(r,x,g);return n.resources[1].push($,X.createView()),n.needsUpdate=!0,{texture:X,width:x,height:g}}),f=()=>{let _=[];s.length=0,n.resources.forEach(x=>{if(!x.length)return;let{layout:g,bindGroup:X}=Ie(r,x);_.push(g),s.push(X)}),n.pipeline=Ge(r,o,u,_,e.vs,e.fs)};return{webgpu:n,render:()=>{if(n.loadingImg)return;n.needsUpdate&&f(),n.needsUpdate=!1;let _=r.createCommandEncoder(),x=_.beginRenderPass(Fe(t));x.setPipeline(n.pipeline),s.forEach((g,X)=>x.setBindGroup(X,g)),a.forEach((g,X)=>x.setVertexBuffer(X,g)),x.draw(e.count,1,0,0),x.end(),r.queue.submit([_.finish()])},clean:()=>{},_attribute:(_="",x)=>{let{array:g,buffer:X}=d(_,x);r.queue.writeBuffer(X,0,g)},_uniform:(_,x)=>{v.num(x)&&(x=[x]);let{array:g,buffer:X}=l(_,x);g.set(x),r.queue.writeBuffer(X,0,g)},_texture:(_,x)=>{n.loadingImg++;let g=Object.assign(new Image,{src:x,crossOrigin:"anonymous"});g.decode().then(()=>{let{texture:X,width:$,height:Me}=p(_,g);r.queue.copyExternalImageToTexture({source:g},{texture:X},{width:$,height:Me}),n.loadingImg--})}}};var bn=e=>v.obj(e)?"isGL"in e:!1,dt=()=>typeof window>"u",xt=()=>dt()?!1:"gpu"in navigator,ee=performance.now(),gt=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=mt(),t.frame=lt(),t.attribute=J((r,o,n)=>t.queue(()=>t._attribute?.(r,o,n))),t.texture=J((r,o)=>t.queue(()=>t._texture?.(r,o))),t.uniform=J((r,o,n)=>t.queue(()=>t._uniform?.(r,o,n))),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:ee}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex,t.fs=t.fs||t.frag||t.fragment,xt()||(t.isWebGL=!0),t.isWebGL?t(await we(t)):t(await De(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,a]=t.size,{top:u,left:d}=t.el.getBoundingClientRect();t.mouse[0]=(o-u-s/2)/(s/2),t.mouse[1]=-(n-d-a/2)/(a/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{ee=performance.now()/1e3,t.uniform("iTime",ee)}),t(e)},vn=gt;export{ze as ADDITIONAL_FUNCTIONS,V as BOOL_RETURN_FUNCTIONS,ne as BUILTIN_TYPES,se as COMPARISON_OPERATORS,j as COMPONENT_COUNT_TO_TYPE,C as CONSTANTS,B as CONVERSIONS,q as FIRST_ARG_TYPE_FUNCTIONS,re as FUNCTIONS,qt as Fn,k as HIGHEST_TYPE_FUNCTIONS,Vt as If,ie as LOGICAL_OPERATORS,zt as Loop,D as OPERATORS,te as OPERATOR_KEYS,z as PRESERVE_TYPE_FUNCTIONS,M as SCALAR_RETURN_FUNCTIONS,Et as SWIZZLES,Wt as Switch,oe as TYPE_MAPPING,W as VEC3_RETURN_FUNCTIONS,Y as VEC4_RETURN_FUNCTIONS,ae as WGSL_TO_GLSL_BUILTIN,zr as abs,Wr as acos,ut as alignTo256,qr as all,kr as any,Yr as asin,ye as assign,jr as atan,Hr as atan2,Kt as attribute,Kr as bitcast,Tr as bool,h as builtin,Gr as bvec2,Ir as bvec3,Fr as bvec4,Zr as cbrt,Qr as ceil,Jr as clamp,c as code,Ur as color,Qt as constant,y as conversion,de as conversionToConstant,eo as cos,Ce as createAttrib,Ie as createBindGroup,Be as createBufferLayout,Fe as createDescriptor,Oe as createDevice,gt as createGL,Se as createIbo,Ge as createPipeline,Ne as createProgram,Le as createTexture,$e as createTextureSampler,Ae as createUniformBuffer,Pe as createVbo,Ue as createVertexBuffer,to as cross,Mr as cubeTexture,ro as dFdx,oo as dFdy,vn as default,st as defaultFragmentGLSL,nt as defaultVertexGLSL,no as degrees,so as difference,_t as dig,io as distance,ao as dot,Ve as each,uo as equals,co as exp,po as exp2,yt as ext,fo as faceforward,Xt as fig,ot as float,lo as floor,bt as flush,L as formatConversions,mo as fract,cr as fragDepth,F as fragment,ur as frontFacing,i as function_,xo as fwidth,ge as generateDefine,me as getBluiltin,K as getId,le as getOperator,Re as getStride,fe as hex2rgb,$r as iMouse,Ar as iResolution,Br as iTime,T as infer,et as inferImpl,ar as instanceIndex,Xe as int,go as inverseSqrt,v as is,pe as isConversion,ce as isFunction,bn as isGL,R as isNodeProxy,ue as isOperator,dt as isServer,H as isSwizzle,xt as isWebGPUSupported,Sr as ivec2,Rr as ivec3,Cr as ivec4,I as joins,bo as length,vo as lengthSq,yo as log,Xo as log2,Er as mat2,Nr as mat3,Pr as mat4,_o as max,To as min,ho as mix,Eo as negate,m as node,mr as normalLocal,xr as normalView,dr as normalWorld,No as normalize,Po as oneMinus,rt as operator,lr as pointCoord,sr as position,gr as positionLocal,vr as positionView,br as positionWorld,So as pow,Ro as pow2,Co as pow3,Lo as pow4,wo as radians,Oo as reciprocal,Go as reflect,Io as refract,vt as replace,Fo as round,pr as sampleIndex,fr as sampleMask,Uo as saturate,yr as screenCoordinate,Xr as screenUV,er as select,Tt as sig,Ao as sign,$o as sin,Bo as smoothstep,Do as sqrt,Mo as step,_e as swizzle,Vo as tan,Dr as texture,Vr as textureSize,ve as toVar,zo as transformDirection,Wo as trunc,_r as uint,A as uniform,Lr as uvec2,wr as uvec3,Or as uvec4,Jt as variable,Zt as varying,he as vec2,Te as vec3,hr as vec4,U as vertex,ir as vertexIndex,we as webgl,De as webgpu};
|
|
70
70
|
//# sourceMappingURL=index.js.map
|