Skip to content

Conversation

@slimbuck
Copy link
Member

@slimbuck slimbuck commented Jun 25, 2025

Fixes: #7789

This PR adds an option to render SOGS spherical harmonics using a fast and memory efficient, but approximate calculation. Instead of using the gaussian's view vector to evaluate spherical harmonics, we use the camera's Z axis.

Background

SOGS compresses spherical harmonics by constructing a palette of 64K coefficients using k-means and then references these once per gaussian. A scene of 1 million gaussians goes from requiring 45MB of SH data to 5MB.

However at render time, the GPU must access the coefficient data in render order. This results in the GPU accessing the palette data almost randomly, thus killing the memory cache and slowing rendering.

With this PR, instead of evaluating the spherical harmonic once for every gaussian, we evaluate all 64K spherical harmonics once per frame. We evaluate all spherical harmonics using the camera's Z direction, instead of the correct approach of using every gaussian's view vector.

The approximation results in accurate spherical harmonic contribution for gaussians at the center of the screen. Gaussians further from center get less accurate contribution.

API changes

  • added a highQualitySH boolean on the gsplat component. This value is false by default.

Results

Here is the before and after profile on a pixel 7 pro. 45ms -> 34ms GPU time. The saving is very dependent on the scene being rendered and the device.

Before After
1000036270 1000036269

And here is a wide angle comparison between high quality and low quality SH:

Before After
Screenshot 2025-06-27 at 14 51 02 Screenshot 2025-06-27 at 14 50 54

@slimbuck slimbuck requested a review from Copilot June 25, 2025 09:31
@slimbuck slimbuck changed the title Add resolve step for SOGS sphericla harm Add resolve step for SOGS spherical harmonics Jun 25, 2025

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

@slimbuck slimbuck changed the title Add resolve step for SOGS spherical harmonics Add fast render path for SOGS spherical harmonics Jun 27, 2025
@slimbuck slimbuck requested a review from Copilot June 27, 2025 14:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a fast, approximate SH render path for SOGS by precomputing a full SH evaluation once per frame along the camera’s Z axis and streaming results through a texture, reducing per-gaussian work.

  • Registered and integrated new WGSL/GLSL chunks (gsplatEvalSH, gsplatQuatToMat3) in shader collections.
  • Implemented GSplatResolveSH to bake SH in a 2D texture and toggle via a new fastSH flag.
  • Exposed fastSH on GSplatComponent/GSplatInstance and wired through resource, instance, and component layers.

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/scene/shader-lib/wgsl/collections/... Added imports/includes for the new WGSL SH and quaternion chunks
src/scene/shader-lib/wgsl/chunks/gsplat/... Added gsplatQuatToMat3, gsplatEvalSH, and replaced inline logic
src/scene/shader-lib/glsl/... Mirrored WGSL changes in GLSL shader collections and chunks
src/scene/gsplat/gsplat-resource-base.js Stubbed evalTextureSize API (returns zero-sized vector)
src/scene/gsplat/gsplat-resolve-sh.js New GSplatResolveSH class for palette texture generation
src/scene/gsplat/gsplat-instance.js Extended GSplatInstance to accept fastSH option and manage resolver
src/framework/components/gsplat/system.js Inserted new fastSH property into the component schema
src/framework/components/gsplat/component.js Added fastSH getter/setter on the component and passed it to instance
Comments suppressed due to low confidence (1)

src/framework/components/gsplat/system.js:20

  • Inserting fastSH into the existing schema order shifts property indices and can break serialized scenes. To maintain backwards compatibility, append new properties at the end of _properties.
    'fastSH',

@slimbuck slimbuck merged commit 16dcf1a into playcanvas:main Jun 30, 2025
7 checks passed
@slimbuck slimbuck deleted the sogs-sh-dev branch June 30, 2025 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Speed up SOGS rendering

3 participants