mirror of
https://github.com/storytold/spark.git
synced 2026-10-17 00:12:59 +00:00
Externalize render settings minAlpha and maxPixelRadius (#130)
* Add commented benchmarkSort to compare JS vs Wasm sorting. * Add 32-bit float sort via SparkViewpooint.sort32, using 2-pass radix-65536 sort. Turn on sort32 by default for examples/editor. Implemented Rust sort and JS sort, updated benchmarking code to include float16 and float32 sort. * Add sort32 to docs/spark-viewpoint.md. * Externalized SparkRenderer.maxPixelRadius and .minAlpha settings. Added to documentation. Added to examples/editor under Debug folder, moved sort32 there.
This commit is contained in:
committed by
GitHub
parent
23b9b190a0
commit
5eb57038b4
@@ -21,10 +21,6 @@ const float PI = 3.1415926535897932384626433832795;
|
||||
const float INFINITY = 1.0 / 0.0;
|
||||
const float NEG_INFINITY = -INFINITY;
|
||||
|
||||
const float MAX_PIXEL_RADIUS = 512.0;
|
||||
const float MIN_ALPHA = 0.5 * (1.0 / 255.0); // 0.00196
|
||||
const float MAX_STDDEV = sqrt(8.0);
|
||||
|
||||
float sqr(float x) {
|
||||
return x * x;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ uniform float near;
|
||||
uniform float far;
|
||||
uniform bool encodeLinear;
|
||||
uniform float maxStdDev;
|
||||
uniform float minAlpha;
|
||||
uniform bool disableFalloff;
|
||||
uniform float falloff;
|
||||
|
||||
@@ -60,7 +61,7 @@ void main() {
|
||||
|
||||
rgba.a *= mix(1.0, exp(-0.5 * z), falloff);
|
||||
|
||||
if (rgba.a < MIN_ALPHA) {
|
||||
if (rgba.a < minAlpha) {
|
||||
discard;
|
||||
}
|
||||
if (encodeLinear) {
|
||||
|
||||
@@ -16,9 +16,11 @@ uniform uint numSplats;
|
||||
uniform vec4 renderToViewQuat;
|
||||
uniform vec3 renderToViewPos;
|
||||
uniform float maxStdDev;
|
||||
uniform float maxPixelRadius;
|
||||
uniform float time;
|
||||
uniform float deltaTime;
|
||||
uniform bool debugFlag;
|
||||
uniform float minAlpha;
|
||||
uniform bool enable2DGS;
|
||||
uniform float blurAmount;
|
||||
uniform float preBlurAmount;
|
||||
@@ -52,7 +54,7 @@ void main() {
|
||||
vec4 quaternion, rgba;
|
||||
unpackSplat(packed, center, scales, quaternion, rgba);
|
||||
|
||||
if (rgba.a < MIN_ALPHA) {
|
||||
if (rgba.a < minAlpha) {
|
||||
return;
|
||||
}
|
||||
bvec3 zeroScales = equal(scales, vec3(0.0));
|
||||
@@ -141,13 +143,13 @@ void main() {
|
||||
|
||||
float fullBlurAmount = blurAmount;
|
||||
if ((focalDistance > 0.0) && (apertureAngle > 0.0)) {
|
||||
float focusRadius = MAX_PIXEL_RADIUS;
|
||||
float focusRadius = maxPixelRadius;
|
||||
if (viewCenter.z < 0.0) {
|
||||
float focusBlur = abs((-viewCenter.z - focalDistance) / viewCenter.z);
|
||||
float apertureRadius = focal.x * tan(0.5 * apertureAngle);
|
||||
focusRadius = focusBlur * apertureRadius;
|
||||
}
|
||||
fullBlurAmount = clamp(sqr(focusRadius), blurAmount, sqr(MAX_PIXEL_RADIUS));
|
||||
fullBlurAmount = clamp(sqr(focusRadius), blurAmount, sqr(maxPixelRadius));
|
||||
}
|
||||
|
||||
// Do convolution with a 0.5-pixel Gaussian for anti-aliasing: sqrt(0.3) ~= 0.5
|
||||
@@ -159,7 +161,7 @@ void main() {
|
||||
// Compute anti-aliasing intensity scaling factor
|
||||
float blurAdjust = sqrt(max(0.0, detOrig / det));
|
||||
rgba.a *= blurAdjust;
|
||||
if (rgba.a < MIN_ALPHA) {
|
||||
if (rgba.a < minAlpha) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -172,8 +174,8 @@ void main() {
|
||||
vec2 eigenVec1 = normalize(vec2((abs(b) < 0.001) ? 1.0 : b, eigen1 - a));
|
||||
vec2 eigenVec2 = vec2(eigenVec1.y, -eigenVec1.x);
|
||||
|
||||
float scale1 = position.x * min(MAX_PIXEL_RADIUS, maxStdDev * sqrt(eigen1));
|
||||
float scale2 = position.y * min(MAX_PIXEL_RADIUS, maxStdDev * sqrt(eigen2));
|
||||
float scale1 = position.x * min(maxPixelRadius, maxStdDev * sqrt(eigen1));
|
||||
float scale2 = position.y * min(maxPixelRadius, maxStdDev * sqrt(eigen2));
|
||||
|
||||
// Compute the NDC coordinates for the ellipsoid's diagonal axes.
|
||||
vec2 pixelOffset = eigenVec1 * scale1 + eigenVec2 * scale2;
|
||||
|
||||
Reference in New Issue
Block a user