Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 0 additions & 31 deletions src/scene/renderer/renderer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Debug, DebugHelper } from '../../core/debug.js';
import { now } from '../../core/time.js';
import { BlueNoise } from '../../core/math/blue-noise.js';
import { FloatPacking } from '../../core/math/float-packing.js';

Check failure on line 4 in src/scene/renderer/renderer.js

View workflow job for this annotation

GitHub Actions / Lint

'FloatPacking' is defined but never used
import { Vec2 } from '../../core/math/vec2.js';
import { Vec3 } from '../../core/math/vec3.js';
import { Vec4 } from '../../core/math/vec4.js';
Expand All @@ -15,9 +15,9 @@
SHADERSTAGE_VERTEX, SHADERSTAGE_FRAGMENT,
CULLFACE_BACK, CULLFACE_FRONT, CULLFACE_NONE,
BINDGROUP_MESH_UB,
PIXELFORMAT_R16F,

Check failure on line 18 in src/scene/renderer/renderer.js

View workflow job for this annotation

GitHub Actions / Lint

'PIXELFORMAT_R16F' is defined but never used
FILTER_LINEAR,

Check failure on line 19 in src/scene/renderer/renderer.js

View workflow job for this annotation

GitHub Actions / Lint

'FILTER_LINEAR' is defined but never used
ADDRESS_CLAMP_TO_EDGE

Check failure on line 20 in src/scene/renderer/renderer.js

View workflow job for this annotation

GitHub Actions / Lint

'ADDRESS_CLAMP_TO_EDGE' is defined but never used
} from '../../platform/graphics/constants.js';
import { DebugGraphics } from '../../platform/graphics/debug-graphics.js';
import { UniformBuffer } from '../../platform/graphics/uniform-buffer.js';
Expand All @@ -32,7 +32,7 @@
} from '../constants.js';
import { LightCube } from '../graphics/light-cube.js';
import { getBlueNoiseTexture } from '../graphics/noise-textures.js';
import { Texture } from '../../platform/graphics/texture.js';

Check failure on line 35 in src/scene/renderer/renderer.js

View workflow job for this annotation

GitHub Actions / Lint

'Texture' is defined but never used
import { LightTextureAtlas } from '../lighting/light-texture-atlas.js';
import { Material } from '../materials/material.js';
import { ShadowMapCache } from './shadow-map-cache.js';
Expand Down Expand Up @@ -104,30 +104,6 @@
const _tempMeshInstances = [];
const _tempMeshInstancesSkinned = [];

// construct the exponent lookup table used in gaussian splat rendering
const createExpTableTexture = (device) => {
const expTableSize = 32;
const expTable = new Uint16Array(expTableSize);
for (let i = 0; i < expTableSize; ++i) {
const value = Math.exp(-4.0 * i / (expTableSize - 1));
const nvalue = (value - Math.exp(-4.0)) / (1.0 - Math.exp(-4.0));
expTable[i] = FloatPacking.float2Half(nvalue);
}

return new Texture(device, {
name: 'internal-expTable',
width: expTableSize,
height: 1,
format: PIXELFORMAT_R16F,
mipmaps: false,
minFilter: FILTER_LINEAR,
magFilter: FILTER_LINEAR,
addressU: ADDRESS_CLAMP_TO_EDGE,
addressV: ADDRESS_CLAMP_TO_EDGE,
levels: [expTable]
});
};

/**
* The base renderer functionality to allow implementation of specialized renderers.
*
Expand Down Expand Up @@ -273,7 +249,6 @@
this.blueNoiseJitterData = new Float32Array(4);
this.blueNoiseJitterId = scope.resolve('blueNoiseJitter');
this.blueNoiseTextureId = scope.resolve('blueNoiseTex32');
this.expTableTextureId = scope.resolve('expTable');

this.alphaTestId = scope.resolve('alpha_ref');
this.opacityMapId = scope.resolve('texture_opacityMap');
Expand All @@ -289,8 +264,6 @@
// a single instance of light cube
this.lightCube = new LightCube();
this.constantLightCube = scope.resolve('lightCube[0]');

this.expTableTexture = createExpTableTexture(this.device);
}

destroy() {
Expand All @@ -309,9 +282,6 @@

this.gsplatDirector?.destroy();
this.gsplatDirector = null;

this.expTableTexture?.destroy();
this.expTableTexture = null;
}

/**
Expand Down Expand Up @@ -1232,7 +1202,6 @@
updateFrameUniforms() {
// blue noise texture
this.blueNoiseTextureId.setValue(getBlueNoiseTexture(this.device));
this.expTableTextureId.setValue(this.expTableTexture);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/scene/shader-lib/glsl/chunks/gsplat/frag/gsplat.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ export default /* glsl */`
varying mediump vec2 gaussianUV;
varying mediump vec4 gaussianColor;

uniform sampler2D expTable;
#define EXP4 0.018315638888734 // exp(-4)
#define INV_EXP4 1.018657360363774 // 1 / (1 - exp(-4))

float normExp(float x) {
return (exp(x * -4.0) - EXP4) * INV_EXP4;
}

void main(void) {
mediump float A = dot(gaussianUV, gaussianUV);
if (A > 1.0) {
discard;
}

mediump float alpha = texture2DLod(expTable, vec2(A, 0.5), 0.0).r * gaussianColor.a;
mediump float alpha = normExp(A) * gaussianColor.a;

#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
if (alpha < alphaClip) {
Expand Down
12 changes: 8 additions & 4 deletions src/scene/shader-lib/wgsl/chunks/gsplat/frag/gsplat.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ export default /* wgsl */`
#include "floatAsUintPS"
#endif

const EXP4 = exp(-4.0);
const INV_EXP4 = 1.0 / (1.0 - EXP4);

fn normExp(x: f32) -> f32 {
return (exp(x * -4.0) - EXP4) * INV_EXP4;
}

varying gaussianUV: vec2f;
varying gaussianColor: vec4f;

var expTable: texture_2d<f32>;
var expTableSampler: sampler;

@fragment
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
var output: FragmentOutput;
Expand All @@ -36,7 +40,7 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
}

// evaluate alpha
var alpha = textureSampleLevel(expTable, expTableSampler, vec2f(A, 0.5), 0).r * gaussianColor.a;
var alpha = normExp(A) * gaussianColor.a;

#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
if (alpha < uniform.alphaClip) {
Expand Down
Loading