Skip to content

Commit b790403

Browse files
committed
Fix completely broken SHs lol!
My reordering code was effectively only picking up the SH1 coefficient instead of all 15 ones. So while the overall "color" (SH0) was correct, the directional aspect was, uhh, "not great". And with that, fix the SH direction axis swapping to be correct.
1 parent 8fa8cca commit b790403

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Assets/Scripts/GaussianSplatRenderer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ static unsafe void ReorderSHs(int splatCount, float* data)
9999
{
100100
for (int j = 0; j < shCount; ++j)
101101
{
102-
tmp[j * 3 + 0] = data[idx];
103-
tmp[j * 3 + 1] = data[idx + shCount];
104-
tmp[j * 3 + 2] = data[idx + shCount * 2];
102+
tmp[j * 3 + 0] = data[idx + j];
103+
tmp[j * 3 + 1] = data[idx + j + shCount];
104+
tmp[j * 3 + 2] = data[idx + j + shCount * 2];
105105
}
106106

107107
for (int j = 0; j < shCount * 3; ++j)

Assets/Shaders/RenderGaussianSplats.shader

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ static const float SH_C3[] = {
6565
half3 ShadeSH(InputSplat splat, float3 dir)
6666
{
6767
dir *= -1;
68+
dir.z *= -1;
6869

6970
float x = dir.x, y = dir.y, z = dir.z;
7071

7172
// ambient band
7273
half3 res = SH_C0 * splat.sh0;
7374
// 1st degree
74-
res += - splat.sh1 * (y * SH_C1) + splat.sh2 * (z * SH_C1) - splat.sh3 * (x * SH_C1);
75+
res += SH_C1 * (-splat.sh1 * y + splat.sh2 * z - splat.sh3 * x);
7576
// 2nd degree
7677
float xx = x * x, yy = y * y, zz = z * z;
7778
float xy = x * y, yz = y * z, xz = x * z;
@@ -89,7 +90,7 @@ half3 ShadeSH(InputSplat splat, float3 dir)
8990
(SH_C3[3] * z * (2 * zz - 3 * xx - 3 * yy)) * splat.sh12 +
9091
(SH_C3[4] * x * (4 * zz - xx - yy)) * splat.sh13 +
9192
(SH_C3[5] * z * (xx - yy)) * splat.sh14 +
92-
(SH_C3[6] * x * (xx - 3.0f * yy)) * splat.sh15;
93+
(SH_C3[6] * x * (xx - 3 * yy)) * splat.sh15;
9394
return max(res + 0.5, 0);
9495
}
9596

0 commit comments

Comments
 (0)