Skip to content

Commit 0b6410a

Browse files
authored
Optimize sqrt calls (#8070)
1 parent 7a2059b commit 0b6410a

File tree

7 files changed

+7
-7
lines changed

7 files changed

+7
-7
lines changed

src/core/math/random.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const random = {
3636
*/
3737
circlePointDeterministic(point, index, numPoints) {
3838
const theta = index * _goldenAngle;
39-
const r = Math.sqrt(index) / Math.sqrt(numPoints);
39+
const r = Math.sqrt(index / numPoints);
4040

4141
point.x = r * Math.cos(theta);
4242
point.y = r * Math.sin(theta);

src/scene/gsplat/gsplat-compressed-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SplatCompressedIterator {
3232

3333
// unpack quaternion with 2,10,10,10 format (largest element, 3x10bit element)
3434
const unpackRot = (result, value) => {
35-
const norm = 1.0 / (Math.sqrt(2) * 0.5);
35+
const norm = Math.SQRT2;
3636
const a = (unpackUnorm(value >>> 20, 10) - 0.5) * norm;
3737
const b = (unpackUnorm(value >>> 10, 10) - 0.5) * norm;
3838
const c = (unpackUnorm(value, 10) - 0.5) * norm;

src/scene/gsplat/gsplat-sogs-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class GSplatSogsIterator {
5454
const sh_labels_data = sh && data.sh_labels._levels[0];
5555
const sh_centroids_data = sh && data.sh_centroids._levels[0];
5656

57-
const norm = 2.0 / Math.sqrt(2.0);
57+
const norm = Math.SQRT2;
5858

5959
const coeffs = { 1: 3, 2: 8, 3: 15 }[shBands] ?? 0;
6060

src/scene/shader-lib/glsl/chunks/gsplat/vert/gsplatCompressedData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ vec4 unpack8888(uint bits) {
2727
);
2828
}
2929
30-
const float norm = 1.0 / (sqrt(2.0) * 0.5);
30+
const float norm = sqrt(2.0);
3131
3232
vec4 unpackRotation(uint bits) {
3333
float a = (float((bits >> 20u) & 0x3ffu) / 1023.0 - 0.5) * norm;

src/scene/shader-lib/glsl/chunks/gsplat/vert/gsplatSogsData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ vec3 readCenter(SplatSource source) {
2525
return sign(v) * (exp(abs(v)) - 1.0);
2626
}
2727
28-
const float norm = 2.0 / sqrt(2.0);
28+
const float norm = sqrt(2.0);
2929
3030
// sample covariance vectors
3131
void readCovariance(in SplatSource source, out vec3 covA, out vec3 covB) {

src/scene/shader-lib/wgsl/chunks/gsplat/vert/gsplatCompressedData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn unpack8888(bits: u32) -> vec4f {
2323
) / 255.0;
2424
}
2525
26-
const norm_const: f32 = 1.0 / (sqrt(2.0) * 0.5);
26+
const norm_const: f32 = sqrt(2.0);
2727
2828
fn unpackRotation(bits: u32) -> vec4f {
2929
let a = (f32((bits >> 20u) & 0x3ffu) / 1023.0 - 0.5) * norm_const;

src/scene/shader-lib/wgsl/chunks/gsplat/vert/gsplatSogsData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn readCenter(source: ptr<function, SplatSource>) -> vec3f {
2424
return sign(v) * (exp(abs(v)) - 1.0);
2525
}
2626
27-
const norm: f32 = 2.0 / sqrt(2.0);
27+
const norm: f32 = sqrt(2.0);
2828
2929
// sample covariance vectors
3030
fn readCovariance(source: ptr<function, SplatSource>, covA_ptr: ptr<function, vec3f>, covB_ptr: ptr<function, vec3f>) {

0 commit comments

Comments
 (0)