glre 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -9
- package/dist/index.cjs +66 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +547 -0
- package/dist/index.js +39 -21
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +66 -0
- package/dist/native.cjs.map +1 -0
- package/dist/native.d.cts +53 -0
- package/dist/native.js +39 -21
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +66 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +8 -0
- package/dist/react.js +40 -22
- package/dist/react.js.map +1 -1
- package/dist/solid.cjs +66 -0
- package/dist/solid.cjs.map +1 -0
- package/dist/solid.d.cts +8 -0
- package/dist/solid.js +40 -22
- package/dist/solid.js.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +0 -2
- package/src/native.ts +2 -2
- package/src/node/code.ts +103 -0
- package/src/node/const.ts +158 -98
- package/src/node/index.ts +109 -82
- package/src/node/infer.ts +93 -0
- package/src/node/node.ts +43 -92
- package/src/node/scope.ts +121 -0
- package/src/node/types.ts +120 -86
- package/src/node/utils.ts +95 -0
- package/src/utils/pipeline.ts +4 -5
- package/src/utils/program.ts +13 -9
- package/src/webgl.ts +1 -1
- package/src/webgpu.ts +2 -2
- package/dist/index.d.ts +0 -399
- package/dist/index.mjs +0 -48
- package/dist/index.mjs.map +0 -1
- package/dist/native.d.ts +0 -53
- package/dist/native.mjs +0 -48
- package/dist/native.mjs.map +0 -1
- package/dist/react.d.ts +0 -8
- package/dist/react.mjs +0 -48
- package/dist/react.mjs.map +0 -1
- package/dist/solid.d.ts +0 -8
- package/dist/solid.mjs +0 -48
- package/dist/solid.mjs.map +0 -1
- package/src/code/glsl.ts +0 -148
- package/src/code/wgsl.ts +0 -134
- package/src/node/cache.ts +0 -60
- package/src/node/conv.ts +0 -111
- package/src/node/uniform.ts +0 -92
package/src/webgpu.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { nested as cached } from 'reev'
|
|
2
2
|
import { is } from './utils/helpers'
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
createDevice,
|
|
5
5
|
createPipeline,
|
|
6
6
|
createDescriptor,
|
|
7
7
|
createUniformBuffer,
|
|
@@ -14,7 +14,7 @@ import type { GL, WebGPUState } from './types'
|
|
|
14
14
|
|
|
15
15
|
export const webgpu = async (gl: Partial<GL>) => {
|
|
16
16
|
const c = gl.el!.getContext('webgpu') as any
|
|
17
|
-
const { device, format } = await
|
|
17
|
+
const { device, format } = await createDevice(c)
|
|
18
18
|
const state = {
|
|
19
19
|
device,
|
|
20
20
|
context: c,
|
package/dist/index.d.ts
DELETED
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
import * as refr from 'refr';
|
|
2
|
-
import { Queue, Frame } from 'refr';
|
|
3
|
-
export { Frame, Fun, Queue } from 'refr';
|
|
4
|
-
import { EventState } from 'reev';
|
|
5
|
-
|
|
6
|
-
declare const TYPES: readonly ["float", "int", "uint", "bool", "color", "vec2", "vec3", "vec4", "mat2", "mat3", "mat4", "ivec2", "ivec3", "ivec4", "uvec2", "uvec3", "uvec4", "bvec2", "bvec3", "bvec4"];
|
|
7
|
-
type NodeType = (typeof TYPES)[number];
|
|
8
|
-
declare const SWIZZLES: readonly ["x", "y", "z", "w", "r", "g", "b", "a", "s", "t", "p", "q"];
|
|
9
|
-
type AllSwizzles<T extends string> = T | `${T}${T}` | `${T}${T}${T}` | `${T}${T}${T}${T}`;
|
|
10
|
-
type Swillzes = AllSwizzles<'x' | 'y' | 'z' | 'w'> | AllSwizzles<'r' | 'g' | 'b' | 'a'> | AllSwizzles<'p' | 'q'> | AllSwizzles<'s' | 't'>;
|
|
11
|
-
declare const OPERATORS: readonly ["add", "sub", "mul", "div", "mod", "equal", "notEqual", "lessThan", "lessThanEqual", "greaterThan", "greaterThanEqual", "and", "or", "not", "assign", "xor", "bitAnd", "bitNot", "bitOr", "bitXor", "shiftLeft", "shiftRight"];
|
|
12
|
-
type Operator = (typeof OPERATORS)[number];
|
|
13
|
-
declare const FUNCTIONS: readonly ["abs", "acos", "asin", "atan", "atan2", "ceil", "clamp", "cos", "cross", "degrees", "distance", "dot", "exp", "exp2", "faceforward", "floor", "fract", "length", "all", "any", "bitcast", "cbrt", "dFdx", "dFdy", "difference", "equals", "fwidth", "inverseSqrt", "lengthSq", "log", "log2", "max", "min", "mix", "negate", "normalize", "oneMinus", "pow", "pow2", "pow3", "pow4", "radians", "reciprocal", "reflect", "refract", "round", "saturate", "sign", "sin", "smoothstep", "sqrt", "step", "tan", "transformDirection", "trunc"];
|
|
14
|
-
type MathFunction = (typeof FUNCTIONS)[number];
|
|
15
|
-
declare const CACHE_BOOLS: readonly [true, false];
|
|
16
|
-
declare const CACHE_INTS: readonly [0, 1, 2, 3, 4, 5];
|
|
17
|
-
declare const CACHE_FLOATS: readonly [0, 1, 0.5, 2];
|
|
18
|
-
|
|
19
|
-
interface Node {
|
|
20
|
-
id: string;
|
|
21
|
-
type: NodeType;
|
|
22
|
-
value?: any;
|
|
23
|
-
property?: string;
|
|
24
|
-
parent?: Node;
|
|
25
|
-
children?: Node[];
|
|
26
|
-
operator?: Operator;
|
|
27
|
-
mathFunction?: MathFunction;
|
|
28
|
-
}
|
|
29
|
-
interface ProxyCallback {
|
|
30
|
-
path: string[];
|
|
31
|
-
args: any[];
|
|
32
|
-
}
|
|
33
|
-
type NodeCreator = (value?: any) => X;
|
|
34
|
-
interface OperatorMethods {
|
|
35
|
-
add(x: X | number): X;
|
|
36
|
-
sub(x: X | number): X;
|
|
37
|
-
mul(x: X | number): X;
|
|
38
|
-
div(x: X | number): X;
|
|
39
|
-
mod(x: X | number): X;
|
|
40
|
-
equal(x: X | number): X;
|
|
41
|
-
notEqual(x: X | number): X;
|
|
42
|
-
lessThan(x: X | number): X;
|
|
43
|
-
lessThanEqual(x: X | number): X;
|
|
44
|
-
greaterThan(x: X | number): X;
|
|
45
|
-
greaterThanEqual(x: X | number): X;
|
|
46
|
-
and(x: X): X;
|
|
47
|
-
or(x: X): X;
|
|
48
|
-
not(): X;
|
|
49
|
-
}
|
|
50
|
-
interface MathMethods {
|
|
51
|
-
abs(): X;
|
|
52
|
-
acos(): X;
|
|
53
|
-
asin(): X;
|
|
54
|
-
atan(): X;
|
|
55
|
-
ceil(): X;
|
|
56
|
-
cos(): X;
|
|
57
|
-
floor(): X;
|
|
58
|
-
fract(): X;
|
|
59
|
-
length(): X;
|
|
60
|
-
normalize(): X;
|
|
61
|
-
sin(): X;
|
|
62
|
-
sqrt(): X;
|
|
63
|
-
tan(): X;
|
|
64
|
-
toVar(): X;
|
|
65
|
-
}
|
|
66
|
-
type SwizzleProperties = {
|
|
67
|
-
[k in Swillzes]: X;
|
|
68
|
-
};
|
|
69
|
-
interface X extends MathMethods, OperatorMethods, SwizzleProperties {
|
|
70
|
-
readonly id: string;
|
|
71
|
-
readonly type: NodeType;
|
|
72
|
-
readonly value: any;
|
|
73
|
-
readonly property: string;
|
|
74
|
-
(...args: any[]): X;
|
|
75
|
-
}
|
|
76
|
-
interface UniformNode extends X {
|
|
77
|
-
set(value: any): void;
|
|
78
|
-
onObjectUpdate(callback: (context: any) => any): UniformNode;
|
|
79
|
-
onRenderUpdate(callback: (context: any) => any): UniformNode;
|
|
80
|
-
}
|
|
81
|
-
interface FunctionNode {
|
|
82
|
-
(...args: any[]): X;
|
|
83
|
-
call(x: X[]): X;
|
|
84
|
-
}
|
|
85
|
-
interface ConditionalNode {
|
|
86
|
-
ElseIf(condition: X, callback: () => void): ConditionalNode;
|
|
87
|
-
Else(callback: () => void): void;
|
|
88
|
-
}
|
|
89
|
-
interface ConversionContext {
|
|
90
|
-
target: 'webgl' | 'webgpu';
|
|
91
|
-
nodes: Map<string, Node>;
|
|
92
|
-
variables: Map<string, string>;
|
|
93
|
-
functions: Map<string, string>;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
declare const getCachedBool: (x: boolean) => X;
|
|
97
|
-
declare const getCachedInt: (x: number) => X;
|
|
98
|
-
declare const getCachedFloat: (x: number) => X;
|
|
99
|
-
declare const findDuplicateNodes: (nodes: X[]) => Map<string, X[]>;
|
|
100
|
-
|
|
101
|
-
declare const convertToNode: (x: unknown) => X;
|
|
102
|
-
declare const float: (x: unknown) => X;
|
|
103
|
-
declare const int: (x: unknown) => X;
|
|
104
|
-
declare const bool: (x: unknown) => X;
|
|
105
|
-
declare const vec2: (x?: any, y?: any) => X;
|
|
106
|
-
declare const vec3: (x?: any, y?: any, z?: any) => X;
|
|
107
|
-
declare const vec4: (x?: any, y?: any, z?: any, w?: any) => X;
|
|
108
|
-
declare const color: (r?: any, g?: any, b?: any) => X;
|
|
109
|
-
|
|
110
|
-
declare const createNode: (type: NodeType, value?: any, options?: Partial<Node>) => Node;
|
|
111
|
-
declare const node: (type: NodeType, value?: any, options?: Partial<Node>) => X;
|
|
112
|
-
|
|
113
|
-
interface UpdateContext {
|
|
114
|
-
object?: any;
|
|
115
|
-
camera?: any;
|
|
116
|
-
renderer?: any;
|
|
117
|
-
scene?: any;
|
|
118
|
-
time?: number;
|
|
119
|
-
}
|
|
120
|
-
declare const uniform: (initialValue: any) => UniformNode;
|
|
121
|
-
declare const iPrevTime: UniformNode;
|
|
122
|
-
declare const iDeltaTime: UniformNode;
|
|
123
|
-
declare const updateUniforms: (context: UpdateContext) => void;
|
|
124
|
-
|
|
125
|
-
declare const Fn: (jsFunc: Function) => FunctionNode;
|
|
126
|
-
declare const If: (condition: X, callback: () => void) => ConditionalNode;
|
|
127
|
-
declare const fragCoord: X;
|
|
128
|
-
declare const position: X;
|
|
129
|
-
declare const iTime: UniformNode;
|
|
130
|
-
declare const iResolution: UniformNode;
|
|
131
|
-
declare const iMouse: UniformNode;
|
|
132
|
-
declare const abs: (x: X) => X;
|
|
133
|
-
declare const sin: (x: X) => X;
|
|
134
|
-
declare const cos: (x: X) => X;
|
|
135
|
-
declare const tan: (x: X) => X;
|
|
136
|
-
declare const sqrt: (x: X) => X;
|
|
137
|
-
declare const floor: (x: X) => X;
|
|
138
|
-
declare const ceil: (x: X) => X;
|
|
139
|
-
declare const fract: (x: X) => X;
|
|
140
|
-
declare const normalize: (x: X) => X;
|
|
141
|
-
declare const length: (x: X) => X;
|
|
142
|
-
|
|
143
|
-
type GPUContext = any;
|
|
144
|
-
type GPUDevice = any;
|
|
145
|
-
type GPUBuffer = any;
|
|
146
|
-
type GPUPipeline = any;
|
|
147
|
-
type GPUBindGroup = any;
|
|
148
|
-
type Uniform = number | number[];
|
|
149
|
-
type Attribute = number[];
|
|
150
|
-
type Attributes = Record<string, Attribute>;
|
|
151
|
-
type Uniforms = Record<string, Uniform>;
|
|
152
|
-
type PrecisionMode = 'highp' | 'mediump' | 'lowp';
|
|
153
|
-
type GLClearMode = 'COLOR_BUFFER_BIT' | 'DEPTH_BUFFER_BIT' | 'STENCIL_BUFFER_BIT';
|
|
154
|
-
type GLDrawType = 'UNSIGNED_BYTE' | 'UNSIGNED_SHORT' | 'UNSIGNED_INT';
|
|
155
|
-
type GLDrawMode = 'POINTS' | 'LINE_STRIP' | 'LINE_LOOP' | 'LINES' | 'TRIANGLE_STRIP' | 'TRIANGLE_FAN' | 'TRIANGLES';
|
|
156
|
-
interface WebGLState {
|
|
157
|
-
context: WebGLRenderingContext;
|
|
158
|
-
program: WebGLProgram;
|
|
159
|
-
}
|
|
160
|
-
interface WebGPUState {
|
|
161
|
-
device: GPUDevice;
|
|
162
|
-
context: GPUContext;
|
|
163
|
-
pipeline: GPUPipeline;
|
|
164
|
-
groups: any[];
|
|
165
|
-
resources: any[];
|
|
166
|
-
loadingImg: number;
|
|
167
|
-
needsUpdate: boolean;
|
|
168
|
-
}
|
|
169
|
-
type GL = EventState<{
|
|
170
|
-
/**
|
|
171
|
-
* initial value
|
|
172
|
-
*/
|
|
173
|
-
isNative: boolean;
|
|
174
|
-
isWebGL: boolean;
|
|
175
|
-
isLoop: boolean;
|
|
176
|
-
isGL: true;
|
|
177
|
-
width: number;
|
|
178
|
-
height: number;
|
|
179
|
-
size: [number, number];
|
|
180
|
-
mouse: [number, number];
|
|
181
|
-
count: number;
|
|
182
|
-
el: HTMLCanvasElement;
|
|
183
|
-
vs: string | X;
|
|
184
|
-
fs: string | X;
|
|
185
|
-
vert: string | X;
|
|
186
|
-
frag: string | X;
|
|
187
|
-
vertex: string | X;
|
|
188
|
-
fragment: string | X;
|
|
189
|
-
/**
|
|
190
|
-
* core state
|
|
191
|
-
*/
|
|
192
|
-
webgpu: WebGPUState;
|
|
193
|
-
webgl: WebGLState;
|
|
194
|
-
queue: Queue;
|
|
195
|
-
frame: Frame;
|
|
196
|
-
/**
|
|
197
|
-
* events
|
|
198
|
-
*/
|
|
199
|
-
ref?: any;
|
|
200
|
-
init(): void;
|
|
201
|
-
loop(): void;
|
|
202
|
-
mount(): void;
|
|
203
|
-
clean(): void;
|
|
204
|
-
render(): void;
|
|
205
|
-
resize(e?: Event): void;
|
|
206
|
-
mousemove(e: Event): void;
|
|
207
|
-
/**
|
|
208
|
-
* setter
|
|
209
|
-
*/
|
|
210
|
-
_uniform?(key: string, value: Uniform, isMatrix?: boolean): GL;
|
|
211
|
-
uniform(key: string, value: Uniform, isMatrix?: boolean): GL;
|
|
212
|
-
uniform(target: {
|
|
213
|
-
[key: string]: Uniform;
|
|
214
|
-
}): GL;
|
|
215
|
-
_texture?(key: string, value: string): GL;
|
|
216
|
-
texture(key: string, value: string): GL;
|
|
217
|
-
texture(target: {
|
|
218
|
-
[key: string]: string;
|
|
219
|
-
}): GL;
|
|
220
|
-
_attribute?(key: string, value: Attribute, iboValue?: Attribute): GL;
|
|
221
|
-
attribute(key: string, value: Attribute, iboValue?: Attribute): GL;
|
|
222
|
-
attribute(target: {
|
|
223
|
-
[key: string]: Attribute;
|
|
224
|
-
}): GL;
|
|
225
|
-
}>;
|
|
226
|
-
|
|
227
|
-
interface GLSLContext extends ConversionContext {
|
|
228
|
-
target: 'webgl';
|
|
229
|
-
precision: 'lowp' | 'mediump' | 'highp';
|
|
230
|
-
version: '100' | '300 es';
|
|
231
|
-
}
|
|
232
|
-
declare const nodeToGLSL: (nodeProxy: X, context?: Partial<GLSLContext>) => string;
|
|
233
|
-
declare const glsl: (fragmentNode: X, options?: {
|
|
234
|
-
precision?: "lowp" | "mediump" | "highp";
|
|
235
|
-
version?: "100" | "300 es";
|
|
236
|
-
uniforms?: Record<string, any>;
|
|
237
|
-
}) => string;
|
|
238
|
-
|
|
239
|
-
interface WGSLContext extends ConversionContext {
|
|
240
|
-
target: 'webgpu';
|
|
241
|
-
}
|
|
242
|
-
declare const nodeToWGSL: (nodeProxy: X, context?: Partial<WGSLContext>) => string;
|
|
243
|
-
declare const wgsl: (fragmentNode: X, options?: {
|
|
244
|
-
uniforms?: Record<string, any>;
|
|
245
|
-
}) => string;
|
|
246
|
-
|
|
247
|
-
declare const is: {
|
|
248
|
-
arr: (arg: any) => arg is any[];
|
|
249
|
-
bol: (a: unknown) => a is boolean;
|
|
250
|
-
str: (a: unknown) => a is string;
|
|
251
|
-
num: (a: unknown) => a is number;
|
|
252
|
-
int: (a: unknown) => a is number;
|
|
253
|
-
fun: (a: unknown) => a is Function;
|
|
254
|
-
und: (a: unknown) => a is undefined;
|
|
255
|
-
nul: (a: unknown) => a is null;
|
|
256
|
-
set: (a: unknown) => a is Set<unknown>;
|
|
257
|
-
map: (a: unknown) => a is Map<unknown, unknown>;
|
|
258
|
-
obj: (a: unknown) => a is object;
|
|
259
|
-
nan: (a: unknown) => a is number;
|
|
260
|
-
};
|
|
261
|
-
/**
|
|
262
|
-
* each
|
|
263
|
-
*/
|
|
264
|
-
type EachFn<Value, Key, This> = (this: This, value: Value, key: Key) => void;
|
|
265
|
-
type Eachable<Value = any, Key = any, This = any> = {
|
|
266
|
-
forEach(cb: EachFn<Value, Key, This>, ctx?: This): void;
|
|
267
|
-
};
|
|
268
|
-
declare const each: <Value, Key, This>(obj: Eachable<Value, Key, This>, fn: EachFn<Value, Key, This>) => void;
|
|
269
|
-
declare const flush: <Value extends Function, Key, This>(obj: Eachable<Value, Key, This>, ...args: any[]) => void;
|
|
270
|
-
/**
|
|
271
|
-
* other
|
|
272
|
-
*/
|
|
273
|
-
declare const replace: (x?: string, from?: string, to?: string) => string;
|
|
274
|
-
declare const ext: (src?: string) => string;
|
|
275
|
-
declare const fig: (x?: number) => number;
|
|
276
|
-
declare const dig: (x?: number) => number;
|
|
277
|
-
declare const sig: (value?: number, digit?: number) => number;
|
|
278
|
-
|
|
279
|
-
declare const createDevive: (c: GPUContext) => Promise<{
|
|
280
|
-
device: any;
|
|
281
|
-
format: any;
|
|
282
|
-
}>;
|
|
283
|
-
declare const createPipeline: (device: GPUDevice, format: string, bufferLayouts: any[], bindGroupLayouts: any[], vs?: string | X, fs?: string | X) => GPUPipeline;
|
|
284
|
-
declare const createBindGroup: (device: GPUDevice, resources: any[]) => {
|
|
285
|
-
layout: any;
|
|
286
|
-
bindGroup: any;
|
|
287
|
-
};
|
|
288
|
-
declare const createDescriptor: (c: GPUContext) => {
|
|
289
|
-
colorAttachments: {
|
|
290
|
-
view: any;
|
|
291
|
-
clearValue: {
|
|
292
|
-
r: number;
|
|
293
|
-
g: number;
|
|
294
|
-
b: number;
|
|
295
|
-
a: number;
|
|
296
|
-
};
|
|
297
|
-
loadOp: string;
|
|
298
|
-
storeOp: string;
|
|
299
|
-
}[];
|
|
300
|
-
};
|
|
301
|
-
declare const alignTo256: (size: number) => number;
|
|
302
|
-
declare const createVertexBuffer: (device: GPUDevice, value: number[]) => {
|
|
303
|
-
array: Float32Array<ArrayBuffer>;
|
|
304
|
-
buffer: any;
|
|
305
|
-
};
|
|
306
|
-
declare const createUniformBuffer: (device: GPUDevice, value: number[]) => {
|
|
307
|
-
array: Float32Array<ArrayBuffer>;
|
|
308
|
-
buffer: Buffer;
|
|
309
|
-
};
|
|
310
|
-
declare const createTextureSampler: (device: GPUDevice, width?: number, height?: number) => {
|
|
311
|
-
texture: any;
|
|
312
|
-
sampler: any;
|
|
313
|
-
};
|
|
314
|
-
declare const createBufferLayout: (shaderLocation: number, dataLength: number, count?: number) => {
|
|
315
|
-
arrayStride: number;
|
|
316
|
-
attributes: {
|
|
317
|
-
shaderLocation: number;
|
|
318
|
-
offset: number;
|
|
319
|
-
format: string;
|
|
320
|
-
}[];
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
declare const defaultVertexGLSL = "\n#version 300 es\nvoid main() {\n float x = float(gl_VertexID % 2) * 4.0 - 1.0;\n float y = float(gl_VertexID / 2) * 4.0 - 1.0;\n gl_Position = vec4(x, y, 0.0, 1.0);\n}\n";
|
|
324
|
-
declare const defaultFragmentGLSL = "\n#version 300 es\nprecision mediump float;\nuniform vec2 iResolution;\nout vec4 fragColor;\nvoid main() {\n fragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);\n}\n";
|
|
325
|
-
declare const createProgram: (c: WebGLRenderingContext, vs?: string | X, fs?: string | X) => WebGLProgram;
|
|
326
|
-
declare const createVbo: (c: WebGLRenderingContext, data: number[]) => WebGLBuffer;
|
|
327
|
-
declare const createIbo: (c: WebGLRenderingContext, data: number[]) => WebGLBuffer;
|
|
328
|
-
declare const getStride: (count: number, value: number[], iboValue?: number[]) => number;
|
|
329
|
-
declare const createAttrib: (c: WebGLRenderingContext, stride: number, loc: any, vbo: WebGLBuffer, ibo?: WebGLBuffer) => void;
|
|
330
|
-
declare const createTexture: (c: WebGLRenderingContext, img: HTMLImageElement, loc: any, unit: number) => void;
|
|
331
|
-
|
|
332
|
-
declare const webgl: (gl: Partial<GL>) => Promise<{
|
|
333
|
-
webgl: WebGLState;
|
|
334
|
-
render: () => void;
|
|
335
|
-
clean: () => void;
|
|
336
|
-
_attribute: (key: string | undefined, value: number[], iboValue: number[]) => void;
|
|
337
|
-
_uniform: (key: string, value: number | number[]) => void;
|
|
338
|
-
_texture: (key: string, src: string) => void;
|
|
339
|
-
}>;
|
|
340
|
-
|
|
341
|
-
declare const webgpu: (gl: Partial<GL>) => Promise<{
|
|
342
|
-
webgpu: WebGPUState;
|
|
343
|
-
render: () => void;
|
|
344
|
-
clean: () => void;
|
|
345
|
-
_attribute: (key: string | undefined, value: number[]) => void;
|
|
346
|
-
_uniform: (key: string, value: number | number[]) => void;
|
|
347
|
-
_texture: (key: string, src: string) => void;
|
|
348
|
-
}>;
|
|
349
|
-
|
|
350
|
-
declare const isGL: (a: unknown) => a is EventState<GL>;
|
|
351
|
-
declare const isServer: () => boolean;
|
|
352
|
-
declare const isWebGPUSupported: () => boolean;
|
|
353
|
-
declare const createGL: (props?: Partial<GL>) => EventState<{
|
|
354
|
-
isNative: boolean;
|
|
355
|
-
isWebGL: boolean;
|
|
356
|
-
isLoop: boolean;
|
|
357
|
-
isGL: true;
|
|
358
|
-
width: number;
|
|
359
|
-
height: number;
|
|
360
|
-
size: [number, number];
|
|
361
|
-
mouse: [number, number];
|
|
362
|
-
count: number;
|
|
363
|
-
el: HTMLCanvasElement;
|
|
364
|
-
vs: string | X;
|
|
365
|
-
fs: string | X;
|
|
366
|
-
vert: string | X;
|
|
367
|
-
frag: string | X;
|
|
368
|
-
vertex: string | X;
|
|
369
|
-
fragment: string | X;
|
|
370
|
-
webgpu: WebGPUState;
|
|
371
|
-
webgl: WebGLState;
|
|
372
|
-
queue: refr.Queue;
|
|
373
|
-
frame: refr.Frame;
|
|
374
|
-
ref?: any;
|
|
375
|
-
init(): void;
|
|
376
|
-
loop(): void;
|
|
377
|
-
mount(): void;
|
|
378
|
-
clean(): void;
|
|
379
|
-
render(): void;
|
|
380
|
-
resize(e?: Event): void;
|
|
381
|
-
mousemove(e: Event): void;
|
|
382
|
-
_uniform?(key: string, value: Uniform, isMatrix?: boolean): GL;
|
|
383
|
-
uniform(key: string, value: Uniform, isMatrix?: boolean): GL;
|
|
384
|
-
uniform(target: {
|
|
385
|
-
[key: string]: Uniform;
|
|
386
|
-
}): GL;
|
|
387
|
-
_texture?(key: string, value: string): GL;
|
|
388
|
-
texture(key: string, value: string): GL;
|
|
389
|
-
texture(target: {
|
|
390
|
-
[key: string]: string;
|
|
391
|
-
}): GL;
|
|
392
|
-
_attribute?(key: string, value: Attribute, iboValue?: Attribute): GL;
|
|
393
|
-
attribute(key: string, value: Attribute, iboValue?: Attribute): GL;
|
|
394
|
-
attribute(target: {
|
|
395
|
-
[key: string]: Attribute;
|
|
396
|
-
}): GL;
|
|
397
|
-
}, any[] | unknown[]>;
|
|
398
|
-
|
|
399
|
-
export { Attribute, Attributes, CACHE_BOOLS, CACHE_FLOATS, CACHE_INTS, ConditionalNode, ConversionContext, FUNCTIONS, Fn, FunctionNode, GL, GLClearMode, GLDrawMode, GLDrawType, GPUBindGroup, GPUBuffer, GPUContext, GPUDevice, GPUPipeline, If, MathFunction, MathMethods, Node, NodeCreator, NodeType, OPERATORS, Operator, OperatorMethods, PrecisionMode, ProxyCallback, SWIZZLES, Swillzes, SwizzleProperties, TYPES, Uniform, UniformNode, Uniforms, WebGLState, WebGPUState, X, abs, alignTo256, bool, ceil, color, convertToNode, cos, createAttrib, createBindGroup, createBufferLayout, createDescriptor, createDevive, createGL, createIbo, createNode, createPipeline, createProgram, createTexture, createTextureSampler, createUniformBuffer, createVbo, createVertexBuffer, createGL as default, defaultFragmentGLSL, defaultVertexGLSL, dig, each, ext, fig, findDuplicateNodes, float, floor, flush, fract, fragCoord, getCachedBool, getCachedFloat, getCachedInt, getStride, glsl, iDeltaTime, iMouse, iPrevTime, iResolution, iTime, int, is, isGL, isServer, isWebGPUSupported, length, node, nodeToGLSL, nodeToWGSL, normalize, position, replace, sig, sin, sqrt, tan, uniform, updateUniforms, vec2, vec3, vec4, webgl, webgpu, wgsl };
|
package/dist/index.mjs
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import{durable as z,event as je}from"reev";import{createFrame as ke,createQueue as Ye}from"refr";import{nested as R}from"reev";var i={arr:Array.isArray,bol:e=>typeof e=="boolean",str:e=>typeof e=="string",num:e=>typeof e=="number",int:e=>Number.isInteger(e),fun:e=>typeof e=="function",und:e=>typeof e>"u",nul:e=>e===null,set:e=>e instanceof Set,map:e=>e instanceof Map,obj:e=>!!e&&e.constructor.name==="Object",nan:e=>typeof e=="number"&&Number.isNaN(e)},de=(e,t)=>e.forEach(t),Qe=(e,...t)=>{de(e,r=>r(...t))},Je=(e="",t="_",r="/")=>e.split(t).join(r),et=(e=".pdf")=>e.split(".").pop()?.toLowerCase()??"",tt=(e=0)=>`${e}`.split(".")[1]?.length??0,rt=(e=0)=>`${e}`.split(".")[0]?.length-(e<0?1:0),nt=(e=0,t=-2)=>(t*=-1,t=Math.pow(10,t),e*=t,e=Math.round(e),e/=t,e);var ge=(e,t)=>{let r={target:"webgl",precision:"mediump",version:"300 es",nodes:new Map,variables:new Map,functions:new Map,...t};return w(e,r)},w=(e,t)=>e?i.und(e.value)?e.property&&e.parent?`${w(e.parent,t)}.${e.property}`:e.operator&&e.children&&e.children.length>=2?be(e,t):e.mathFunction&&e.children&&e.children.length>=1?xe(e,t):"0.0":he(e.value,e.type):"0.0",he=(e,t)=>{if(t==="float"){let r=Number(e);return r%1===0?`${r}.0`:`${r}`}if(t==="int")return`${Math.floor(Number(e))}`;if(t==="bool")return e?"true":"false";if(i.arr(e)){let r=e.map(n=>{let o=Number(n);return o%1===0?`${o}.0`:`${o}`}).join(", ");if(t==="vec2")return`vec2(${r})`;if(t==="vec3")return`vec3(${r})`;if(t==="vec4")return`vec4(${r})`;if(t==="color")return`vec3(${r})`}return"0.0"},be=(e,t)=>{if(!e.children||e.children.length<2)return"0.0";let r=w(e.children[0],t),n=w(e.children[1],t);return e.operator==="add"?`(${r} + ${n})`:e.operator==="sub"?`(${r} - ${n})`:e.operator==="mul"?`(${r} * ${n})`:e.operator==="div"?`(${r} / ${n})`:e.operator==="mod"?`mod(${r}, ${n})`:e.operator==="equal"?`(${r} == ${n})`:e.operator==="notEqual"?`(${r} != ${n})`:e.operator==="lessThan"?`(${r} < ${n})`:e.operator==="lessThanEqual"?`(${r} <= ${n})`:e.operator==="greaterThan"?`(${r} > ${n})`:e.operator==="greaterThanEqual"?`(${r} >= ${n})`:e.operator==="and"?`(${r} && ${n})`:e.operator==="or"?`(${r} || ${n})`:`(${r} + ${n})`},xe=(e,t)=>{if(!e.children||e.children.length<1)return"0.0";let r=e.mathFunction,n=e.children.map(p=>w(p,t)),[o,a,u]=n;return n.length===1?`${r}(${o})`:n.length===2?`${r}(${o}, ${a})`:n.length===3?`${r}(${o}, ${a}, ${u})`:o||"0.0"},ye=e=>{if(i.num(e))return"float";if(i.bol(e))return"bool";if(i.arr(e)){let t=e.length;if(t===2)return"vec2";if(t===3)return"vec3";if(t===4)return"vec4"}return"float"},G=(e,t)=>{let r=t?.precision||"mediump",o=(t?.version||"300 es")==="300 es",a=ge(e),u="";return o&&(u+=`#version 300 es
|
|
2
|
-
`),u+=`precision ${r} float;
|
|
3
|
-
|
|
4
|
-
`,t?.uniforms&&(Object.entries(t.uniforms).forEach(([p,y])=>{let E=ye(y);u+=`uniform ${E} ${p};
|
|
5
|
-
`}),u+=`
|
|
6
|
-
`),o&&(u+=`out vec4 fragColor;
|
|
7
|
-
|
|
8
|
-
`),u+=`void main() {
|
|
9
|
-
`,u+=o?` fragColor = ${a};
|
|
10
|
-
`:` gl_FragColor = ${a};
|
|
11
|
-
`,u+=`}
|
|
12
|
-
`,u};var Te=`
|
|
13
|
-
#version 300 es
|
|
14
|
-
void main() {
|
|
15
|
-
float x = float(gl_VertexID % 2) * 4.0 - 1.0;
|
|
16
|
-
float y = float(gl_VertexID / 2) * 4.0 - 1.0;
|
|
17
|
-
gl_Position = vec4(x, y, 0.0, 1.0);
|
|
18
|
-
}
|
|
19
|
-
`,ve=`
|
|
20
|
-
#version 300 es
|
|
21
|
-
precision mediump float;
|
|
22
|
-
uniform vec2 iResolution;
|
|
23
|
-
out vec4 fragColor;
|
|
24
|
-
void main() {
|
|
25
|
-
fragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
|
|
26
|
-
}
|
|
27
|
-
`,W=(e,t,r)=>{let n=e.createShader(r);if(!n)throw new Error("Failed to create shader");if(e.shaderSource(n,t.trim()),e.compileShader(n),e.getShaderParameter(n,e.COMPILE_STATUS))return n;let o=e.getShaderInfoLog(n);throw e.deleteShader(n),new Error(`Could not compile shader: ${o}`)},D=(e,t=Te,r=ve)=>{i.obj(r)&&(r=G(r)),i.obj(t)&&(t=G(t));let n=e.createProgram();if(e.attachShader(n,W(e,t,e.VERTEX_SHADER)),e.attachShader(n,W(e,r,e.FRAGMENT_SHADER)),e.linkProgram(n),e.getProgramParameter(n,e.LINK_STATUS))return n;let o=e.getProgramInfoLog(n);throw e.deleteProgram(n),new Error(`Could not link pg: ${o}`)},q=(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},V=(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},j=(e,t,r)=>{r&&(e=Math.max(...r)+1);let n=t.length/e;return Math.floor(n)},k=(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)},Y=(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 H=async e=>{let t=e.el.getContext("webgl2"),r=D(t,e.vs,e.fs),n={context:t,program:r};t.useProgram(r);let o=0,a=R(h=>t.getUniformLocation(r,h)),u=R(h=>t.getAttribLocation(r,h)),p=R(()=>o++);return{webgl:n,render:()=>{t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,...e.size),t.drawArrays(t.TRIANGLES,0,3)},clean:()=>t.deleteProgram(r),_attribute:(h="",b,x)=>{let T=u(h,!0),l=q(t,b),f=V(t,x),c=j(e.count,b,x);k(t,c,T,l,f)},_uniform:(h,b)=>{let x=a(h);if(i.num(b))return t.uniform1f(x,b);let T=b.length;if(T<=4)return t[`uniform${T}fv`](x,b);T=Math.sqrt(T)<<0,t[`uniformMatrix${T}fv`](x,!1,b)},_texture:(h,b)=>{let x=new Image;Object.assign(x,{src:b,crossOrigin:"anonymous"}),x.decode().then(()=>{let T=a(h),l=p(h);Y(t,x,T,l)})}}};import{nested as U}from"reev";var Ee=(e,t)=>{let r={target:"webgpu",nodes:new Map,variables:new Map,functions:new Map,...t};return L(e,r)},L=(e,t)=>e?e.value!==void 0?$e(e.value,e.type):e.property&&e.parent?`${L(e.parent,t)}.${e.property}`:e.operator&&e.children&&e.children.length>=2?we(e,t):e.mathFunction&&e.children&&e.children.length>=1?Le(e,t):"0.0":"0.0",$e=(e,t)=>{if(t==="float"){let r=Number(e);return r%1===0?`${r}.0`:`${r}`}if(t==="int")return`${Math.floor(Number(e))}`;if(t==="bool")return e?"true":"false";if(i.arr(e)){let r=e.map(n=>{let o=Number(n);return o%1===0?`${o}.0`:`${o}`}).join(", ");if(t==="vec2")return`vec2<f32>(${r})`;if(t==="vec3")return`vec3<f32>(${r})`;if(t==="vec4")return`vec4<f32>(${r})`;if(t==="color")return`vec3<f32>(${r})`}return"0.0"},we=(e,t)=>{if(!e.children||e.children.length<2)return"0.0";let r=L(e.children[0],t),n=L(e.children[1],t);return e.operator==="add"?`(${r} + ${n})`:e.operator==="sub"?`(${r} - ${n})`:e.operator==="mul"?`(${r} * ${n})`:e.operator==="div"?`(${r} / ${n})`:e.operator==="mod"?`(${r} % ${n})`:e.operator==="equal"?`(${r} == ${n})`:e.operator==="notEqual"?`(${r} != ${n})`:e.operator==="lessThan"?`(${r} < ${n})`:e.operator==="lessThanEqual"?`(${r} <= ${n})`:e.operator==="greaterThan"?`(${r} > ${n})`:e.operator==="greaterThanEqual"?`(${r} >= ${n})`:e.operator==="and"?`(${r} && ${n})`:e.operator==="or"?`(${r} || ${n})`:`(${r} + ${n})`},Le=(e,t)=>{if(!e.children||e.children.length<1)return"0.0";let r=e.mathFunction,n=e.children.map(p=>L(p,t)),[o,a,u]=n;return n.length===1?`${r}(${o})`:n.length===2?`${r}(${o}, ${a})`:n.length===3?`${r}(${o}, ${a}, ${u})`:o||"0.0"},_=(e,t)=>{let r="";t?.uniforms&&(Object.entries(t.uniforms).forEach(([o,a])=>{let u=Ne(a);r+=`@group(0) @binding(0) var<uniform> ${o}: ${u};
|
|
28
|
-
`}),r+=`
|
|
29
|
-
`),r+=`@fragment
|
|
30
|
-
`,r+=`fn main() -> @location(0) vec4<f32> {
|
|
31
|
-
`;let n=Ee(e);return r+=` return ${n};
|
|
32
|
-
`,r+=`}
|
|
33
|
-
`,r},Ne=e=>{if(i.num(e))return"f32";if(i.bol(e))return"bool";if(i.arr(e)){let t=e.length;if(t===2)return"vec2<f32>";if(t===3)return"vec3<f32>";if(t===4)return"vec4<f32>"}return"f32"};var Se=`
|
|
34
|
-
@vertex
|
|
35
|
-
fn main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4f {
|
|
36
|
-
let x = f32(vertex_index % 2u) * 4.0 - 1.0;
|
|
37
|
-
let y = f32(vertex_index / 2u) * 4.0 - 1.0;
|
|
38
|
-
return vec4f(x, y, 0.0, 1.0);
|
|
39
|
-
}
|
|
40
|
-
`,Ce=`
|
|
41
|
-
@group(0) @binding(0) var<uniform> iResolution: vec2f;
|
|
42
|
-
|
|
43
|
-
@fragment
|
|
44
|
-
fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
|
45
|
-
return vec4f(position.xy / iResolution, 0.0, 1.0);
|
|
46
|
-
}
|
|
47
|
-
`,K=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}},Z=(e,t,r,n,o=Se,a=Ce)=>{i.obj(a)&&(a=_(a)),i.obj(o)&&(o=_(o));let u=e.createPipelineLayout({bindGroupLayouts:n});return e.createRenderPipeline({vertex:{module:e.createShaderModule({code:o.trim()}),entryPoint:"main",buffers:r},fragment:{module:e.createShaderModule({code:a.trim()}),entryPoint:"main",targets:[{format:t}]},layout:u,primitive:{topology:"triangle-list"}})},Q=(e,t)=>{let r=[],n=[];t.forEach((u,p)=>{if(!u)return;let y="buffer"in u,E=u instanceof GPUTextureView,d=u instanceof GPUSampler;if(y)r.push({binding:p,visibility:3,buffer:{type:"uniform"}});else if(E)r.push({binding:p,visibility:2,texture:{}});else if(d)r.push({binding:p,visibility:2,sampler:{}});else return;n.push({binding:p,resource:u})});let o=e.createBindGroupLayout({entries:r}),a=e.createBindGroup({layout:o,entries:n});return{layout:o,bindGroup:a}},J=e=>({colorAttachments:[{view:e.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),Ge=e=>Math.ceil(e/256)*256,ee=(e,t)=>{let r=new Float32Array(t),n=e.createBuffer({size:r.byteLength,usage:40});return{array:r,buffer:n}},te=(e,t)=>{let r=new Float32Array(t),n=Ge(r.byteLength),o=e.createBuffer({size:n,usage:72});return{array:r,buffer:o}},re=(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}},Re=(e,t)=>e/t,_e=e=>e===2?"float32x2":e===3?"float32x3":e===4?"float32x4":"float32",ne=(e,t,r=6)=>{let n=Re(t,r);return{arrayStride:n*4,attributes:[{shaderLocation:e,offset:0,format:_e(n)}]}};var oe=async e=>{let t=e.el.getContext("webgpu"),{device:r,format:n}=await K(t),o={device:r,context:t,resources:[[],[]],loadingImg:0,needsUpdate:!0},a=[],u=[],p=[],y=U((l,f)=>{let{array:c,buffer:m}=ee(r,f);return u.push(m),p.push(ne(p.length,c.length,e.count)),o.needsUpdate=!0,{array:c,buffer:m}}),E=U((l,f)=>{let{array:c,buffer:m}=te(r,f);return o.resources[0].push({buffer:m}),o.needsUpdate=!0,{array:c,buffer:m}}),d=U((l,{width:f,height:c})=>{let{texture:m,sampler:C}=re(r,f,c);return o.resources[1].push(C,m.createView()),o.needsUpdate=!0,{texture:m,width:f,height:c}}),g=()=>{let l=[];a.length=0,o.resources.forEach(f=>{if(!f.length)return;let{layout:c,bindGroup:m}=Q(r,f);l.push(c),a.push(m)}),o.pipeline=Z(r,n,p,l,e.vs,e.fs)};return{webgpu:o,render:()=>{if(o.loadingImg)return;o.needsUpdate&&g(),o.needsUpdate=!1;let l=r.createCommandEncoder(),f=l.beginRenderPass(J(t));f.setPipeline(o.pipeline),a.forEach((c,m)=>f.setBindGroup(m,c)),u.forEach((c,m)=>f.setVertexBuffer(m,c)),f.draw(e.count,1,0,0),f.end(),r.queue.submit([l.finish()])},clean:()=>{},_attribute:(l="",f)=>{let{array:c,buffer:m}=y(l,f);r.queue.writeBuffer(m,0,c)},_uniform:(l,f)=>{i.num(f)&&(f=[f]);let{array:c,buffer:m}=E(l,f);c.set(f),r.queue.writeBuffer(m,0,c)},_texture:(l,f)=>{o.loadingImg++;let c=Object.assign(new Image,{src:f,crossOrigin:"anonymous"});c.decode().then(()=>{let{texture:m,width:C,height:le}=d(l,c);r.queue.copyExternalImageToTexture({source:c},{texture:m},{width:C,height:le}),o.loadingImg--})}}};var $t=["float","int","uint","bool","color","vec2","vec3","vec4","mat2","mat3","mat4","ivec2","ivec3","ivec4","uvec2","uvec3","uvec4","bvec2","bvec3","bvec4"],ie=["x","y","z","w","r","g","b","a","s","t","p","q"],ae=["add","sub","mul","div","mod","equal","notEqual","lessThan","lessThanEqual","greaterThan","greaterThanEqual","and","or","not","assign","xor","bitAnd","bitNot","bitOr","bitXor","shiftLeft","shiftRight"],se=["abs","acos","asin","atan","atan2","ceil","clamp","cos","cross","degrees","distance","dot","exp","exp2","faceforward","floor","fract","length","all","any","bitcast","cbrt","dFdx","dFdy","difference","equals","fwidth","inverseSqrt","lengthSq","log","log2","max","min","mix","negate","normalize","oneMinus","pow","pow2","pow3","pow4","radians","reciprocal","reflect","refract","round","saturate","sign","sin","smoothstep","sqrt","step","tan","transformDirection","trunc"],ue=[!0,!1],fe=[0,1,2,3,4,5],ce=[0,1,.5,2];var X=new Map,A=new Map,F=new Map,Ue=()=>{ue.forEach(e=>{X.set(e,s("bool",e))}),fe.forEach(e=>{A.set(e,s("int",e))}),ce.forEach(e=>{F.set(e,s("float",e))})},P=e=>(X.has(e)||Ue(),X.get(e)||s("bool",e)),M=e=>A.has(e)?A.get(e):s("int",e),B=e=>F.has(e)?F.get(e):s("float",e),St=e=>{let t=new Map,r=new Map;return e.forEach(n=>{let o=Xe(n);r.has(o)?(t.has(o)||t.set(o,[r.get(o)]),t.get(o).push(n)):r.set(o,n)}),t},Xe=e=>[e.type,`${e.value}`,e.property||""].join("|");var Ut=e=>i.bol(e)?P(e):i.num(e)?i.int(e)?M(e):B(e):i.arr(e)?pe(e):i.obj(e)?Ae(e):s("float",0),pe=e=>{let t=e.length;return t===2?s("vec2",e):t===3?s("vec3",e):t===4?s("vec4",e):t===9?s("mat3",e):t===16?s("mat4",e):s("float",e[0])},Ae=e=>{if("r"in e&&"g"in e&&"b"in e){let t=[e.r,e.g,e.b];return"a"in e&&t.push(e.a),s("color",t)}if("x"in e&&"y"in e){let t=[e.x,e.y];return"z"in e&&t.push(e.z),"w"in e&&t.push(e.w),pe(t)}return s("float",0)},I=e=>i.num(e)?B(e):s("float",Number(e)),Xt=e=>i.num(e)&&Number.isInteger(e)?M(e):s("int",Math.floor(Number(e))),At=e=>P(!!e),Ft=(e,t)=>i.und(e)?s("vec2",[0,0]):i.und(t)?i.arr(e)?s("vec2",e.slice(0,2)):i.obj(e)&&"x"in e&&"y"in e?s("vec2",[e.x,e.y]):s("vec2",[Number(e),Number(e)]):s("vec2",[Number(e),Number(t)]),Fe=(e,t,r)=>i.und(e)?s("vec3",[0,0,0]):i.und(t)?i.arr(e)?s("vec3",e.slice(0,3)):i.obj(e)&&"x"in e&&"y"in e&&"z"in e?s("vec3",[e.x,e.y,e.z]):s("vec3",[Number(e),Number(e),Number(e)]):r===void 0?s("vec3",[Number(e),Number(t),0]):s("vec3",[Number(e),Number(t),Number(r)]),Pt=(e,t,r,n)=>i.und(e)?s("vec4",[0,0,0,1]):i.und(t)?i.arr(e)?s("vec4",e.slice(0,4)):i.obj(e)&&"x"in e&&"y"in e&&"z"in e&&"w"in e?s("vec4",[e.x,e.y,e.z,e.w]):s("vec4",[Number(e),Number(e),Number(e),1]):s("vec4",[Number(e),Number(t),Number(r),Number(n)]),Mt=(e,t,r)=>{if(e===void 0)return s("color",[1,1,1]);if(i.str(e)&&e.startsWith("#")){let n=e.slice(1),o=parseInt(n,16);return s("color",[(o>>16&255)/255,(o>>8&255)/255,(o&255)/255])}return i.num(e)&&t===void 0&&r===void 0?s("color",[(e>>16&255)/255,(e>>8&255)/255,(e&255)/255]):Fe(e,t,r)};var Pe=0,Me=()=>`node_${++Pe}`,N=(e,t,r)=>({id:Me(),type:e,value:t,children:[],...r}),Be=(e="")=>ie.includes(e),Ie=(e="")=>ae.includes(e),ze=(e="")=>se.includes(e),S=(e,t)=>{let r=(o,a)=>{if(!(!i.str(a)||a==="then"))return a==="id"?e.id:a==="type"?e.type:a==="value"?e.value:a==="property"?e.property:Be(a)?S(N(Oe(a),void 0,{parent:e,property:a}),t):Ie(a)?(...u)=>S(N(e.type,void 0,{operator:a,children:[e,...u]}),t):ze(a)?(...u)=>S(N(We(a,e.type),void 0,{mathFunction:a,children:[e,...u]}),t):t?.({path:[a],args:[]})},n=(o,a,u)=>t?.({path:[],args:u});return new Proxy(()=>{},{get:r,apply:n})},Oe=e=>e.length===1?"float":e.length===2?"vec2":e.length===3?"vec3":e.length===4?"vec4":"float",We=(e,t)=>e==="length"?"float":t,s=(e,t,r)=>{let n=N(e,t,r);return S(n)};var De=e=>{if(i.num(e))return"float";if(i.bol(e))return"bool";if(i.arr(e)){let t=e.length;if(t===2)return"vec2";if(t===3)return"vec3";if(t===4)return"vec4";if(t===9)return"mat3";if(t===16)return"mat4"}return i.obj(e)&&"r"in e&&"g"in e&&"b"in e?"color":"float"},v=e=>{let t=De(e),r=e,n=null,o=null,a=s(t,r),u=g=>{r=g,a.value=g},p=g=>(n=g,d),y=g=>(o=g,d),E=g=>{if(n){let $=n(g);$!==void 0&&u($)}if(o){let $=o(g);$!==void 0&&u($)}},d=Object.create(a);return d.set=u,d.onObjectUpdate=p,d.onRenderUpdate=y,d._updateFromContext=E,d.isUniform=!0,d},me=v(0),qe=v(0),Ve=v(0),qt=v([1920,1080]),Vt=v([0,0]),jt=e=>{if(e.time!==void 0){let t=me.value||0;me.set(e.time),qe.set(t),Ve.set(e.time-t)}};var Qt=e=>{let t=(...r)=>{let n=r.map(a=>i.obj(a)&&"type"in a&&a.type?a:I(a));return e(n)||I(0)};return t.call=r=>e(r),t},Jt=(e,t)=>{t();let r={ElseIf(n,o){return o(),r},Else(n){n()}};return r},er=s("vec4",void 0),tr=s("vec4",void 0),rr=v(0),nr=v([1920,1080]),or=v([0,0]),ir=e=>e.abs(),ar=e=>e.sin(),sr=e=>e.cos(),ur=e=>e.tan(),fr=e=>e.sqrt(),cr=e=>e.floor(),pr=e=>e.ceil(),mr=e=>e.fract(),lr=e=>e.normalize(),dr=e=>e.length();var Sr=e=>i.obj(e)?"isGL"in e:!1,He=()=>typeof window>"u",Ke=()=>He()?!1:"gpu"in navigator,O=performance.now(),Ze=e=>{let t=je({isNative:!1,isWebGL:!0,isLoop:!0,isGL:!0,size:[0,0],mouse:[0,0],count:6,webgl:{},webgpu:{}});return t.queue=Ye(),t.frame=ke(),t.attribute=z((r,n,o)=>t.queue(()=>t._attribute?.(r,n,o))),t.texture=z((r,n)=>t.queue(()=>t._texture?.(r,n))),t.uniform=z((r,n,o)=>t.queue(()=>t._uniform?.(r,n,o))),t.uniform({iResolution:t.size,iMouse:[0,0],iTime:O}),t("mount",async()=>{t.vs=t.vs||t.vert||t.vertex,t.fs=t.fs||t.frag||t.fragment,Ke()||(t.isWebGL=!0),t.isWebGL?t(await H(t)):t(await oe(t)),t.resize(),t.frame(()=>(t.loop(),t.queue.flush(),t.render(),t.isLoop)),!t.isNative&&(window.addEventListener("resize",t.resize),t.el.addEventListener("mousemove",t.mousemove))}),t("clean",()=>{t.frame.stop(),t.frame.clean(t.render),!t.isNative&&(window.removeEventListener("resize",t.resize),t.el.removeEventListener("mousemove",t.mousemove))}),t("resize",()=>{let r=t.width||window.innerWidth,n=t.height||window.innerHeight;t.size[0]=t.el.width=r,t.size[1]=t.el.height=n,t.uniform("iResolution",t.size)}),t("mousemove",(r,n=r.clientX,o=r.clientY)=>{let[a,u]=t.size,{top:p,left:y}=t.el.getBoundingClientRect();t.mouse[0]=(n-p-a/2)/(a/2),t.mouse[1]=-(o-y-u/2)/(u/2),t.uniform("iMouse",t.mouse)}),t("loop",()=>{O=performance.now()/1e3,t.uniform("iTime",O)}),t(e)},Cr=Ze;export{ue as CACHE_BOOLS,ce as CACHE_FLOATS,fe as CACHE_INTS,se as FUNCTIONS,Qt as Fn,Jt as If,ae as OPERATORS,ie as SWIZZLES,$t as TYPES,ir as abs,Ge as alignTo256,At as bool,pr as ceil,Mt as color,Ut as convertToNode,sr as cos,k as createAttrib,Q as createBindGroup,ne as createBufferLayout,J as createDescriptor,K as createDevive,Ze as createGL,V as createIbo,N as createNode,Z as createPipeline,D as createProgram,Y as createTexture,re as createTextureSampler,te as createUniformBuffer,q as createVbo,ee as createVertexBuffer,Cr as default,ve as defaultFragmentGLSL,Te as defaultVertexGLSL,rt as dig,de as each,et as ext,tt as fig,St as findDuplicateNodes,I as float,cr as floor,Qe as flush,mr as fract,er as fragCoord,P as getCachedBool,B as getCachedFloat,M as getCachedInt,j as getStride,G as glsl,Ve as iDeltaTime,or as iMouse,qe as iPrevTime,nr as iResolution,rr as iTime,Xt as int,i as is,Sr as isGL,He as isServer,Ke as isWebGPUSupported,dr as length,s as node,ge as nodeToGLSL,Ee as nodeToWGSL,lr as normalize,tr as position,Je as replace,nt as sig,ar as sin,fr as sqrt,ur as tan,v as uniform,jt as updateUniforms,Ft as vec2,Fe as vec3,Pt as vec4,H as webgl,oe as webgpu,_ as wgsl};
|
|
48
|
-
//# sourceMappingURL=index.mjs.map
|