glre 0.36.0 → 0.38.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 +35 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +219 -1652
- package/dist/index.js +35 -30
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +35 -30
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.ts +7 -6
- package/dist/native.js +35 -30
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +35 -30
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +35 -30
- package/dist/react.js.map +1 -1
- package/dist/solid.cjs +35 -30
- package/dist/solid.cjs.map +1 -1
- package/dist/solid.d.ts +1 -1
- package/dist/solid.js +35 -30
- package/dist/solid.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/node/core.ts +25 -4
- package/src/node/index.ts +61 -64
- package/src/node/node.ts +9 -5
- package/src/node/scope.ts +30 -17
- package/src/node/types.ts +168 -119
- package/src/node/utils/const.ts +113 -120
- package/src/node/utils/index.ts +21 -7
- package/src/node/utils/infer.ts +13 -18
- package/src/node/utils/parse.ts +57 -16
- package/src/node/utils/utils.ts +16 -8
- package/src/types.ts +6 -4
- package/src/utils/program.ts +62 -18
- package/src/webgl.ts +79 -67
- package/src/webgpu.ts +50 -42
package/src/node/types.ts
CHANGED
|
@@ -6,6 +6,9 @@ export type Conversions = (typeof CONVERSIONS)[number]
|
|
|
6
6
|
export type Functions = (typeof FUNCTIONS)[number]
|
|
7
7
|
export type Operators = (typeof OPERATOR_KEYS)[number]
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* scope
|
|
11
|
+
*/
|
|
9
12
|
export interface FnLayout {
|
|
10
13
|
name: string
|
|
11
14
|
type: Constants | 'auto'
|
|
@@ -15,12 +18,18 @@ export interface FnLayout {
|
|
|
15
18
|
}>
|
|
16
19
|
}
|
|
17
20
|
|
|
21
|
+
export interface FnType<T extends NodeProxy | StructNode | void, Args extends any[]> {
|
|
22
|
+
(...args: Args): T extends void ? Void : T
|
|
23
|
+
setLayout(layout: FnLayout): FnType<T, Args>
|
|
24
|
+
}
|
|
25
|
+
|
|
18
26
|
/**
|
|
19
|
-
*
|
|
27
|
+
* node
|
|
20
28
|
*/
|
|
21
29
|
export type NodeTypes =
|
|
22
30
|
// headers
|
|
23
31
|
| 'attribute'
|
|
32
|
+
| 'storage'
|
|
24
33
|
| 'uniform'
|
|
25
34
|
| 'constant'
|
|
26
35
|
// variables
|
|
@@ -35,6 +44,8 @@ export type NodeTypes =
|
|
|
35
44
|
| 'struct'
|
|
36
45
|
| 'member'
|
|
37
46
|
| 'element'
|
|
47
|
+
| 'gather'
|
|
48
|
+
| 'scatter'
|
|
38
49
|
// scopes
|
|
39
50
|
| 'scope'
|
|
40
51
|
| 'assign'
|
|
@@ -45,7 +56,7 @@ export type NodeTypes =
|
|
|
45
56
|
| 'declare'
|
|
46
57
|
| 'return'
|
|
47
58
|
|
|
48
|
-
export interface NodeProps
|
|
59
|
+
export interface NodeProps {
|
|
49
60
|
id?: string
|
|
50
61
|
args?: any[]
|
|
51
62
|
type?: string
|
|
@@ -53,15 +64,15 @@ export interface NodeProps<T extends Record<string, NodeProxy> = {}> {
|
|
|
53
64
|
inferFrom?: any[]
|
|
54
65
|
layout?: FnLayout
|
|
55
66
|
// for struct
|
|
56
|
-
fields?:
|
|
57
|
-
initialValues?:
|
|
67
|
+
fields?: StructFields
|
|
68
|
+
initialValues?: StructFields
|
|
58
69
|
}
|
|
59
70
|
|
|
60
71
|
export interface NodeContext {
|
|
61
72
|
gl?: Partial<GL>
|
|
62
|
-
|
|
73
|
+
label?: 'vert' | 'frag' | 'compute'
|
|
63
74
|
isWebGL?: boolean
|
|
64
|
-
|
|
75
|
+
units?: any // @TODO FIX
|
|
65
76
|
infers?: WeakMap<NodeProxy, Constants>
|
|
66
77
|
onMount?: (name: string) => void
|
|
67
78
|
code?: {
|
|
@@ -70,7 +81,9 @@ export interface NodeContext {
|
|
|
70
81
|
vertInputs: Map<string, string>
|
|
71
82
|
vertOutputs: Map<string, string>
|
|
72
83
|
vertVaryings: Map<string, string>
|
|
84
|
+
computeInputs: Map<string, string>
|
|
73
85
|
dependencies: Map<string, Set<string>>
|
|
86
|
+
structFields: Map<string, StructFields>
|
|
74
87
|
}
|
|
75
88
|
}
|
|
76
89
|
|
|
@@ -140,6 +153,7 @@ type NodeProxyMethods =
|
|
|
140
153
|
| Conversions
|
|
141
154
|
| Swizzles
|
|
142
155
|
// system property
|
|
156
|
+
| '__nodeType'
|
|
143
157
|
| 'type'
|
|
144
158
|
| 'props'
|
|
145
159
|
| 'isProxy'
|
|
@@ -148,8 +162,86 @@ type NodeProxyMethods =
|
|
|
148
162
|
| 'toString'
|
|
149
163
|
| 'element'
|
|
150
164
|
|
|
165
|
+
type ReadNodeProxy = {
|
|
166
|
+
[K in string as K extends NodeProxyMethods ? never : K]: any
|
|
167
|
+
} & {
|
|
168
|
+
[K in Swizzles]: NodeProxy<InferSwizzleType<K>>
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Internal NodeProxy implementation (renamed from original)
|
|
172
|
+
type NodeProxyImpl<T extends Constants> = BaseNodeProxy<T> & ReadNodeProxy
|
|
173
|
+
|
|
174
|
+
export type Void = NodeProxyImpl<'void'>
|
|
175
|
+
export type Bool = NodeProxyImpl<'bool'>
|
|
176
|
+
export type UInt = NodeProxyImpl<'uint'>
|
|
177
|
+
export type Int = NodeProxyImpl<'int'>
|
|
178
|
+
export type Float = NodeProxyImpl<'float'>
|
|
179
|
+
export type BVec2 = NodeProxyImpl<'bvec2'>
|
|
180
|
+
export type IVec2 = NodeProxyImpl<'ivec2'>
|
|
181
|
+
export type UVec2 = NodeProxyImpl<'uvec2'>
|
|
182
|
+
export type Vec2 = NodeProxyImpl<'vec2'>
|
|
183
|
+
export type BVec3 = NodeProxyImpl<'bvec3'>
|
|
184
|
+
export type IVec3 = NodeProxyImpl<'ivec3'>
|
|
185
|
+
export type UVec3 = NodeProxyImpl<'uvec3'>
|
|
186
|
+
export type Vec3 = NodeProxyImpl<'vec3'>
|
|
187
|
+
export type BVec4 = NodeProxyImpl<'bvec4'>
|
|
188
|
+
export type IVec4 = NodeProxyImpl<'ivec4'>
|
|
189
|
+
export type UVec4 = NodeProxyImpl<'uvec4'>
|
|
190
|
+
export type Vec4 = NodeProxyImpl<'vec4'>
|
|
191
|
+
export type Color = NodeProxyImpl<'color'>
|
|
192
|
+
export type Mat2 = NodeProxyImpl<'mat2'>
|
|
193
|
+
export type Mat3 = NodeProxyImpl<'mat3'>
|
|
194
|
+
export type Mat4 = NodeProxyImpl<'mat4'>
|
|
195
|
+
export type Texture = NodeProxyImpl<'texture'>
|
|
196
|
+
export type Sampler2D = NodeProxyImpl<'sampler2D'>
|
|
197
|
+
export type Struct = NodeProxyImpl<'struct'>
|
|
198
|
+
export type StructFields = Record<string, NodeProxy>
|
|
199
|
+
export type StructNode<T extends StructFields = any> = Omit<Struct, keyof T> & {
|
|
200
|
+
[K in keyof T]: T[K] extends NodeProxy<infer U> ? NodeProxy<U> : never
|
|
201
|
+
} & {
|
|
202
|
+
toVar(id?: string): StructNode<T>
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface StructFactory<T extends StructFields> {
|
|
206
|
+
(initialValues?: StructFields, instanceId?: string): StructNode<T>
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface ConstantsToType {
|
|
210
|
+
void: Void
|
|
211
|
+
bool: Bool
|
|
212
|
+
uint: UInt
|
|
213
|
+
int: Int
|
|
214
|
+
float: Float
|
|
215
|
+
bvec2: BVec2
|
|
216
|
+
ivec2: IVec2
|
|
217
|
+
uvec2: UVec2
|
|
218
|
+
vec2: Vec2
|
|
219
|
+
bvec3: BVec3
|
|
220
|
+
ivec3: IVec3
|
|
221
|
+
uvec3: UVec3
|
|
222
|
+
vec3: Vec3
|
|
223
|
+
bvec4: BVec4
|
|
224
|
+
ivec4: IVec4
|
|
225
|
+
uvec4: UVec4
|
|
226
|
+
vec4: Vec4
|
|
227
|
+
color: Color
|
|
228
|
+
mat2: Mat2
|
|
229
|
+
mat3: Mat3
|
|
230
|
+
mat4: Mat4
|
|
231
|
+
texture: Texture
|
|
232
|
+
sampler2D: Sampler2D
|
|
233
|
+
struct: Struct
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export type NodeProxy<T extends Constants = Constants> = T extends keyof ConstantsToType
|
|
237
|
+
? ConstantsToType[T]
|
|
238
|
+
: BaseNodeProxy<T>
|
|
239
|
+
|
|
240
|
+
export type X<T extends Constants = Constants> = number | string | boolean | undefined | NodeProxy<T>
|
|
241
|
+
|
|
151
242
|
export interface BaseNodeProxy<T extends Constants> {
|
|
152
243
|
// System properties
|
|
244
|
+
readonly __nodeType?: T
|
|
153
245
|
assign(x: any): NodeProxy<T>
|
|
154
246
|
toVar(name?: string): NodeProxy<T>
|
|
155
247
|
toString(c?: NodeContext): string
|
|
@@ -158,6 +250,14 @@ export interface BaseNodeProxy<T extends Constants> {
|
|
|
158
250
|
isProxy: true
|
|
159
251
|
listeners: Set<(value: any) => void>
|
|
160
252
|
|
|
253
|
+
// Element access for array/matrix types
|
|
254
|
+
element<Index extends X>(index: Index): NodeProxy<InferArrayElement<T>>
|
|
255
|
+
|
|
256
|
+
// Enhanced member access with type preservation
|
|
257
|
+
member<K extends string>(
|
|
258
|
+
key: K
|
|
259
|
+
): K extends keyof T ? (T[K] extends NodeProxy<infer U> ? NodeProxy<U> : never) : never
|
|
260
|
+
|
|
161
261
|
// Operators methods
|
|
162
262
|
add<U extends Constants>(x: X<U>): NodeProxy<InferOperator<T, U>>
|
|
163
263
|
sub<U extends Constants>(x: X<U>): NodeProxy<InferOperator<T, U>>
|
|
@@ -204,134 +304,83 @@ export interface BaseNodeProxy<T extends Constants> {
|
|
|
204
304
|
toMat3(): Mat3
|
|
205
305
|
toMat4(): Mat4
|
|
206
306
|
|
|
207
|
-
|
|
307
|
+
/**
|
|
308
|
+
* 3.1. unified logic with:
|
|
309
|
+
* 1.1. index.ts functions and
|
|
310
|
+
* 2.1. const.ts FUNCTION_RETURN_TYPES
|
|
311
|
+
*/
|
|
312
|
+
// 0. Always return bool
|
|
313
|
+
all(): Bool
|
|
314
|
+
any(): Bool
|
|
315
|
+
// 2. Always return float
|
|
316
|
+
determinant(): Float
|
|
317
|
+
distance<U extends Constants>(y: X<U>): Float
|
|
318
|
+
dot<U extends Constants>(y: X<U>): Float
|
|
319
|
+
length(): Float
|
|
320
|
+
lengthSq(): Float
|
|
321
|
+
luminance(): Float
|
|
322
|
+
// 3. Always return vec3
|
|
323
|
+
cross<U extends Constants>(y: X<U>): Vec3
|
|
324
|
+
// 4. Always return vec4
|
|
325
|
+
cubeTexture(...args: X[]): Vec4
|
|
326
|
+
texture(...args: X[]): Vec4
|
|
327
|
+
texelFetch(...args: X[]): Vec4
|
|
328
|
+
textureLod(...args: X[]): Vec4
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* 3.1. unified with:
|
|
332
|
+
* 1.1. index.ts functions and
|
|
333
|
+
* 2.1. const.ts FUNCTIONS
|
|
334
|
+
*/
|
|
335
|
+
// 0. Component-wise functions
|
|
208
336
|
abs(): NodeProxy<T>
|
|
209
|
-
sign(): NodeProxy<T>
|
|
210
|
-
floor(): NodeProxy<T>
|
|
211
|
-
ceil(): NodeProxy<T>
|
|
212
|
-
round(): NodeProxy<T>
|
|
213
|
-
fract(): NodeProxy<T>
|
|
214
|
-
trunc(): NodeProxy<T>
|
|
215
|
-
sin(): NodeProxy<T>
|
|
216
|
-
cos(): NodeProxy<T>
|
|
217
|
-
tan(): NodeProxy<T>
|
|
218
|
-
asin(): NodeProxy<T>
|
|
219
337
|
acos(): NodeProxy<T>
|
|
338
|
+
acosh(): NodeProxy<T>
|
|
339
|
+
asin(): NodeProxy<T>
|
|
340
|
+
asinh(): NodeProxy<T>
|
|
220
341
|
atan(): NodeProxy<T>
|
|
342
|
+
atanh(): NodeProxy<T>
|
|
343
|
+
ceil(): NodeProxy<T>
|
|
344
|
+
cos(): NodeProxy<T>
|
|
345
|
+
cosh(): NodeProxy<T>
|
|
346
|
+
degrees(): NodeProxy<T>
|
|
347
|
+
dFdx(): NodeProxy<T>
|
|
348
|
+
dFdy(): NodeProxy<T>
|
|
221
349
|
exp(): NodeProxy<T>
|
|
222
350
|
exp2(): NodeProxy<T>
|
|
351
|
+
floor(): NodeProxy<T>
|
|
352
|
+
fract(): NodeProxy<T>
|
|
353
|
+
fwidth(): NodeProxy<T>
|
|
354
|
+
inverseSqrt(): NodeProxy<T>
|
|
223
355
|
log(): NodeProxy<T>
|
|
224
356
|
log2(): NodeProxy<T>
|
|
225
|
-
|
|
226
|
-
inverseSqrt(): NodeProxy<T>
|
|
357
|
+
negate(): NodeProxy<T>
|
|
227
358
|
normalize(): NodeProxy<T>
|
|
228
359
|
oneMinus(): NodeProxy<T>
|
|
229
|
-
|
|
230
|
-
negate(): NodeProxy<T>
|
|
360
|
+
radians(): NodeProxy<T>
|
|
231
361
|
reciprocal(): NodeProxy<T>
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
// Bool return functions
|
|
243
|
-
all(): Bool
|
|
244
|
-
any(): Bool
|
|
245
|
-
|
|
246
|
-
// Specific return type functions
|
|
247
|
-
cross<U extends Constants>(y: X<U>): Vec3
|
|
362
|
+
round(): NodeProxy<T>
|
|
363
|
+
saturate(): NodeProxy<T>
|
|
364
|
+
sign(): NodeProxy<T>
|
|
365
|
+
sin(): NodeProxy<T>
|
|
366
|
+
sinh(): NodeProxy<T>
|
|
367
|
+
sqrt(): NodeProxy<T>
|
|
368
|
+
tan(): NodeProxy<T>
|
|
369
|
+
tanh(): NodeProxy<T>
|
|
370
|
+
trunc(): NodeProxy<T>
|
|
248
371
|
|
|
249
|
-
//
|
|
372
|
+
// 1. Functions where first argument determines return type
|
|
250
373
|
atan2<U extends Constants>(x: X<U>): NodeProxy<T>
|
|
374
|
+
clamp<U extends Constants, V>(mix: X<U>, max: V): NodeProxy<InferOperator<T, U>>
|
|
375
|
+
max<U extends Constants>(y: X<U>): NodeProxy<InferOperator<T, U>>
|
|
376
|
+
min<U extends Constants>(y: X<U>): NodeProxy<InferOperator<T, U>>
|
|
377
|
+
mix<U extends Constants, V>(y: X<U>, a: V): NodeProxy<InferOperator<T, U>>
|
|
251
378
|
pow<U extends Constants>(y: X<U>): NodeProxy<T>
|
|
252
|
-
distance<U extends Constants>(y: X<U>): Float
|
|
253
|
-
dot<U extends Constants>(y: X<U>): Float
|
|
254
379
|
reflect<U extends Constants>(N: X<U>): NodeProxy<T>
|
|
255
380
|
refract<U extends Constants>(N: X<U>, eta: any): NodeProxy<T>
|
|
256
381
|
|
|
257
|
-
//
|
|
258
|
-
min<U extends Constants>(y: X<U>): NodeProxy<InferOperator<T, U>>
|
|
259
|
-
max<U extends Constants>(y: X<U>): NodeProxy<InferOperator<T, U>>
|
|
260
|
-
mix<U extends Constants, V>(y: X<U>, a: V): NodeProxy<InferOperator<T, U>>
|
|
261
|
-
clamp<U extends Constants, V>(mix: X<U>, max: V): NodeProxy<InferOperator<T, U>>
|
|
262
|
-
step<U extends Constants>(edge: X<U>): NodeProxy<InferOperator<T, U>>
|
|
382
|
+
// 2. Functions where not first argument determines return type
|
|
263
383
|
smoothstep<U extends Constants, V>(edge0: X<U>, edge1: V): NodeProxy<InferOperator<T, U>>
|
|
264
|
-
|
|
265
|
-
//
|
|
266
|
-
pow2(): NodeProxy<T>
|
|
267
|
-
pow3(): NodeProxy<T>
|
|
268
|
-
pow4(): NodeProxy<T>
|
|
269
|
-
|
|
270
|
-
// Element access for array/matrix types
|
|
271
|
-
element<Index extends X>(index: Index): NodeProxy<InferArrayElement<T>>
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
type ReadNodeProxy = {
|
|
275
|
-
[K in string as K extends NodeProxyMethods ? never : K]: any
|
|
276
|
-
} & {
|
|
277
|
-
[K in Swizzles]: NodeProxy<InferSwizzleType<K>>
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// Internal NodeProxy implementation (renamed from original)
|
|
281
|
-
type NodeProxyImpl<T extends Constants = string> = BaseNodeProxy<T> & ReadNodeProxy
|
|
282
|
-
|
|
283
|
-
export type Bool = NodeProxyImpl<'bool'>
|
|
284
|
-
export type UInt = NodeProxyImpl<'uint'>
|
|
285
|
-
export type Int = NodeProxyImpl<'int'>
|
|
286
|
-
export type Float = NodeProxyImpl<'float'>
|
|
287
|
-
export type BVec2 = NodeProxyImpl<'bvec2'>
|
|
288
|
-
export type IVec2 = NodeProxyImpl<'ivec2'>
|
|
289
|
-
export type UVec2 = NodeProxyImpl<'uvec2'>
|
|
290
|
-
export type Vec2 = NodeProxyImpl<'vec2'>
|
|
291
|
-
export type BVec3 = NodeProxyImpl<'bvec3'>
|
|
292
|
-
export type IVec3 = NodeProxyImpl<'ivec3'>
|
|
293
|
-
export type UVec3 = NodeProxyImpl<'uvec3'>
|
|
294
|
-
export type Vec3 = NodeProxyImpl<'vec3'>
|
|
295
|
-
export type BVec4 = NodeProxyImpl<'bvec4'>
|
|
296
|
-
export type IVec4 = NodeProxyImpl<'ivec4'>
|
|
297
|
-
export type UVec4 = NodeProxyImpl<'uvec4'>
|
|
298
|
-
export type Vec4 = NodeProxyImpl<'vec4'>
|
|
299
|
-
export type Color = NodeProxyImpl<'color'>
|
|
300
|
-
export type Mat2 = NodeProxyImpl<'mat2'>
|
|
301
|
-
export type Mat3 = NodeProxyImpl<'mat3'>
|
|
302
|
-
export type Mat4 = NodeProxyImpl<'mat4'>
|
|
303
|
-
export type Texture = NodeProxyImpl<'texture'>
|
|
304
|
-
export type Sampler2D = NodeProxyImpl<'sampler2D'>
|
|
305
|
-
export type Struct = NodeProxyImpl<'struct'>
|
|
306
|
-
|
|
307
|
-
export interface ConstantsToType {
|
|
308
|
-
bool: Bool
|
|
309
|
-
uint: UInt
|
|
310
|
-
int: Int
|
|
311
|
-
float: Float
|
|
312
|
-
bvec2: BVec2
|
|
313
|
-
ivec2: IVec2
|
|
314
|
-
uvec2: UVec2
|
|
315
|
-
vec2: Vec2
|
|
316
|
-
bvec3: BVec3
|
|
317
|
-
ivec3: IVec3
|
|
318
|
-
uvec3: UVec3
|
|
319
|
-
vec3: Vec3
|
|
320
|
-
bvec4: BVec4
|
|
321
|
-
ivec4: IVec4
|
|
322
|
-
uvec4: UVec4
|
|
323
|
-
vec4: Vec4
|
|
324
|
-
color: Color
|
|
325
|
-
mat2: Mat2
|
|
326
|
-
mat3: Mat3
|
|
327
|
-
mat4: Mat4
|
|
328
|
-
texture: Texture
|
|
329
|
-
sampler2D: Sampler2D
|
|
330
|
-
struct: Struct
|
|
384
|
+
step<U extends Constants>(edge: X<U>): NodeProxy<InferOperator<T, U>>
|
|
385
|
+
// @NOTE: mod is operator
|
|
331
386
|
}
|
|
332
|
-
|
|
333
|
-
export type NodeProxy<T extends Constants = string> = T extends keyof ConstantsToType
|
|
334
|
-
? ConstantsToType[T]
|
|
335
|
-
: NodeProxyImpl<T>
|
|
336
|
-
|
|
337
|
-
export type X<T extends Constants = string> = number | string | boolean | undefined | NodeProxy<T> | X[]
|
package/src/node/utils/const.ts
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
export const SWIZZLES = ['x', 'y', 'z', 'w', 'r', 'g', 'b', 'a', 's', 't', 'p', 'q'] as const
|
|
2
2
|
|
|
3
|
+
// Unified order with TYPE_MAPPING array
|
|
4
|
+
export const CONVERSIONS = [
|
|
5
|
+
'toBool',
|
|
6
|
+
'toUint',
|
|
7
|
+
'toInt',
|
|
8
|
+
'toFloat',
|
|
9
|
+
'toBvec2',
|
|
10
|
+
'toIvec2',
|
|
11
|
+
'toUvec2',
|
|
12
|
+
'toVec2',
|
|
13
|
+
'toBvec3',
|
|
14
|
+
'toIvec3',
|
|
15
|
+
'toUvec3',
|
|
16
|
+
'toVec3',
|
|
17
|
+
'toBvec4',
|
|
18
|
+
'toIvec4',
|
|
19
|
+
'toUvec4',
|
|
20
|
+
'toVec4',
|
|
21
|
+
'toColor',
|
|
22
|
+
'toMat2',
|
|
23
|
+
'toMat3',
|
|
24
|
+
'toMat4',
|
|
25
|
+
] as const
|
|
26
|
+
|
|
27
|
+
// Unified order with CONVERSIONS array
|
|
3
28
|
export const TYPE_MAPPING = {
|
|
4
29
|
bool: 'bool',
|
|
5
30
|
uint: 'u32',
|
|
@@ -26,32 +51,10 @@ export const TYPE_MAPPING = {
|
|
|
26
51
|
struct: 'struct',
|
|
27
52
|
} as const
|
|
28
53
|
|
|
29
|
-
export const CONSTANTS = Object.keys(TYPE_MAPPING) as
|
|
30
|
-
|
|
31
|
-
export const CONVERSIONS = [
|
|
32
|
-
'toBool',
|
|
33
|
-
'toUint',
|
|
34
|
-
'toInt',
|
|
35
|
-
'toFloat',
|
|
36
|
-
'toBvec2',
|
|
37
|
-
'toIvec2',
|
|
38
|
-
'toUvec2',
|
|
39
|
-
'toVec2',
|
|
40
|
-
'toBvec3',
|
|
41
|
-
'toIvec3',
|
|
42
|
-
'toUvec3',
|
|
43
|
-
'toVec3',
|
|
44
|
-
'toBvec4',
|
|
45
|
-
'toIvec4',
|
|
46
|
-
'toUvec4',
|
|
47
|
-
'toVec4',
|
|
48
|
-
'toColor',
|
|
49
|
-
'toMat2',
|
|
50
|
-
'toMat3',
|
|
51
|
-
'toMat4',
|
|
52
|
-
] as const
|
|
54
|
+
export const CONSTANTS = Object.keys(TYPE_MAPPING) as (keyof typeof TYPE_MAPPING)[]
|
|
53
55
|
|
|
54
56
|
export const OPERATORS = {
|
|
57
|
+
not: '', // IGNORED
|
|
55
58
|
add: '+',
|
|
56
59
|
sub: '-',
|
|
57
60
|
mul: '*',
|
|
@@ -74,84 +77,6 @@ export const OPERATORS = {
|
|
|
74
77
|
|
|
75
78
|
export const OPERATOR_KEYS = Object.keys(OPERATORS) as (keyof typeof OPERATORS)[]
|
|
76
79
|
|
|
77
|
-
// All shader functions (type inference now handled by inferFrom)
|
|
78
|
-
export const FUNCTIONS = [
|
|
79
|
-
// Float return functions
|
|
80
|
-
'dot',
|
|
81
|
-
'distance',
|
|
82
|
-
'length',
|
|
83
|
-
'lengthSq',
|
|
84
|
-
'determinant',
|
|
85
|
-
'luminance',
|
|
86
|
-
// Bool return functions
|
|
87
|
-
'all',
|
|
88
|
-
'any',
|
|
89
|
-
// Component-wise functions (preserve input type)
|
|
90
|
-
'abs',
|
|
91
|
-
'sign',
|
|
92
|
-
'floor',
|
|
93
|
-
'ceil',
|
|
94
|
-
'round',
|
|
95
|
-
'fract',
|
|
96
|
-
'trunc',
|
|
97
|
-
'sin',
|
|
98
|
-
'cos',
|
|
99
|
-
'tan',
|
|
100
|
-
'asin',
|
|
101
|
-
'acos',
|
|
102
|
-
'atan',
|
|
103
|
-
'sinh',
|
|
104
|
-
'cosh',
|
|
105
|
-
'tanh',
|
|
106
|
-
'asinh',
|
|
107
|
-
'acosh',
|
|
108
|
-
'atanh',
|
|
109
|
-
'exp',
|
|
110
|
-
'exp2',
|
|
111
|
-
'log',
|
|
112
|
-
'log2',
|
|
113
|
-
'sqrt',
|
|
114
|
-
'inverseSqrt',
|
|
115
|
-
'normalize',
|
|
116
|
-
'oneMinus',
|
|
117
|
-
'saturate',
|
|
118
|
-
'negate',
|
|
119
|
-
'reciprocal',
|
|
120
|
-
'dFdx',
|
|
121
|
-
'dFdy',
|
|
122
|
-
'fwidth',
|
|
123
|
-
'degrees',
|
|
124
|
-
'radians',
|
|
125
|
-
// Vector functions
|
|
126
|
-
'cross',
|
|
127
|
-
'reflect',
|
|
128
|
-
'refract',
|
|
129
|
-
// Multi-argument functions
|
|
130
|
-
'min',
|
|
131
|
-
'max',
|
|
132
|
-
'mix',
|
|
133
|
-
'clamp',
|
|
134
|
-
'step',
|
|
135
|
-
'smoothstep',
|
|
136
|
-
'pow',
|
|
137
|
-
'atan2',
|
|
138
|
-
// Texture functions
|
|
139
|
-
'texture',
|
|
140
|
-
'textureLod',
|
|
141
|
-
'textureSize',
|
|
142
|
-
'cubeTexture',
|
|
143
|
-
// Utility functions
|
|
144
|
-
'faceforward',
|
|
145
|
-
'bitcast',
|
|
146
|
-
'cbrt',
|
|
147
|
-
'difference',
|
|
148
|
-
'equals',
|
|
149
|
-
'pow2',
|
|
150
|
-
'pow3',
|
|
151
|
-
'pow4',
|
|
152
|
-
'transformDirection',
|
|
153
|
-
] as const
|
|
154
|
-
|
|
155
80
|
export const COMPONENT_COUNT_TO_TYPE = {
|
|
156
81
|
1: 'float',
|
|
157
82
|
2: 'vec2',
|
|
@@ -161,24 +86,6 @@ export const COMPONENT_COUNT_TO_TYPE = {
|
|
|
161
86
|
16: 'mat4',
|
|
162
87
|
} as const
|
|
163
88
|
|
|
164
|
-
// Function return type mapping for method chaining
|
|
165
|
-
export const FUNCTION_RETURN_TYPES = {
|
|
166
|
-
// Always return vec4
|
|
167
|
-
texture: 'vec4',
|
|
168
|
-
cubeTexture: 'vec4',
|
|
169
|
-
textureSize: 'vec4',
|
|
170
|
-
// Always return float
|
|
171
|
-
length: 'float',
|
|
172
|
-
lengthSq: 'float',
|
|
173
|
-
distance: 'float',
|
|
174
|
-
dot: 'float',
|
|
175
|
-
// Always return bool
|
|
176
|
-
all: 'bool',
|
|
177
|
-
any: 'bool',
|
|
178
|
-
// Always return vec3
|
|
179
|
-
cross: 'vec3',
|
|
180
|
-
} as const
|
|
181
|
-
|
|
182
89
|
export const BUILTIN_TYPES = {
|
|
183
90
|
// WGSL builtin variables
|
|
184
91
|
position: 'vec4',
|
|
@@ -189,6 +96,7 @@ export const BUILTIN_TYPES = {
|
|
|
189
96
|
sample_index: 'uint',
|
|
190
97
|
sample_mask: 'uint',
|
|
191
98
|
point_coord: 'vec2',
|
|
99
|
+
global_invocation_id: 'uvec3',
|
|
192
100
|
|
|
193
101
|
// TSL compatible variables
|
|
194
102
|
positionLocal: 'vec3',
|
|
@@ -238,3 +146,88 @@ export const WGSL_TO_GLSL_BUILTIN = {
|
|
|
238
146
|
point_coord: 'gl_PointCoord',
|
|
239
147
|
uv: 'gl_FragCoord.xy',
|
|
240
148
|
} as const
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 2.1. unified with:
|
|
152
|
+
* 1.1. index.ts functions and
|
|
153
|
+
* 3.1. types.ts BaseNodeProxy
|
|
154
|
+
*/
|
|
155
|
+
// Function return type mapping for method chaining
|
|
156
|
+
export const FUNCTION_RETURN_TYPES = {
|
|
157
|
+
// 0. Always return bool
|
|
158
|
+
all: 'bool',
|
|
159
|
+
any: 'bool',
|
|
160
|
+
// 2. Always return float
|
|
161
|
+
determinant: 'float',
|
|
162
|
+
distance: 'float',
|
|
163
|
+
dot: 'float',
|
|
164
|
+
length: 'float',
|
|
165
|
+
lengthSq: 'float',
|
|
166
|
+
luminance: 'float',
|
|
167
|
+
// 3. Always return vec3
|
|
168
|
+
cross: 'vec3',
|
|
169
|
+
// 4. Always return vec4
|
|
170
|
+
cubeTexture: 'vec4',
|
|
171
|
+
texture: 'vec4',
|
|
172
|
+
texelFetch: 'vec4',
|
|
173
|
+
textureLod: 'vec4',
|
|
174
|
+
} as const
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 2.2. unified with:
|
|
178
|
+
* 1.2. index.ts functions and
|
|
179
|
+
* 3.2. types.ts BaseNodeProxy
|
|
180
|
+
*/
|
|
181
|
+
// All shader functions (type inference now handled by inferFrom)
|
|
182
|
+
export const FUNCTIONS = [
|
|
183
|
+
...(Object.keys(FUNCTION_RETURN_TYPES) as (keyof typeof FUNCTION_RETURN_TYPES)[]),
|
|
184
|
+
// 0. Component-wise functions
|
|
185
|
+
'abs',
|
|
186
|
+
'acos',
|
|
187
|
+
'acosh',
|
|
188
|
+
'asin',
|
|
189
|
+
'asinh',
|
|
190
|
+
'atan',
|
|
191
|
+
'atanh',
|
|
192
|
+
'ceil',
|
|
193
|
+
'cos',
|
|
194
|
+
'cosh',
|
|
195
|
+
'dFdx',
|
|
196
|
+
'dFdy',
|
|
197
|
+
'degrees',
|
|
198
|
+
'exp',
|
|
199
|
+
'exp2',
|
|
200
|
+
'floor',
|
|
201
|
+
'fract',
|
|
202
|
+
'fwidth',
|
|
203
|
+
'inverseSqrt',
|
|
204
|
+
'log',
|
|
205
|
+
'log2',
|
|
206
|
+
'negate',
|
|
207
|
+
'normalize',
|
|
208
|
+
'oneMinus',
|
|
209
|
+
'radians',
|
|
210
|
+
'reciprocal',
|
|
211
|
+
'round',
|
|
212
|
+
'saturate',
|
|
213
|
+
'sign',
|
|
214
|
+
'sin',
|
|
215
|
+
'sinh',
|
|
216
|
+
'sqrt',
|
|
217
|
+
'tan',
|
|
218
|
+
'tanh',
|
|
219
|
+
'trunc',
|
|
220
|
+
// 1. Functions where first argument determines return type
|
|
221
|
+
'atan2',
|
|
222
|
+
'clamp',
|
|
223
|
+
'max',
|
|
224
|
+
'min',
|
|
225
|
+
'mix',
|
|
226
|
+
'pow',
|
|
227
|
+
'reflect',
|
|
228
|
+
'refract',
|
|
229
|
+
// 2. Functions where not first argument determines return type
|
|
230
|
+
'smoothstep',
|
|
231
|
+
'step',
|
|
232
|
+
// @NOTE: mod is operator
|
|
233
|
+
] as const
|