Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/SparkRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ export class SparkRenderer extends THREE.Mesh {
time: { value: 0 },
// Delta time in seconds since last frame
deltaTime: { value: 0 },
// Whether to use three.js's built-in linearToOutputTexel function instead of encodeLinear.
useLinearToOutputTexel: { value: false },
// Whether to encode Gsplat with linear RGB (for environment mapping)
encodeLinear: { value: false },
// Debug flag that alternates each frame
Expand Down Expand Up @@ -536,6 +538,7 @@ export class SparkRenderer extends THREE.Mesh {
| THREE.OrthographicCamera;
this.uniforms.near.value = typedCamera.near;
this.uniforms.far.value = typedCamera.far;
this.uniforms.useLinearToOutputTexel.value = viewpoint.useLinearToOutputTexel;
this.uniforms.encodeLinear.value = viewpoint.encodeLinear;
this.uniforms.maxStdDev.value = this.maxStdDev;
this.uniforms.minPixelRadius.value = this.minPixelRadius;
Expand Down
1 change: 1 addition & 0 deletions src/SparkViewpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class SparkViewpoint {
target?: THREE.WebGLRenderTarget;
private back?: THREE.WebGLRenderTarget;
onTextureUpdated?: (texture: THREE.Texture) => void;
useLinearToOutputTexel = false;
encodeLinear = false;
superXY = 1;
private superPixels?: Uint8Array;
Expand Down
10 changes: 8 additions & 2 deletions src/shaders/splatDefines.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ float pow8(float x) {
}

vec3 srgbToLinear(vec3 rgb) {
return pow(rgb, vec3(2.2));
// See https://github.com/mrdoob/three.js/blob/e04b9f7bd7f5b17103339d343168bfab2d6e0ace/src/math/ColorManagement.js#L205
vec3 linearLow = rgb * 0.0773993808;
vec3 linearHigh = pow(rgb * 0.9478672986 + 0.0521327014, vec3(2.4));
return mix(linearLow, linearHigh, greaterThanEqual(rgb, vec3(0.04045)));
}

vec3 linearToSrgb(vec3 rgb) {
return pow(rgb, vec3(1.0 / 2.2));
// See https://github.com/mrdoob/three.js/blob/e04b9f7bd7f5b17103339d343168bfab2d6e0ace/src/math/ColorManagement.js#L211
vec3 srgbLow = rgb * 12.92;
vec3 srgbHigh = 1.055 * (pow(rgb, vec3(0.41666)) - 0.055);
return mix(srgbLow, srgbHigh, greaterThanEqual(rgb, vec3(0.0031308)));
}

// uint encodeQuatXyz888(vec4 q) {
Expand Down
6 changes: 5 additions & 1 deletion src/shaders/splatFragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ precision highp int;

uniform float near;
uniform float far;
uniform bool useLinearToOutputTexel;
uniform bool encodeLinear;
uniform float time;
uniform bool debugFlag;
Expand Down Expand Up @@ -69,7 +70,7 @@ void main() {
if (rgba.a < minAlpha) {
discard;
}
if (encodeLinear) {
if (useLinearToOutputTexel || encodeLinear) {
rgba.rgb = srgbToLinear(rgba.rgb);
}

Expand All @@ -88,6 +89,9 @@ void main() {
discard;
}
} else {
if (useLinearToOutputTexel) {
rgba = linearToOutputTexel( rgba );
}
#ifdef PREMULTIPLIED_ALPHA
fragColor = vec4(rgba.rgb * rgba.a, rgba.a);
#else
Expand Down