glre 0.33.0 → 0.35.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 +96 -98
- package/dist/index.cjs +29 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1813 -248
- package/dist/index.js +29 -31
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +29 -31
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.ts +15 -13
- package/dist/native.js +29 -31
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +29 -31
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +29 -31
- package/dist/react.js.map +1 -1
- package/dist/solid.cjs +29 -31
- package/dist/solid.cjs.map +1 -1
- package/dist/solid.d.ts +1 -1
- package/dist/solid.js +29 -31
- package/dist/solid.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +10 -2
- package/src/node/code.ts +13 -9
- package/src/node/const.ts +57 -30
- package/src/node/index.ts +111 -98
- package/src/node/infer.ts +47 -64
- package/src/node/node.ts +19 -17
- package/src/node/parse.ts +38 -33
- package/src/node/scope.ts +25 -20
- package/src/node/types.ts +222 -98
- package/src/node/utils.ts +6 -6
- package/src/types.ts +13 -11
- package/src/utils/program.ts +10 -11
- package/src/webgl.ts +17 -8
- package/src/webgpu.ts +11 -7
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -45,9 +45,10 @@ const defaultVertex = () =>
|
|
|
45
45
|
)
|
|
46
46
|
|
|
47
47
|
export const createGL = (props?: Partial<GL>) => {
|
|
48
|
-
const gl = event
|
|
48
|
+
const gl = event({
|
|
49
49
|
isNative: false,
|
|
50
50
|
isWebGL: true,
|
|
51
|
+
isError: false,
|
|
51
52
|
isLoop: true,
|
|
52
53
|
isGL: true,
|
|
53
54
|
size: [0, 0],
|
|
@@ -55,6 +56,12 @@ export const createGL = (props?: Partial<GL>) => {
|
|
|
55
56
|
count: 6,
|
|
56
57
|
webgl: {},
|
|
57
58
|
webgpu: {},
|
|
59
|
+
loading: 0,
|
|
60
|
+
error() {
|
|
61
|
+
gl.isError = true
|
|
62
|
+
gl.isLoop = false
|
|
63
|
+
gl.clean()
|
|
64
|
+
},
|
|
58
65
|
}) as EventState<GL>
|
|
59
66
|
|
|
60
67
|
gl.queue = createQueue()
|
|
@@ -72,10 +79,12 @@ export const createGL = (props?: Partial<GL>) => {
|
|
|
72
79
|
if (gl.isWebGL) {
|
|
73
80
|
gl((await webgl(gl)) as GL)
|
|
74
81
|
} else gl((await webgpu(gl)) as GL)
|
|
82
|
+
if (gl.isError) return // stop if error
|
|
75
83
|
gl.resize()
|
|
76
84
|
gl.frame(() => {
|
|
77
85
|
gl.loop()
|
|
78
86
|
gl.queue.flush()
|
|
87
|
+
if (gl.loading) return true // wait for textures @TODO FIX
|
|
79
88
|
gl.render()
|
|
80
89
|
return gl.isLoop
|
|
81
90
|
})
|
|
@@ -86,7 +95,6 @@ export const createGL = (props?: Partial<GL>) => {
|
|
|
86
95
|
|
|
87
96
|
gl('clean', () => {
|
|
88
97
|
gl.frame.stop()
|
|
89
|
-
gl.frame.clean(gl.render)
|
|
90
98
|
if (gl.isNative) return
|
|
91
99
|
window.removeEventListener('resize', gl.resize)
|
|
92
100
|
gl.el.removeEventListener('mousemove', gl.mousemove)
|
package/src/node/code.ts
CHANGED
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
parseUniformHead,
|
|
16
16
|
} from './parse'
|
|
17
17
|
import { getBluiltin, getOperator, formatConversions, safeEventCall, getEventFun, initNodeContext } from './utils'
|
|
18
|
-
import type {
|
|
18
|
+
import type { Constants, NodeContext, X } from './types'
|
|
19
19
|
|
|
20
|
-
export const code = (target: X
|
|
20
|
+
export const code = <T extends Constants>(target: X<T>, c?: NodeContext | null): string => {
|
|
21
21
|
if (!c) c = {}
|
|
22
22
|
initNodeContext(c)
|
|
23
23
|
if (is.arr(target)) return parseArray(target, c)
|
|
@@ -25,12 +25,14 @@ export const code = (target: X, c?: NodeContext | null): string => {
|
|
|
25
25
|
if (is.num(target)) {
|
|
26
26
|
const ret = `${target}`
|
|
27
27
|
if (ret.includes('.')) return ret
|
|
28
|
+
// Check if this number should be an integer based on the inferred type
|
|
29
|
+
// For now, keep the original behavior to maintain compatibility
|
|
28
30
|
return ret + '.0'
|
|
29
31
|
}
|
|
30
32
|
if (is.bol(target)) return target ? 'true' : 'false'
|
|
31
33
|
if (!target) return ''
|
|
32
34
|
const { type, props } = target
|
|
33
|
-
const { id = '', children = [], fields, initialValues } = props
|
|
35
|
+
const { id = 'i', children = [], fields, initialValues } = props
|
|
34
36
|
const [x, y, z, w] = children
|
|
35
37
|
/**
|
|
36
38
|
* variables
|
|
@@ -39,16 +41,18 @@ export const code = (target: X, c?: NodeContext | null): string => {
|
|
|
39
41
|
if (type === 'member') return `${code(y, c)}.${code(x, c)}`
|
|
40
42
|
if (type === 'ternary')
|
|
41
43
|
return c.isWebGL
|
|
42
|
-
? `(${code(
|
|
43
|
-
: `select(${code(
|
|
44
|
+
? `(${code(z, c)} ? ${code(x, c)} : ${code(y, c)})`
|
|
45
|
+
: `select(${code(x, c)}, ${code(y, c)}, ${code(z, c)})`
|
|
44
46
|
if (type === 'conversion') return `${formatConversions(x, c)}(${parseArray(children.slice(1), c)})`
|
|
45
47
|
if (type === 'operator') {
|
|
46
48
|
if (x === 'not' || x === 'bitNot') return `!${code(y, c)}`
|
|
47
49
|
return `(${code(y, c)} ${getOperator(x)} ${code(z, c)})`
|
|
48
50
|
}
|
|
49
51
|
if (type === 'function') {
|
|
50
|
-
if (x === 'negate') return `(-${
|
|
52
|
+
if (x === 'negate') return `(-${code(y, c)})`
|
|
53
|
+
if (x === 'oneMinus') return `(1.0-${code(y, c)})`
|
|
51
54
|
if (x === 'texture') return parseTexture(c, y, z, w)
|
|
55
|
+
if (x === 'atan2' && c.isWebGL) return `atan(${code(y, c)}, ${code(z, c)})`
|
|
52
56
|
return `${x}(${parseArray(children.slice(1), c)})`
|
|
53
57
|
}
|
|
54
58
|
/**
|
|
@@ -59,8 +63,8 @@ export const code = (target: X, c?: NodeContext | null): string => {
|
|
|
59
63
|
if (type === 'return') return `return ${code(x, c)};`
|
|
60
64
|
if (type === 'loop')
|
|
61
65
|
return c.isWebGL
|
|
62
|
-
? `for (int
|
|
63
|
-
: `for (var
|
|
66
|
+
? `for (int ${id} = 0; ${id} < ${code(x, c)}; ${id} += 1) {\n${code(y, c)}\n}`
|
|
67
|
+
: `for (var ${id}: i32 = 0; ${id} < ${code(x, c)}; ${id}++) {\n${code(y, c)}\n}`
|
|
64
68
|
if (type === 'if') return parseIf(c, x, y, children)
|
|
65
69
|
if (type === 'switch') return parseSwitch(c, x, children)
|
|
66
70
|
if (type === 'declare') return parseDeclare(c, x, y)
|
|
@@ -70,7 +74,7 @@ export const code = (target: X, c?: NodeContext | null): string => {
|
|
|
70
74
|
}
|
|
71
75
|
if (type === 'struct') {
|
|
72
76
|
if (!c.code?.headers.has(id)) c.code?.headers.set(id, parseStructHead(c, id, fields))
|
|
73
|
-
return parseStruct(c, id,
|
|
77
|
+
return parseStruct(c, id, x.props.id, fields, initialValues)
|
|
74
78
|
}
|
|
75
79
|
/**
|
|
76
80
|
* headers
|
package/src/node/const.ts
CHANGED
|
@@ -74,11 +74,19 @@ export const OPERATORS = {
|
|
|
74
74
|
|
|
75
75
|
export const OPERATOR_KEYS = Object.keys(OPERATORS) as (keyof typeof OPERATORS)[]
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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)
|
|
82
90
|
'abs',
|
|
83
91
|
'sign',
|
|
84
92
|
'floor',
|
|
@@ -92,6 +100,12 @@ export const PRESERVE_TYPE_FUNCTIONS = [
|
|
|
92
100
|
'asin',
|
|
93
101
|
'acos',
|
|
94
102
|
'atan',
|
|
103
|
+
'sinh',
|
|
104
|
+
'cosh',
|
|
105
|
+
'tanh',
|
|
106
|
+
'asinh',
|
|
107
|
+
'acosh',
|
|
108
|
+
'atanh',
|
|
95
109
|
'exp',
|
|
96
110
|
'exp2',
|
|
97
111
|
'log',
|
|
@@ -106,43 +120,38 @@ export const PRESERVE_TYPE_FUNCTIONS = [
|
|
|
106
120
|
'dFdx',
|
|
107
121
|
'dFdy',
|
|
108
122
|
'fwidth',
|
|
109
|
-
] as const
|
|
110
|
-
|
|
111
|
-
export const VEC3_RETURN_FUNCTIONS = ['cross'] as const
|
|
112
|
-
|
|
113
|
-
export const FIRST_ARG_TYPE_FUNCTIONS = ['reflect', 'refract'] as const
|
|
114
|
-
|
|
115
|
-
export const HIGHEST_TYPE_FUNCTIONS = ['min', 'max', 'mix', 'clamp', 'step', 'smoothstep'] as const
|
|
116
|
-
|
|
117
|
-
export const VEC4_RETURN_FUNCTIONS = ['texture', 'textureLod', 'textureSize', 'cubeTexture'] as const
|
|
118
|
-
|
|
119
|
-
export const ADDITIONAL_FUNCTIONS = [
|
|
120
|
-
'atan2',
|
|
121
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
|
|
122
144
|
'faceforward',
|
|
123
145
|
'bitcast',
|
|
124
146
|
'cbrt',
|
|
125
147
|
'difference',
|
|
126
148
|
'equals',
|
|
127
|
-
'pow',
|
|
128
149
|
'pow2',
|
|
129
150
|
'pow3',
|
|
130
151
|
'pow4',
|
|
131
|
-
'radians',
|
|
132
152
|
'transformDirection',
|
|
133
153
|
] as const
|
|
134
154
|
|
|
135
|
-
export const FUNCTIONS = [
|
|
136
|
-
...SCALAR_RETURN_FUNCTIONS,
|
|
137
|
-
...BOOL_RETURN_FUNCTIONS,
|
|
138
|
-
...PRESERVE_TYPE_FUNCTIONS,
|
|
139
|
-
...VEC3_RETURN_FUNCTIONS,
|
|
140
|
-
...FIRST_ARG_TYPE_FUNCTIONS,
|
|
141
|
-
...HIGHEST_TYPE_FUNCTIONS,
|
|
142
|
-
...VEC4_RETURN_FUNCTIONS,
|
|
143
|
-
...ADDITIONAL_FUNCTIONS,
|
|
144
|
-
] as const
|
|
145
|
-
|
|
146
155
|
export const COMPONENT_COUNT_TO_TYPE = {
|
|
147
156
|
1: 'float',
|
|
148
157
|
2: 'vec2',
|
|
@@ -152,6 +161,24 @@ export const COMPONENT_COUNT_TO_TYPE = {
|
|
|
152
161
|
16: 'mat4',
|
|
153
162
|
} as const
|
|
154
163
|
|
|
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
|
+
|
|
155
182
|
export const BUILTIN_TYPES = {
|
|
156
183
|
// WGSL builtin variables
|
|
157
184
|
position: 'vec4',
|
package/src/node/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { is } from '../utils/helpers'
|
|
|
2
2
|
import { code } from './code'
|
|
3
3
|
import { builtin, conversion as c, function_ as f, uniform as u } from './node'
|
|
4
4
|
import { hex2rgb, sortHeadersByDependencies } from './utils'
|
|
5
|
-
import type { NodeContext, X } from './types'
|
|
5
|
+
import type { Constants as C, NodeContext, X, Vec2, Float, NodeProxy } from './types'
|
|
6
6
|
export * from './code'
|
|
7
7
|
export * from './node'
|
|
8
8
|
export * from './scope'
|
|
@@ -56,7 +56,7 @@ export const vertex = (x: X, c: NodeContext) => {
|
|
|
56
56
|
}
|
|
57
57
|
ret.push('}')
|
|
58
58
|
const main = ret.filter(Boolean).join('\n').trim()
|
|
59
|
-
console.log(`↓↓↓generated↓↓↓\n${main}`)
|
|
59
|
+
// console.log(`↓↓↓generated↓↓↓\n${main}`)
|
|
60
60
|
return main
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -79,31 +79,31 @@ export const fragment = (x: X, c: NodeContext) => {
|
|
|
79
79
|
}
|
|
80
80
|
ret.push('}')
|
|
81
81
|
const main = ret.filter(Boolean).join('\n').trim()
|
|
82
|
-
console.log(`↓↓↓generated↓↓↓\n${main}`)
|
|
82
|
+
// console.log(`↓↓↓generated↓↓↓\n${main}`)
|
|
83
83
|
return main
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
// Builtin Variables
|
|
87
|
-
export const position = builtin('position')
|
|
88
|
-
export const vertexIndex = builtin('vertex_index')
|
|
89
|
-
export const instanceIndex = builtin('instance_index')
|
|
90
|
-
export const frontFacing = builtin('front_facing')
|
|
91
|
-
export const fragDepth = builtin('frag_depth')
|
|
92
|
-
export const sampleIndex = builtin('sample_index')
|
|
93
|
-
export const sampleMask = builtin('sample_mask')
|
|
94
|
-
export const pointCoord = builtin('point_coord')
|
|
87
|
+
export const position = builtin<'vec4'>('position')
|
|
88
|
+
export const vertexIndex = builtin<'uint'>('vertex_index')
|
|
89
|
+
export const instanceIndex = builtin<'uint'>('instance_index')
|
|
90
|
+
export const frontFacing = builtin<'bool'>('front_facing')
|
|
91
|
+
export const fragDepth = builtin<'float'>('frag_depth')
|
|
92
|
+
export const sampleIndex = builtin<'uint'>('sample_index')
|
|
93
|
+
export const sampleMask = builtin<'uint'>('sample_mask')
|
|
94
|
+
export const pointCoord = builtin<'vec2'>('point_coord')
|
|
95
95
|
|
|
96
96
|
// TSL Compatible Builtin Variables
|
|
97
|
-
export const
|
|
98
|
-
export const
|
|
99
|
-
export const
|
|
100
|
-
export const
|
|
101
|
-
export const
|
|
102
|
-
export const
|
|
103
|
-
export const screenCoordinate = builtin('screenCoordinate')
|
|
104
|
-
export const screenUV = builtin('screenUV')
|
|
105
|
-
|
|
106
|
-
// Type constructors
|
|
97
|
+
export const positionLocal = builtin<'vec3'>('position')
|
|
98
|
+
export const positionWorld = builtin<'vec3'>('positionWorld')
|
|
99
|
+
export const positionView = builtin<'vec3'>('positionView')
|
|
100
|
+
export const normalLocal = builtin<'vec3'>('normalLocal')
|
|
101
|
+
export const normalWorld = builtin<'vec3'>('normalWorld')
|
|
102
|
+
export const normalView = builtin<'vec3'>('normalView')
|
|
103
|
+
export const screenCoordinate = builtin<'vec2'>('screenCoordinate')
|
|
104
|
+
export const screenUV = builtin<'vec2'>('screenUV')
|
|
105
|
+
|
|
106
|
+
// Type constructors with proper type inference
|
|
107
107
|
export const float = (x?: X) => c('float', x)
|
|
108
108
|
export const int = (x?: X) => c('int', x)
|
|
109
109
|
export const uint = (x?: X) => c('uint', x)
|
|
@@ -130,80 +130,93 @@ export const color = (r?: X, g?: X, b?: X) => {
|
|
|
130
130
|
return vec3(r, g, b)
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
// Default uniforms
|
|
134
|
-
export const iResolution = u(vec2(), 'iResolution')
|
|
135
|
-
export const iMouse = u(vec2(), 'iMouse')
|
|
136
|
-
export const iTime = u(float(), 'iTime')
|
|
137
|
-
export const uv =
|
|
138
|
-
|
|
139
|
-
// Texture Functions
|
|
140
|
-
export const texture = (x: X, y: X, z?: X) => f('texture', x, y, z)
|
|
141
|
-
export const cubeTexture = (x: X, y: X, z?: X) => f('cubeTexture', x, y, z)
|
|
142
|
-
export const textureSize = (x: X, y?: X) => f('textureSize', x, y)
|
|
143
|
-
|
|
144
|
-
//
|
|
145
|
-
export const
|
|
146
|
-
export const
|
|
147
|
-
export const
|
|
148
|
-
export const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
export const
|
|
152
|
-
export const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
export const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
export const
|
|
159
|
-
export const
|
|
160
|
-
export const
|
|
161
|
-
export const
|
|
162
|
-
export const
|
|
163
|
-
export const
|
|
164
|
-
export const
|
|
165
|
-
export const
|
|
166
|
-
export const
|
|
167
|
-
export const
|
|
168
|
-
export const
|
|
169
|
-
export const
|
|
170
|
-
export const
|
|
171
|
-
export const
|
|
172
|
-
export const
|
|
173
|
-
export const
|
|
174
|
-
export const
|
|
175
|
-
export const
|
|
176
|
-
export const
|
|
177
|
-
export const
|
|
178
|
-
export const
|
|
179
|
-
export const
|
|
180
|
-
export const
|
|
181
|
-
export const
|
|
182
|
-
export const
|
|
183
|
-
export const
|
|
184
|
-
export const
|
|
185
|
-
export const
|
|
186
|
-
export const
|
|
187
|
-
export const reciprocal = (x: X) => f('reciprocal', x)
|
|
188
|
-
export const
|
|
189
|
-
export const
|
|
190
|
-
export const
|
|
191
|
-
export const
|
|
192
|
-
export const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
export const
|
|
196
|
-
export const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
export const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
//
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
133
|
+
// Default uniforms with proper typing
|
|
134
|
+
export const iResolution: Vec2 = u(vec2(), 'iResolution')
|
|
135
|
+
export const iMouse: Vec2 = u(vec2(), 'iMouse')
|
|
136
|
+
export const iTime: Float = u(float(), 'iTime')
|
|
137
|
+
export const uv = position.xy.div(iResolution)
|
|
138
|
+
|
|
139
|
+
// Texture Functions - always return vec4
|
|
140
|
+
export const texture = (x: X, y: X, z?: X) => f<'vec4'>('texture', x, y, z)
|
|
141
|
+
export const cubeTexture = (x: X, y: X, z?: X) => f<'vec4'>('cubeTexture', x, y, z)
|
|
142
|
+
export const textureSize = (x: X, y?: X) => f<'vec4'>('textureSize', x, y)
|
|
143
|
+
|
|
144
|
+
// Functions that always return float regardless of input
|
|
145
|
+
export const length = (x: X) => f<'float'>('length', x)
|
|
146
|
+
export const lengthSq = (x: X) => f<'float'>('lengthSq', x)
|
|
147
|
+
export const distance = (x: X, y: X) => f<'float'>('distance', x, y)
|
|
148
|
+
export const dot = (x: X, y: X) => f<'float'>('dot', x, y)
|
|
149
|
+
|
|
150
|
+
// Functions that always return bool
|
|
151
|
+
export const all = <T extends C>(x: X<T>) => f<'bool'>('all', x)
|
|
152
|
+
export const any = <T extends C>(x: X<T>) => f<'bool'>('any', x)
|
|
153
|
+
|
|
154
|
+
// Functions that always return vec3 (cross product only works with vec3)
|
|
155
|
+
export const cross = (x: X<'vec3'>, y: X<'vec3'>) => f<'vec3'>('cross', x, y)
|
|
156
|
+
|
|
157
|
+
// Component-wise functions - preserve input type (T -> T)
|
|
158
|
+
export const abs = <T extends C>(x: X<T>) => f<T>('abs', x)
|
|
159
|
+
export const sign = <T extends C>(x: X<T>) => f<T>('sign', x)
|
|
160
|
+
export const floor = <T extends C>(x: X<T>) => f<T>('floor', x)
|
|
161
|
+
export const ceil = <T extends C>(x: X<T>) => f<T>('ceil', x)
|
|
162
|
+
export const round = <T extends C>(x: X<T>) => f<T>('round', x)
|
|
163
|
+
export const fract = <T extends C>(x: X<T>) => f<T>('fract', x)
|
|
164
|
+
export const trunc = <T extends C>(x: X<T>) => f<T>('trunc', x)
|
|
165
|
+
export const sin = <T extends C>(x: X<T>) => f<T>('sin', x)
|
|
166
|
+
export const cos = <T extends C>(x: X<T>) => f<T>('cos', x)
|
|
167
|
+
export const tan = <T extends C>(x: X<T>) => f<T>('tan', x)
|
|
168
|
+
export const asin = <T extends C>(x: X<T>) => f<T>('asin', x)
|
|
169
|
+
export const acos = <T extends C>(x: X<T>) => f<T>('acos', x)
|
|
170
|
+
export const atan = <T extends C>(x: X<T>) => f<T>('atan', x)
|
|
171
|
+
export const sinh = <T extends C>(x: X<T>) => f<T>('sinh', x)
|
|
172
|
+
export const cosh = <T extends C>(x: X<T>) => f<T>('cosh', x)
|
|
173
|
+
export const tanh = <T extends C>(x: X<T>) => f<T>('tanh', x)
|
|
174
|
+
export const asinh = <T extends C>(x: X<T>) => f<T>('asinh', x)
|
|
175
|
+
export const acosh = <T extends C>(x: X<T>) => f<T>('acosh', x)
|
|
176
|
+
export const atanh = <T extends C>(x: X<T>) => f<T>('atanh', x)
|
|
177
|
+
export const exp = <T extends C>(x: X<T>) => f<T>('exp', x)
|
|
178
|
+
export const exp2 = <T extends C>(x: X<T>) => f<T>('exp2', x)
|
|
179
|
+
export const log = <T extends C>(x: X<T>) => f<T>('log', x)
|
|
180
|
+
export const log2 = <T extends C>(x: X<T>) => f<T>('log2', x)
|
|
181
|
+
export const sqrt = <T extends C>(x: X<T>) => f<T>('sqrt', x)
|
|
182
|
+
export const inverseSqrt = <T extends C>(x: X<T>) => f<T>('inverseSqrt', x)
|
|
183
|
+
export const normalize = <T extends C>(x: X<T>) => f<T>('normalize', x)
|
|
184
|
+
export const oneMinus = <T extends C>(x: X<T>) => f<T>('oneMinus', x)
|
|
185
|
+
export const saturate = <T extends C>(x: X<T>) => f<T>('saturate', x)
|
|
186
|
+
export const negate = <T extends C>(x: X<T>) => f<T>('negate', x)
|
|
187
|
+
export const reciprocal = <T extends C>(x: X<T>) => f<T>('reciprocal', x)
|
|
188
|
+
export const dFdx = <T extends C>(x: X<T>) => f<T>('dFdx', x)
|
|
189
|
+
export const dFdy = <T extends C>(x: X<T>) => f<T>('dFdy', x)
|
|
190
|
+
export const fwidth = <T extends C>(x: X<T>) => f<T>('fwidth', x)
|
|
191
|
+
export const degrees = <T extends C>(x: X<T>) => f<T>('degrees', x)
|
|
192
|
+
export const radians = <T extends C>(x: X<T>) => f<T>('radians', x)
|
|
193
|
+
|
|
194
|
+
// Functions where first argument determines return type
|
|
195
|
+
export const reflect = <T extends C>(I: X<T>, N: X) => f<T>('reflect', I, N)
|
|
196
|
+
export const refract = <T extends C>(I: X<T>, N: X, eta: X) => f<T>('refract', I, N, eta)
|
|
197
|
+
|
|
198
|
+
// Functions with highest priority type among arguments (using first arg for simplicity)
|
|
199
|
+
export const min = <T extends C>(x: X<T>, y: X) => f<T>('min', x, y)
|
|
200
|
+
export const max = <T extends C>(x: X<T>, y: X) => f<T>('max', x, y)
|
|
201
|
+
export const mix = <T extends C>(x: X<T>, y: X, a: X) => f<T>('mix', x, y, a)
|
|
202
|
+
export const clamp = <T extends C>(x: X<T>, minVal: X, maxVal: X) => f<T>('clamp', x, minVal, maxVal)
|
|
203
|
+
export const step = <T extends C>(edge: X, x: X<T>) => f<T>('step', edge, x)
|
|
204
|
+
export const smoothstep = <T extends C>(e0: X, e1: X, x: X<T>) => f<T>('smoothstep', e0, e1, x)
|
|
205
|
+
|
|
206
|
+
// Two-argument functions with highest priority type
|
|
207
|
+
export const atan2 = <T extends C>(y: X<T>, x: X) => f<T>('atan2', y, x)
|
|
208
|
+
export const pow = <T extends C>(x: X<T>, y: X) => f<T>('pow', x, y)
|
|
209
|
+
|
|
210
|
+
// Component-wise power functions
|
|
211
|
+
export const pow2 = <T extends C>(x: X<T>) => f<T>('pow2', x)
|
|
212
|
+
export const pow3 = <T extends C>(x: X<T>) => f<T>('pow3', x)
|
|
213
|
+
export const pow4 = <T extends C>(x: X<T>) => f<T>('pow4', x)
|
|
214
|
+
|
|
215
|
+
// Utility functions
|
|
216
|
+
export const bitcast = <T extends C>(x: X<T>, y: X) => f<T>('bitcast', x, y)
|
|
217
|
+
export const cbrt = <T extends C>(x: X<T>) => f<T>('cbrt', x)
|
|
218
|
+
export const difference = <T extends C>(x: X<T>, y: X) => f<T>('difference', x, y)
|
|
219
|
+
export const equals = (x: X, y: X) => f<'bool'>('equals', x, y)
|
|
220
|
+
export const faceforward = <T extends C>(N: X<T>, I: X, Nref: X) => f<T>('faceforward', N, I, Nref)
|
|
221
|
+
export const transformDirection = <T extends C>(dir: X<T>, matrix: X) => f<T>('transformDirection', dir, matrix)
|
|
222
|
+
export const mod = <T extends C>(x: NodeProxy<T>, y: X<T>) => x.sub(x.div(y).floor().mul(y))
|