Skip to content

Initial clustered lights implementation (tiled clustering only) #16866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
fb3179b
Clustered lights initial implementation
matanui159 Jul 8, 2025
f47efdd
Make changes a bit less invasive to other code
matanui159 Jul 8, 2025
e0e7d6a
Detect how many supported lights there are
matanui159 Jul 8, 2025
dd8a0a2
Render lights to render-target
matanui159 Jul 9, 2025
4b926f8
Tiled clustering
matanui159 Jul 9, 2025
aaa4705
Expose shader precision via engine
matanui159 Jul 10, 2025
b98f8f9
Thin instances
matanui159 Jul 11, 2025
f5aa2f9
Make light mask configurable
matanui159 Jul 14, 2025
310e60a
WebGPU support
matanui159 Jul 16, 2025
0555de4
Simplify, remove depth prepass, add back webgl support
matanui159 Jul 17, 2025
e629c96
Add more options, prevent depth clipping
matanui159 Jul 17, 2025
afcee59
Scale matrices
matanui159 Jul 17, 2025
d972dbd
PointLight support
matanui159 Jul 17, 2025
ac8cd58
Comment change
matanui159 Jul 17, 2025
b0c09b7
Fix WebGL performance
matanui159 Jul 18, 2025
f054a01
Expand proxy mesh, fix lack of conservative
matanui159 Jul 21, 2025
be19d47
PBR materials (no webgpu yet)
matanui159 Jul 22, 2025
977c8ee
Small tweaks
matanui159 Jul 23, 2025
5ce7064
Switch to using disc mesh
matanui159 Jul 23, 2025
05f9beb
PBR WebGPU
matanui159 Jul 24, 2025
0c749a0
Initial uncapped limit (hacky, webgl only, not amazing performance, n…
matanui159 Jul 24, 2025
01b8357
WebGPU support and performance improvement
matanui159 Jul 24, 2025
d1c2755
Add support for non-UBO devices
matanui159 Jul 24, 2025
f17f361
PBR support
matanui159 Jul 25, 2025
9781991
Fix tile size issue
matanui159 Jul 25, 2025
25c245c
Bring over improvements from depth clustering PR
matanui159 Jul 29, 2025
9077390
Cleanup and fixes
matanui159 Jul 29, 2025
739cef1
Add doc comments
matanui159 Jul 30, 2025
e1da5ca
Build fixup
matanui159 Jul 30, 2025
d2b1431
Serialize and register
matanui159 Jul 30, 2025
7905fb7
More cleanup
matanui159 Jul 31, 2025
441aaba
Fix PBR shader
matanui159 Jul 31, 2025
cb8a44d
Add remove light functionality
matanui159 Jul 31, 2025
4bfc5ee
PR fixes
matanui159 Aug 11, 2025
ac21597
Add visualization test
matanui159 Aug 11, 2025
f7face5
Switch to square and calculate sphere horizons
matanui159 Aug 14, 2025
312fbca
Remove unused GLSL function
matanui159 Aug 14, 2025
a604c97
Add square mesh to WebGPU too
matanui159 Aug 15, 2025
05ec636
Mass renaming
matanui159 Aug 15, 2025
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
9 changes: 9 additions & 0 deletions packages/dev/core/src/Buffers/storageBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export class StorageBuffer {
return this._buffer;
}

/**
* Clears the storage buffer to zeros
* @param byteOffset the byte offset to start clearing (optional)
* @param byteLength the byte length to clear (optional)
*/
public clear(byteOffset?: number, byteLength?: number): void {
this._engine.clearStorageBuffer(this._buffer, byteOffset, byteLength);
}

/**
* Updates the storage buffer
* @param data the data used to update the storage buffer
Expand Down
4 changes: 4 additions & 0 deletions packages/dev/core/src/Engines/engineCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface EngineCapabilities {
maxVertexUniformVectors: number;
/** Maximum number of uniforms per fragment shader */
maxFragmentUniformVectors: number;
/** The number of bits that can be accurately represented in shader floats */
shaderFloatPrecision: number;
/** Defines if standard derivatives (dx/dy) are supported */
standardDerivatives: boolean;
/** Defines if s3tc texture compression is supported */
Expand Down Expand Up @@ -80,6 +82,8 @@ export interface EngineCapabilities {
depthTextureExtension: boolean;
/** Defines if float color buffer are supported */
colorBufferFloat: boolean;
/** Defines if float color blending is supported */
blendFloat: boolean;
/** Defines if half float color buffer are supported */
colorBufferHalfFloat?: boolean;
/** Gets disjoint timer query extension (null if not supported) */
Expand Down
2 changes: 2 additions & 0 deletions packages/dev/core/src/Engines/nativeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export class NativeEngine extends Engine {
maxDrawBuffers: 8,
maxFragmentUniformVectors: 16,
maxVertexUniformVectors: 16,
shaderFloatPrecision: 23, // TODO: is this correct?
standardDerivatives: true,
astc: null,
pvrtc: null,
Expand All @@ -297,6 +298,7 @@ export class NativeEngine extends Engine {
fragmentDepthSupported: false,
highPrecisionShaderSupported: true,
colorBufferFloat: false,
blendFloat: false,
supportFloatTexturesResolve: false,
rg11b10ufColorRenderable: false,
textureFloat: true,
Expand Down
2 changes: 2 additions & 0 deletions packages/dev/core/src/Engines/nullEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class NullEngine extends Engine {
maxVaryingVectors: 16,
maxFragmentUniformVectors: 16,
maxVertexUniformVectors: 16,
shaderFloatPrecision: 10, // Minimum precision for mediump floats WebGL 1
standardDerivatives: false,
astc: null,
pvrtc: null,
Expand All @@ -144,6 +145,7 @@ export class NullEngine extends Engine {
fragmentDepthSupported: false,
highPrecisionShaderSupported: true,
colorBufferFloat: false,
blendFloat: false,
supportFloatTexturesResolve: false,
rg11b10ufColorRenderable: false,
textureFloat: false,
Expand Down
15 changes: 15 additions & 0 deletions packages/dev/core/src/Engines/thinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ export class ThinEngine extends AbstractEngine {
maxVaryingVectors: this._gl.getParameter(this._gl.MAX_VARYING_VECTORS),
maxFragmentUniformVectors: this._gl.getParameter(this._gl.MAX_FRAGMENT_UNIFORM_VECTORS),
maxVertexUniformVectors: this._gl.getParameter(this._gl.MAX_VERTEX_UNIFORM_VECTORS),
shaderFloatPrecision: 0,
parallelShaderCompile: this._gl.getExtension("KHR_parallel_shader_compile") || undefined,
standardDerivatives: this._webGLVersion > 1 || this._gl.getExtension("OES_standard_derivatives") !== null,
maxAnisotropy: 1,
Expand Down Expand Up @@ -531,6 +532,7 @@ export class ThinEngine extends AbstractEngine {
drawBuffersExtension: false,
maxMSAASamples: 1,
colorBufferFloat: !!(this._webGLVersion > 1 && this._gl.getExtension("EXT_color_buffer_float")),
blendFloat: this._gl.getExtension("EXT_float_blend") !== null,
supportFloatTexturesResolve: false,
rg11b10ufColorRenderable: false,
colorBufferHalfFloat: !!(this._webGLVersion > 1 && this._gl.getExtension("EXT_color_buffer_half_float")),
Expand Down Expand Up @@ -732,6 +734,19 @@ export class ThinEngine extends AbstractEngine {

if (vertexhighp && fragmenthighp) {
this._caps.highPrecisionShaderSupported = vertexhighp.precision !== 0 && fragmenthighp.precision !== 0;
this._caps.shaderFloatPrecision = Math.min(vertexhighp.precision, fragmenthighp.precision);
}
// This will check both the capability and the `useHighPrecisionFloats` option
if (!this._shouldUseHighPrecisionShader) {
const vertexmedp = this._gl.getShaderPrecisionFormat(this._gl.VERTEX_SHADER, this._gl.MEDIUM_FLOAT);
const fragmentmedp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.MEDIUM_FLOAT);
if (vertexmedp && fragmentmedp) {
this._caps.shaderFloatPrecision = Math.min(vertexmedp.precision, fragmentmedp.precision);
}
}
if (this._caps.shaderFloatPrecision < 10) {
// WebGL spec requires mediump precision to atleast be 10
this._caps.shaderFloatPrecision = 10;
}
}

Expand Down
12 changes: 12 additions & 0 deletions packages/dev/core/src/Engines/webgpuEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
maxVaryingVectors: this._deviceLimits.maxInterStageShaderVariables,
maxFragmentUniformVectors: Math.floor(this._deviceLimits.maxUniformBufferBindingSize / 4),
maxVertexUniformVectors: Math.floor(this._deviceLimits.maxUniformBufferBindingSize / 4),
shaderFloatPrecision: 23, // WGSL always uses IEEE-754 binary32 floats (which have 23 bits of significand)
standardDerivatives: true,
astc: (this._deviceEnabledExtensions.indexOf(WebGPUConstants.FeatureName.TextureCompressionASTC) >= 0 ? true : undefined) as any,
s3tc: (this._deviceEnabledExtensions.indexOf(WebGPUConstants.FeatureName.TextureCompressionBC) >= 0 ? true : undefined) as any,
Expand All @@ -877,6 +878,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
fragmentDepthSupported: true,
highPrecisionShaderSupported: true,
colorBufferFloat: true,
blendFloat: this._deviceEnabledExtensions.indexOf(WebGPUConstants.FeatureName.Float32Blendable) >= 0,
supportFloatTexturesResolve: false, // See https://github.com/gpuweb/gpuweb/issues/3844
rg11b10ufColorRenderable: this._deviceEnabledExtensions.indexOf(WebGPUConstants.FeatureName.RG11B10UFloatRenderable) >= 0,
textureFloat: true,
Expand Down Expand Up @@ -3936,6 +3938,16 @@ export class WebGPUEngine extends ThinWebGPUEngine {
return this._createBuffer(data, creationFlags | Constants.BUFFER_CREATIONFLAG_STORAGE, label);
}

/**
* Clears a storage buffer to zeroes
* @param storageBuffer the storage buffer to clear
* @param byteOffset the byte offset to start clearing (optional)
* @param byteLength the byte length to clear (optional)
*/
public clearStorageBuffer(storageBuffer: DataBuffer, byteOffset?: number, byteLength?: number): void {
this._renderEncoder.clearBuffer(storageBuffer.underlyingResource, byteOffset, byteLength);
}

/**
* Updates a storage buffer
* @param buffer the storage buffer to update
Expand Down
Loading
Loading