Skip to content

Commit

Permalink
Fix completely broken SHs lol!
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aras-p committed Sep 6, 2023
1 parent 8fa8cca commit b790403
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Assets/Scripts/GaussianSplatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ static unsafe void ReorderSHs(int splatCount, float* data)
{
for (int j = 0; j < shCount; ++j)
{
tmp[j * 3 + 0] = data[idx];
tmp[j * 3 + 1] = data[idx + shCount];
tmp[j * 3 + 2] = data[idx + shCount * 2];
tmp[j * 3 + 0] = data[idx + j];
tmp[j * 3 + 1] = data[idx + j + shCount];
tmp[j * 3 + 2] = data[idx + j + shCount * 2];
}

for (int j = 0; j < shCount * 3; ++j)
Expand Down
5 changes: 3 additions & 2 deletions Assets/Shaders/RenderGaussianSplats.shader
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ static const float SH_C3[] = {
half3 ShadeSH(InputSplat splat, float3 dir)
{
dir *= -1;
dir.z *= -1;

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

// ambient band
half3 res = SH_C0 * splat.sh0;
// 1st degree
res += - splat.sh1 * (y * SH_C1) + splat.sh2 * (z * SH_C1) - splat.sh3 * (x * SH_C1);
res += SH_C1 * (-splat.sh1 * y + splat.sh2 * z - splat.sh3 * x);
// 2nd degree
float xx = x * x, yy = y * y, zz = z * z;
float xy = x * y, yz = y * z, xz = x * z;
Expand All @@ -89,7 +90,7 @@ half3 ShadeSH(InputSplat splat, float3 dir)
(SH_C3[3] * z * (2 * zz - 3 * xx - 3 * yy)) * splat.sh12 +
(SH_C3[4] * x * (4 * zz - xx - yy)) * splat.sh13 +
(SH_C3[5] * z * (xx - yy)) * splat.sh14 +
(SH_C3[6] * x * (xx - 3.0f * yy)) * splat.sh15;
(SH_C3[6] * x * (xx - 3 * yy)) * splat.sh15;
return max(res + 0.5, 0);
}

Expand Down

0 comments on commit b790403

Please sign in to comment.