Skip to content

Commit

Permalink
Fix gsplat discoloration (playcanvas#7383)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck authored Feb 26, 2025
1 parent 154384f commit 469e821
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/scene/gsplat/gsplat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Quat } from '../../core/math/quat.js';
import { Vec2 } from '../../core/math/vec2.js';
import { Vec3 } from '../../core/math/vec3.js';
import {
ADDRESS_CLAMP_TO_EDGE, FILTER_NEAREST, PIXELFORMAT_RGBA16F, PIXELFORMAT_R32U, PIXELFORMAT_RGBA32U,
PIXELFORMAT_RGBA8
ADDRESS_CLAMP_TO_EDGE, FILTER_NEAREST, PIXELFORMAT_RGBA16F, PIXELFORMAT_R32U, PIXELFORMAT_RGBA32U
} from '../../platform/graphics/constants.js';
import { Texture } from '../../platform/graphics/texture.js';
import { BoundingBox } from '../../core/shape/bounding-box.js';
Expand Down Expand Up @@ -80,7 +79,7 @@ class GSplat {
gsplatData.calcAabb(this.aabb);

const size = this.evalTextureSize(numSplats);
this.colorTexture = this.createTexture('splatColor', PIXELFORMAT_RGBA8, size);
this.colorTexture = this.createTexture('splatColor', PIXELFORMAT_RGBA16F, size);
this.transformATexture = this.createTexture('transformA', PIXELFORMAT_RGBA32U, size);
this.transformBTexture = this.createTexture('transformB', PIXELFORMAT_RGBA16F, size);

Expand Down Expand Up @@ -182,6 +181,7 @@ class GSplat {
if (!texture) {
return;
}
const float2Half = FloatPacking.float2Half;
const data = texture.lock();

const cr = gsplatData.getProp('f_dc_0');
Expand All @@ -192,15 +192,15 @@ class GSplat {
const SH_C0 = 0.28209479177387814;

for (let i = 0; i < this.numSplats; ++i) {
const r = (cr[i] * SH_C0 + 0.5) * 255;
const g = (cg[i] * SH_C0 + 0.5) * 255;
const b = (cb[i] * SH_C0 + 0.5) * 255;
const a = 255 / (1 + Math.exp(-ca[i]));

data[i * 4 + 0] = r < 0 ? 0 : r > 255 ? 255 : r;
data[i * 4 + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
data[i * 4 + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
data[i * 4 + 3] = a < 0 ? 0 : a > 255 ? 255 : a;
const r = (cr[i] * SH_C0 + 0.5);
const g = (cg[i] * SH_C0 + 0.5);
const b = (cb[i] * SH_C0 + 0.5);
const a = 1 / (1 + Math.exp(-ca[i]));

data[i * 4 + 0] = float2Half(r);
data[i * 4 + 1] = float2Half(g);
data[i * 4 + 2] = float2Half(b);
data[i * 4 + 3] = float2Half(a);
}

texture.unlock();
Expand Down

0 comments on commit 469e821

Please sign in to comment.