@luma.gl/shadertools 9.3.0-alpha.6 → 9.3.0-alpha.9
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/dist.dev.js +2550 -331
- package/dist/dist.min.js +1803 -283
- package/dist/index.cjs +2496 -358
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
- package/dist/lib/preprocessor/preprocessor.js +4 -3
- package/dist/lib/preprocessor/preprocessor.js.map +1 -1
- package/dist/lib/shader-assembler.d.ts +10 -0
- package/dist/lib/shader-assembler.d.ts.map +1 -1
- package/dist/lib/shader-assembler.js +12 -2
- package/dist/lib/shader-assembler.js.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.d.ts +23 -2
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +211 -11
- package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
- package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts +37 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts.map +1 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.js +140 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -0
- package/dist/lib/shader-generator/glsl/generate-glsl.js +3 -0
- package/dist/lib/shader-generator/glsl/generate-glsl.js.map +1 -1
- package/dist/lib/shader-generator/wgsl/generate-wgsl.d.ts.map +1 -1
- package/dist/lib/shader-generator/wgsl/generate-wgsl.js +3 -0
- package/dist/lib/shader-generator/wgsl/generate-wgsl.js.map +1 -1
- package/dist/lib/shader-module/shader-module-uniform-layout.d.ts +22 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.d.ts.map +1 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.js +113 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -0
- package/dist/lib/shader-module/shader-module.d.ts +11 -5
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js.map +1 -1
- package/dist/lib/utils/uniform-types.d.ts +11 -7
- package/dist/lib/utils/uniform-types.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.d.ts +3 -0
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +3 -0
- package/dist/modules/engine/picking/picking.js.map +1 -1
- package/dist/modules/engine/skin/skin.d.ts +7 -6
- package/dist/modules/engine/skin/skin.d.ts.map +1 -1
- package/dist/modules/engine/skin/skin.js +3 -5
- package/dist/modules/engine/skin/skin.js.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +3 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
- package/dist/modules/lighting/ibl/ibl.d.ts +26 -0
- package/dist/modules/lighting/ibl/ibl.d.ts.map +1 -0
- package/dist/modules/lighting/ibl/ibl.js +33 -0
- package/dist/modules/lighting/ibl/ibl.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-material.d.ts +10 -0
- package/dist/modules/lighting/lambert-material/lambert-material.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-material.js +33 -0
- package/dist/modules/lighting/lambert-material/lambert-material.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +3 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +60 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts +2 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js +73 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js.map +1 -0
- package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.js +43 -55
- package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.js +43 -65
- package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts +104 -86
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +96 -83
- package/dist/modules/lighting/lights/lighting.js.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.d.ts +7 -2
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +3 -1
- package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +524 -28
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +2 -2
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +706 -50
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +110 -61
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +85 -9
- package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js +2 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.d.ts +1 -0
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +4 -0
- package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +15 -4
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +36 -5
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +41 -10
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.js.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +2 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +212 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -0
- package/dist/modules/math/fp64/fp64.d.ts +1 -0
- package/dist/modules/math/fp64/fp64.d.ts.map +1 -1
- package/dist/modules/math/fp64/fp64.js +8 -2
- package/dist/modules/math/fp64/fp64.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +19 -2
- package/src/lib/preprocessor/preprocessor.ts +6 -3
- package/src/lib/shader-assembler.ts +17 -2
- package/src/lib/shader-assembly/assemble-shaders.ts +377 -12
- package/src/lib/shader-assembly/wgsl-binding-debug.ts +216 -0
- package/src/lib/shader-generator/glsl/generate-glsl.ts +7 -1
- package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
- package/src/lib/shader-module/shader-module-uniform-layout.ts +195 -0
- package/src/lib/shader-module/shader-module.ts +16 -6
- package/src/lib/utils/uniform-types.ts +24 -9
- package/src/modules/engine/picking/picking.ts +3 -0
- package/src/modules/engine/skin/skin.ts +3 -5
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
- package/src/modules/lighting/ibl/ibl.ts +44 -0
- package/src/modules/lighting/lambert-material/lambert-material.ts +42 -0
- package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +61 -0
- package/src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts +73 -0
- package/src/modules/lighting/lights/lighting-glsl.ts +43 -55
- package/src/modules/lighting/lights/lighting-wgsl.ts +43 -65
- package/src/modules/lighting/lights/lighting.ts +186 -123
- package/src/modules/lighting/no-material/dirlight.ts +3 -1
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +524 -28
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +706 -50
- package/src/modules/lighting/pbr-material/pbr-material.ts +111 -18
- package/src/modules/lighting/pbr-material/pbr-projection.ts +2 -1
- package/src/modules/lighting/phong-material/phong-material.ts +5 -0
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +15 -4
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +36 -5
- package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +41 -10
- package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +212 -0
- package/src/modules/math/fp64/fp64.ts +9 -3
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
export const fp64arithmeticWGSL = /* wgsl */ `\
|
|
5
|
+
struct Fp64ArithmeticUniforms {
|
|
6
|
+
ONE: f32,
|
|
7
|
+
SPLIT: f32,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
@group(0) @binding(auto) var<uniform> fp64arithmetic : Fp64ArithmeticUniforms;
|
|
11
|
+
|
|
12
|
+
fn fp64_nan(seed: f32) -> f32 {
|
|
13
|
+
let nanBits = 0x7fc00000u | select(0u, 1u, seed < 0.0);
|
|
14
|
+
return bitcast<f32>(nanBits);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
fn fp64_runtime_zero() -> f32 {
|
|
18
|
+
return fp64arithmetic.ONE * 0.0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fn prevent_fp64_optimization(value: f32) -> f32 {
|
|
22
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
23
|
+
return value + fp64_runtime_zero();
|
|
24
|
+
#else
|
|
25
|
+
return value;
|
|
26
|
+
#endif
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fn split(a: f32) -> vec2f {
|
|
30
|
+
let splitValue = prevent_fp64_optimization(fp64arithmetic.SPLIT + fp64_runtime_zero());
|
|
31
|
+
let t = prevent_fp64_optimization(a * splitValue);
|
|
32
|
+
let temp = prevent_fp64_optimization(t - a);
|
|
33
|
+
let aHi = prevent_fp64_optimization(t - temp);
|
|
34
|
+
let aLo = prevent_fp64_optimization(a - aHi);
|
|
35
|
+
return vec2f(aHi, aLo);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fn split2(a: vec2f) -> vec2f {
|
|
39
|
+
var b = split(a.x);
|
|
40
|
+
b.y = b.y + a.y;
|
|
41
|
+
return b;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fn quickTwoSum(a: f32, b: f32) -> vec2f {
|
|
45
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
46
|
+
let sum = prevent_fp64_optimization((a + b) * fp64arithmetic.ONE);
|
|
47
|
+
let err = prevent_fp64_optimization(b - (sum - a) * fp64arithmetic.ONE);
|
|
48
|
+
#else
|
|
49
|
+
let sum = prevent_fp64_optimization(a + b);
|
|
50
|
+
let err = prevent_fp64_optimization(b - (sum - a));
|
|
51
|
+
#endif
|
|
52
|
+
return vec2f(sum, err);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fn twoSum(a: f32, b: f32) -> vec2f {
|
|
56
|
+
let s = prevent_fp64_optimization(a + b);
|
|
57
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
58
|
+
let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);
|
|
59
|
+
let err =
|
|
60
|
+
prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *
|
|
61
|
+
fp64arithmetic.ONE *
|
|
62
|
+
fp64arithmetic.ONE *
|
|
63
|
+
fp64arithmetic.ONE) +
|
|
64
|
+
prevent_fp64_optimization(b - v);
|
|
65
|
+
#else
|
|
66
|
+
let v = prevent_fp64_optimization(s - a);
|
|
67
|
+
let err = prevent_fp64_optimization(a - (s - v)) + prevent_fp64_optimization(b - v);
|
|
68
|
+
#endif
|
|
69
|
+
return vec2f(s, err);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fn twoSub(a: f32, b: f32) -> vec2f {
|
|
73
|
+
let s = prevent_fp64_optimization(a - b);
|
|
74
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
75
|
+
let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);
|
|
76
|
+
let err =
|
|
77
|
+
prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *
|
|
78
|
+
fp64arithmetic.ONE *
|
|
79
|
+
fp64arithmetic.ONE *
|
|
80
|
+
fp64arithmetic.ONE) -
|
|
81
|
+
prevent_fp64_optimization(b + v);
|
|
82
|
+
#else
|
|
83
|
+
let v = prevent_fp64_optimization(s - a);
|
|
84
|
+
let err = prevent_fp64_optimization(a - (s - v)) - prevent_fp64_optimization(b + v);
|
|
85
|
+
#endif
|
|
86
|
+
return vec2f(s, err);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fn twoSqr(a: f32) -> vec2f {
|
|
90
|
+
let prod = prevent_fp64_optimization(a * a);
|
|
91
|
+
let aFp64 = split(a);
|
|
92
|
+
let highProduct = prevent_fp64_optimization(aFp64.x * aFp64.x);
|
|
93
|
+
let crossProduct = prevent_fp64_optimization(2.0 * aFp64.x * aFp64.y);
|
|
94
|
+
let lowProduct = prevent_fp64_optimization(aFp64.y * aFp64.y);
|
|
95
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
96
|
+
let err =
|
|
97
|
+
(prevent_fp64_optimization(highProduct - prod) * fp64arithmetic.ONE +
|
|
98
|
+
crossProduct * fp64arithmetic.ONE * fp64arithmetic.ONE) +
|
|
99
|
+
lowProduct * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;
|
|
100
|
+
#else
|
|
101
|
+
let err = ((prevent_fp64_optimization(highProduct - prod) + crossProduct) + lowProduct);
|
|
102
|
+
#endif
|
|
103
|
+
return vec2f(prod, err);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fn twoProd(a: f32, b: f32) -> vec2f {
|
|
107
|
+
let prod = prevent_fp64_optimization(a * b);
|
|
108
|
+
let aFp64 = split(a);
|
|
109
|
+
let bFp64 = split(b);
|
|
110
|
+
let highProduct = prevent_fp64_optimization(aFp64.x * bFp64.x);
|
|
111
|
+
let crossProduct1 = prevent_fp64_optimization(aFp64.x * bFp64.y);
|
|
112
|
+
let crossProduct2 = prevent_fp64_optimization(aFp64.y * bFp64.x);
|
|
113
|
+
let lowProduct = prevent_fp64_optimization(aFp64.y * bFp64.y);
|
|
114
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
115
|
+
let err1 = (highProduct - prod) * fp64arithmetic.ONE;
|
|
116
|
+
let err2 = crossProduct1 * fp64arithmetic.ONE * fp64arithmetic.ONE;
|
|
117
|
+
let err3 = crossProduct2 * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;
|
|
118
|
+
let err4 =
|
|
119
|
+
lowProduct *
|
|
120
|
+
fp64arithmetic.ONE *
|
|
121
|
+
fp64arithmetic.ONE *
|
|
122
|
+
fp64arithmetic.ONE *
|
|
123
|
+
fp64arithmetic.ONE;
|
|
124
|
+
#else
|
|
125
|
+
let err1 = highProduct - prod;
|
|
126
|
+
let err2 = crossProduct1;
|
|
127
|
+
let err3 = crossProduct2;
|
|
128
|
+
let err4 = lowProduct;
|
|
129
|
+
#endif
|
|
130
|
+
let err12InputA = prevent_fp64_optimization(err1);
|
|
131
|
+
let err12InputB = prevent_fp64_optimization(err2);
|
|
132
|
+
let err12 = prevent_fp64_optimization(err12InputA + err12InputB);
|
|
133
|
+
let err123InputA = prevent_fp64_optimization(err12);
|
|
134
|
+
let err123InputB = prevent_fp64_optimization(err3);
|
|
135
|
+
let err123 = prevent_fp64_optimization(err123InputA + err123InputB);
|
|
136
|
+
let err1234InputA = prevent_fp64_optimization(err123);
|
|
137
|
+
let err1234InputB = prevent_fp64_optimization(err4);
|
|
138
|
+
let err = prevent_fp64_optimization(err1234InputA + err1234InputB);
|
|
139
|
+
return vec2f(prod, err);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
fn sum_fp64(a: vec2f, b: vec2f) -> vec2f {
|
|
143
|
+
var s = twoSum(a.x, b.x);
|
|
144
|
+
let t = twoSum(a.y, b.y);
|
|
145
|
+
s.y = prevent_fp64_optimization(s.y + t.x);
|
|
146
|
+
s = quickTwoSum(s.x, s.y);
|
|
147
|
+
s.y = prevent_fp64_optimization(s.y + t.y);
|
|
148
|
+
s = quickTwoSum(s.x, s.y);
|
|
149
|
+
return s;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
fn sub_fp64(a: vec2f, b: vec2f) -> vec2f {
|
|
153
|
+
var s = twoSub(a.x, b.x);
|
|
154
|
+
let t = twoSub(a.y, b.y);
|
|
155
|
+
s.y = prevent_fp64_optimization(s.y + t.x);
|
|
156
|
+
s = quickTwoSum(s.x, s.y);
|
|
157
|
+
s.y = prevent_fp64_optimization(s.y + t.y);
|
|
158
|
+
s = quickTwoSum(s.x, s.y);
|
|
159
|
+
return s;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
fn mul_fp64(a: vec2f, b: vec2f) -> vec2f {
|
|
163
|
+
var prod = twoProd(a.x, b.x);
|
|
164
|
+
let crossProduct1 = prevent_fp64_optimization(a.x * b.y);
|
|
165
|
+
prod.y = prevent_fp64_optimization(prod.y + crossProduct1);
|
|
166
|
+
#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
|
|
167
|
+
prod = split2(prod);
|
|
168
|
+
#endif
|
|
169
|
+
prod = quickTwoSum(prod.x, prod.y);
|
|
170
|
+
let crossProduct2 = prevent_fp64_optimization(a.y * b.x);
|
|
171
|
+
prod.y = prevent_fp64_optimization(prod.y + crossProduct2);
|
|
172
|
+
#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
|
|
173
|
+
prod = split2(prod);
|
|
174
|
+
#endif
|
|
175
|
+
prod = quickTwoSum(prod.x, prod.y);
|
|
176
|
+
return prod;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
fn div_fp64(a: vec2f, b: vec2f) -> vec2f {
|
|
180
|
+
let xn = prevent_fp64_optimization(1.0 / b.x);
|
|
181
|
+
let yn = mul_fp64(a, vec2f(xn, fp64_runtime_zero()));
|
|
182
|
+
let diff = prevent_fp64_optimization(sub_fp64(a, mul_fp64(b, yn)).x);
|
|
183
|
+
let prod = twoProd(xn, diff);
|
|
184
|
+
return sum_fp64(yn, prod);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
fn sqrt_fp64(a: vec2f) -> vec2f {
|
|
188
|
+
if (a.x == 0.0 && a.y == 0.0) {
|
|
189
|
+
return vec2f(0.0, 0.0);
|
|
190
|
+
}
|
|
191
|
+
if (a.x < 0.0) {
|
|
192
|
+
let nanValue = fp64_nan(a.x);
|
|
193
|
+
return vec2f(nanValue, nanValue);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let x = prevent_fp64_optimization(1.0 / sqrt(a.x));
|
|
197
|
+
let yn = prevent_fp64_optimization(a.x * x);
|
|
198
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
199
|
+
let ynSqr = twoSqr(yn) * fp64arithmetic.ONE;
|
|
200
|
+
#else
|
|
201
|
+
let ynSqr = twoSqr(yn);
|
|
202
|
+
#endif
|
|
203
|
+
let diff = prevent_fp64_optimization(sub_fp64(a, ynSqr).x);
|
|
204
|
+
let prod = twoProd(prevent_fp64_optimization(x * 0.5), diff);
|
|
205
|
+
#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
|
|
206
|
+
return sum_fp64(split(yn), prod);
|
|
207
|
+
#else
|
|
208
|
+
return sum_fp64(vec2f(yn, 0.0), prod);
|
|
209
|
+
#endif
|
|
210
|
+
}
|
|
211
|
+
`;
|
|
212
|
+
//# sourceMappingURL=fp64-arithmetic-wgsl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fp64-arithmetic-wgsl.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-arithmetic-wgsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+M5C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp64.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAEtE,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;
|
|
1
|
+
{"version":3,"file":"fp64.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAEtE,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;AAK3F,KAAK,SAAS,GAAG,EAAE,CAAC;AACpB,KAAK,YAAY,GAAG;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC;AACjD,KAAK,YAAY,GAAG,EAAE,CAAC;AAEvB,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,WAAW,EAAE,OAAO,WAAW,CAAC;IAChC,cAAc,EAAE,OAAO,cAAc,CAAC;CACvC,CAAC;AAUF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,SAAS,EAAE,YAAY,EAAE,YAAY,CAAC,GAAG,aAYlF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,aASrC,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,CAAC"}
|
|
@@ -3,19 +3,25 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { fp64ify, fp64LowPart, fp64ifyMatrix4 } from "../../../modules/math/fp64/fp64-utils.js";
|
|
5
5
|
import { fp64arithmeticShader } from "./fp64-arithmetic-glsl.js";
|
|
6
|
+
import { fp64arithmeticWGSL } from "./fp64-arithmetic-wgsl.js";
|
|
6
7
|
import { fp64functionShader } from "./fp64-functions-glsl.js";
|
|
7
8
|
const defaultUniforms = {
|
|
8
9
|
// Used in LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
9
|
-
ONE: 1.0
|
|
10
|
+
ONE: 1.0,
|
|
11
|
+
// Runtime split factor for Dekker splitting. Keeping this as a uniform helps
|
|
12
|
+
// prevent aggressive constant folding in shader compilers.
|
|
13
|
+
SPLIT: 4097.0
|
|
10
14
|
};
|
|
11
15
|
/**
|
|
12
16
|
* 64bit arithmetic: add, sub, mul, div (small subset of fp64 module)
|
|
13
17
|
*/
|
|
14
18
|
export const fp64arithmetic = {
|
|
15
19
|
name: 'fp64arithmetic',
|
|
20
|
+
source: fp64arithmeticWGSL,
|
|
21
|
+
fs: fp64arithmeticShader,
|
|
16
22
|
vs: fp64arithmeticShader,
|
|
17
23
|
defaultUniforms,
|
|
18
|
-
uniformTypes: { ONE: 'f32' },
|
|
24
|
+
uniformTypes: { ONE: 'f32', SPLIT: 'f32' },
|
|
19
25
|
// Additional Functions
|
|
20
26
|
fp64ify,
|
|
21
27
|
fp64LowPart,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp64.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;AAC3F,OAAO,EAAC,oBAAoB,EAAC,kCAA+B;AAC5D,OAAO,EAAC,kBAAkB,EAAC,iCAA8B;AAYzD,MAAM,eAAe,GAAiB;IACpC,gDAAgD;IAChD,GAAG,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"fp64.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;AAC3F,OAAO,EAAC,oBAAoB,EAAC,kCAA+B;AAC5D,OAAO,EAAC,kBAAkB,EAAC,kCAA+B;AAC1D,OAAO,EAAC,kBAAkB,EAAC,iCAA8B;AAYzD,MAAM,eAAe,GAAiB;IACpC,gDAAgD;IAChD,GAAG,EAAE,GAAG;IACR,6EAA6E;IAC7E,2DAA2D;IAC3D,KAAK,EAAE,MAAM;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAwE;IACjG,IAAI,EAAE,gBAAgB;IACtB,MAAM,EAAE,kBAAkB;IAC1B,EAAE,EAAE,oBAAoB;IACxB,EAAE,EAAE,oBAAoB;IACxB,eAAe;IACf,YAAY,EAAE,EAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAC;IAExC,uBAAuB;IACvB,OAAO;IACP,WAAW;IACX,cAAc;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAqC;IACpD,IAAI,EAAE,MAAM;IACZ,EAAE,EAAE,kBAAkB;IACtB,YAAY,EAAE,CAAC,cAAc,CAAC;IAE9B,uBAAuB;IACvB,OAAO;IACP,WAAW;IACX,cAAc;CACf,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/shadertools",
|
|
3
|
-
"version": "9.3.0-alpha.
|
|
3
|
+
"version": "9.3.0-alpha.9",
|
|
4
4
|
"description": "Shader module system for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@luma.gl/core": "9.
|
|
49
|
+
"@luma.gl/core": "9.3.0-alpha.6"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@math.gl/core": "^4.1.0",
|
|
53
53
|
"@math.gl/types": "^4.1.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "737b0f752b3f8a6ae920b394d5ca028427275b37"
|
|
56
56
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,17 +9,28 @@
|
|
|
9
9
|
* Install https://marketplace.visualstudio.com/items?itemName=boyswan.glsl-literal
|
|
10
10
|
*/
|
|
11
11
|
export type {PlatformInfo} from './lib/shader-assembly/platform-info';
|
|
12
|
+
export type {ShaderBindingDebugRow} from './lib/shader-assembly/wgsl-binding-debug';
|
|
12
13
|
|
|
13
14
|
// ShaderModules
|
|
14
15
|
|
|
15
16
|
export type {ShaderModule} from './lib/shader-module/shader-module';
|
|
16
17
|
export type {ShaderPass} from './lib/shader-module/shader-pass';
|
|
17
|
-
export type {UniformTypes} from './lib/utils/uniform-types';
|
|
18
|
+
export type {ShaderModuleUniformValue, UniformTypes} from './lib/utils/uniform-types';
|
|
18
19
|
|
|
19
20
|
export {initializeShaderModule, initializeShaderModules} from './lib/shader-module/shader-module';
|
|
20
21
|
export {getShaderModuleUniforms} from './lib/shader-module/shader-module';
|
|
21
22
|
export {getShaderModuleDependencies} from './lib/shader-module/shader-module-dependencies';
|
|
22
23
|
export {checkShaderModuleDeprecations} from './lib/shader-module/shader-module';
|
|
24
|
+
export type {
|
|
25
|
+
ShaderModuleUniformLayoutStage,
|
|
26
|
+
ShaderModuleUniformLayoutValidationResult
|
|
27
|
+
} from './lib/shader-module/shader-module-uniform-layout';
|
|
28
|
+
export {
|
|
29
|
+
getShaderModuleUniformBlockFields,
|
|
30
|
+
getShaderModuleUniformBlockName,
|
|
31
|
+
getShaderModuleUniformLayoutValidationResult,
|
|
32
|
+
validateShaderModuleUniformLayout
|
|
33
|
+
} from './lib/shader-module/shader-module-uniform-layout';
|
|
23
34
|
|
|
24
35
|
export {getShaderModuleSource} from './lib/shader-assembly/assemble-shaders';
|
|
25
36
|
|
|
@@ -77,12 +88,18 @@ export {
|
|
|
77
88
|
type Light,
|
|
78
89
|
type AmbientLight,
|
|
79
90
|
type PointLight,
|
|
80
|
-
type
|
|
91
|
+
type SpotLight,
|
|
92
|
+
type DirectionalLight,
|
|
93
|
+
type LightingLightUniform
|
|
81
94
|
} from './modules/lighting/lights/lighting';
|
|
82
95
|
|
|
83
96
|
export type {LightingProps, LightingUniforms} from './modules/lighting/lights/lighting';
|
|
84
97
|
export {lighting} from './modules/lighting/lights/lighting';
|
|
98
|
+
export type {IBLBindings} from './modules/lighting/ibl/ibl';
|
|
99
|
+
export {ibl} from './modules/lighting/ibl/ibl';
|
|
85
100
|
export {dirlight} from './modules/lighting/no-material/dirlight';
|
|
101
|
+
export type {LambertMaterialProps} from './modules/lighting/lambert-material/lambert-material';
|
|
102
|
+
export {lambertMaterial} from './modules/lighting/lambert-material/lambert-material';
|
|
86
103
|
export type {GouraudMaterialProps} from './modules/lighting/gouraud-material/gouraud-material';
|
|
87
104
|
export {gouraudMaterial} from './modules/lighting/gouraud-material/gouraud-material';
|
|
88
105
|
export type {PhongMaterialProps} from './modules/lighting/phong-material/phong-material';
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const DEFINE_NAME_PATTERN = '([a-zA-Z_][a-zA-Z0-9_]*)';
|
|
6
|
+
const IFDEF_REGEXP = new RegExp(`^\\s*\\#\\s*ifdef\\s*${DEFINE_NAME_PATTERN}\\s*$`);
|
|
7
|
+
const IFNDEF_REGEXP = new RegExp(`^\\s*\\#\\s*ifndef\\s*${DEFINE_NAME_PATTERN}\\s*(?:\\/\\/.*)?$`);
|
|
7
8
|
const ELSE_REGEXP = /^\s*\#\s*else\s*(?:\/\/.*)?$/;
|
|
8
9
|
const ENDIF_REGEXP = /^\s*\#\s*endif\s*$/;
|
|
9
|
-
const IFDEF_WITH_COMMENT_REGEXP =
|
|
10
|
+
const IFDEF_WITH_COMMENT_REGEXP = new RegExp(
|
|
11
|
+
`^\\s*\\#\\s*ifdef\\s*${DEFINE_NAME_PATTERN}\\s*(?:\\/\\/.*)?$`
|
|
12
|
+
);
|
|
10
13
|
const ENDIF_WITH_COMMENT_REGEXP = /^\s*\#\s*endif\s*(?:\/\/.*)?$/;
|
|
11
14
|
|
|
12
15
|
export type PreprocessorOptions = {
|
|
@@ -10,6 +10,10 @@ import {
|
|
|
10
10
|
assembleWGSLShader,
|
|
11
11
|
assembleGLSLShaderPair
|
|
12
12
|
} from './shader-assembly/assemble-shaders';
|
|
13
|
+
import {
|
|
14
|
+
getShaderBindingDebugRowsFromWGSL,
|
|
15
|
+
type ShaderBindingDebugRow
|
|
16
|
+
} from './shader-assembly/wgsl-binding-debug';
|
|
13
17
|
import {preprocess} from './preprocessor/preprocessor';
|
|
14
18
|
|
|
15
19
|
/**
|
|
@@ -23,6 +27,8 @@ export class ShaderAssembler {
|
|
|
23
27
|
private readonly _hookFunctions: any[] = [];
|
|
24
28
|
/** Shader modules */
|
|
25
29
|
private _defaultModules: ShaderModule[] = [];
|
|
30
|
+
/** Stable per-run WGSL auto-binding assignments keyed by group/module/binding. */
|
|
31
|
+
private readonly _wgslBindingRegistry = new Map<string, number>();
|
|
26
32
|
|
|
27
33
|
/**
|
|
28
34
|
* A default shader assembler instance - the natural place to register default modules and hooks
|
|
@@ -77,13 +83,16 @@ export class ShaderAssembler {
|
|
|
77
83
|
source: string;
|
|
78
84
|
getUniforms: GetUniformsFunc;
|
|
79
85
|
modules: ShaderModule[];
|
|
86
|
+
bindingAssignments: {moduleName: string; name: string; group: number; location: number}[];
|
|
87
|
+
bindingTable: ShaderBindingDebugRow[];
|
|
80
88
|
} {
|
|
81
89
|
const modules = this._getModuleList(props.modules); // Combine with default modules
|
|
82
90
|
const hookFunctions = this._hookFunctions; // TODO - combine with default hook functions
|
|
83
|
-
const {source, getUniforms} = assembleWGSLShader({
|
|
91
|
+
const {source, getUniforms, bindingAssignments} = assembleWGSLShader({
|
|
84
92
|
...props,
|
|
85
93
|
// @ts-expect-error
|
|
86
94
|
source: props.source,
|
|
95
|
+
_bindingRegistry: this._wgslBindingRegistry,
|
|
87
96
|
modules,
|
|
88
97
|
hookFunctions
|
|
89
98
|
});
|
|
@@ -97,7 +106,13 @@ export class ShaderAssembler {
|
|
|
97
106
|
// WGSL does not have built-in preprocessing support (just compile time constants)
|
|
98
107
|
const preprocessedSource =
|
|
99
108
|
props.platformInfo.shaderLanguage === 'wgsl' ? preprocess(source, {defines}) : source;
|
|
100
|
-
return {
|
|
109
|
+
return {
|
|
110
|
+
source: preprocessedSource,
|
|
111
|
+
getUniforms,
|
|
112
|
+
modules,
|
|
113
|
+
bindingAssignments,
|
|
114
|
+
bindingTable: getShaderBindingDebugRowsFromWGSL(preprocessedSource, bindingAssignments)
|
|
115
|
+
};
|
|
101
116
|
}
|
|
102
117
|
|
|
103
118
|
/**
|