Splat Texture (#79)

* Add experimental Splat Texture rendering and examples/splat-texture. Added star.png and heart.png to assets.json and to assets repo. Update examples/depth-of-field to compute from metric aperture size. Added SparkRenderer.renderScale debug parameter. Updated examples/editor: set default highDPI to true, added logFocalDistance, apertureAngle, refactored, grouped into debugFolder, default settings open, preset buttons for nonAA and AA settings.

* Set default highDpi in examples/editor to not(isMobile).
This commit is contained in:
Andreas Sundquist
2025-07-01 07:57:34 -07:00
committed by GitHub
parent c0db3576bd
commit 179885595c
9 changed files with 359 additions and 40 deletions
+44 -9
View File
@@ -4,11 +4,21 @@ precision highp int;
#include <splatDefines>
uniform float near;
uniform float far;
uniform bool encodeLinear;
uniform float maxStdDev;
uniform bool disableFalloff;
uniform float falloff;
uniform bool splatTexEnable;
uniform sampler3D splatTexture;
uniform mat2 splatTexMul;
uniform vec2 splatTexAdd;
uniform float splatTexNear;
uniform float splatTexFar;
uniform float splatTexMid;
out vec4 fragColor;
in vec4 vRgba;
@@ -16,20 +26,45 @@ in vec2 vSplatUv;
in vec3 vNdc;
void main() {
vec4 rgba = vRgba;
float z = dot(vSplatUv, vSplatUv);
if (z > (maxStdDev * maxStdDev)) {
discard;
if (!splatTexEnable) {
if (z > (maxStdDev * maxStdDev)) {
discard;
}
} else {
vec2 uv = splatTexMul * vSplatUv + splatTexAdd;
float ndcZ = vNdc.z;
float depth = (2.0 * near * far) / (far + near - ndcZ * (far - near));
float clampedFar = max(splatTexFar, splatTexNear);
float clampedDepth = clamp(depth, splatTexNear, clampedFar);
float logDepth = log2(clampedDepth + 1.0);
float logNear = log2(splatTexNear + 1.0);
float logFar = log2(clampedFar + 1.0);
float texZ;
if (splatTexMid > 0.0) {
float clampedMid = clamp(splatTexMid, splatTexNear, clampedFar);
float logMid = log2(clampedMid + 1.0);
texZ = (clampedDepth <= clampedMid) ?
(0.5 * ((logDepth - logNear) / (logMid - logNear))) :
(0.5 * ((logDepth - logMid) / (logFar - logMid)) + 0.5);
} else {
texZ = (logDepth - logNear) / (logFar - logNear);
}
vec4 modulate = texture(splatTexture, vec3(uv, 1.0 - texZ));
rgba *= modulate;
}
float alpha = vRgba.a;
alpha *= mix(1.0, exp(-0.5 * z), falloff);
if (alpha < MIN_ALPHA) {
rgba.a *= mix(1.0, exp(-0.5 * z), falloff);
if (rgba.a < MIN_ALPHA) {
discard;
}
vec3 rgb = vRgba.rgb;
if (encodeLinear) {
rgb = srgbToLinear(rgb);
rgba.rgb = srgbToLinear(rgba.rgb);
}
fragColor = vec4(rgb, alpha);
fragColor = rgba;
}
+4 -2
View File
@@ -25,6 +25,7 @@ uniform float preBlurAmount;
uniform float focalDistance;
uniform float apertureAngle;
uniform float clipXY;
uniform float renderScale;
uniform usampler2DArray packedSplats;
@@ -111,7 +112,8 @@ void main() {
mat3 cov3D = RS * transpose(RS);
// Compute the Jacobian of the splat's projection at its center
vec2 focal = 0.5 * renderSize * vec2(projectionMatrix[0][0], projectionMatrix[1][1]);
vec2 scaledRenderSize = renderSize * renderScale;
vec2 focal = 0.5 * scaledRenderSize * vec2(projectionMatrix[0][0], projectionMatrix[1][1]);
float invZ = 1.0 / viewCenter.z;
vec2 J1 = focal * invZ;
vec2 J2 = -(J1 * viewCenter.xy) * invZ;
@@ -175,7 +177,7 @@ void main() {
// Compute the NDC coordinates for the ellipsoid's diagonal axes.
vec2 pixelOffset = eigenVec1 * scale1 + eigenVec2 * scale2;
vec2 ndcOffset = (2.0 / renderSize) * pixelOffset;
vec2 ndcOffset = (2.0 / scaledRenderSize) * pixelOffset;
vec3 ndc = vec3(ndcCenter.xy + ndcOffset, ndcCenter.z);
vRgba = rgba;