Skip to content

perf(gsplat): avoid per-frame clearVariants in unified material sync#8778

Merged
mvaligursky merged 1 commit into
mainfrom
mv-gsplat-material-sync
May 26, 2026
Merged

perf(gsplat): avoid per-frame clearVariants in unified material sync#8778
mvaligursky merged 1 commit into
mainfrom
mv-gsplat-material-sync

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

Reduces the unified gsplat material sync to a no-op when nothing changed, so per-frame material.setParameter + material.update() on app.scene.gsplat.material no longer forces a shader variant clear every frame.

Changes:

  • GSplatQuadRenderer.copyMaterialSettings now diffs defines and chunks against the source instead of clearing-and-readding every frame. Defines are synced via setDefine so _definesDirty is tracked correctly; chunks are only re-copied when the source's content key changed.
  • ShaderChunkMap.copy() diffs against the source instead of clear() + re-set(), so unchanged entries no longer mark the map dirty.
  • Material.updateUniforms resets _dirtyShader after clearVariants. The reset previously lived only in StandardMaterial.getShaderVariant, so all other Material subclasses (ShaderMaterial, LitMaterial, ParticleMaterial) left _dirtyShader permanently true and cleared variants on every render.

Examples:

  • multi-splat: switched from device.scope.resolve('uTime').setValue(...) to sceneMat.setParameter('uTime', ...) + sceneMat.update(). This is the recommended pattern for driving animated uniforms on the unified gsplat material — global scope values can be overwritten by other code before the draw, material parameters cannot.

Performance:

  • Eliminates per-frame clearVariants on the unified gsplat material when customizing app.scene.gsplat.material for animated effects.
  • Eliminates per-frame clearVariants on all ShaderMaterials caused by updateUniforms not acknowledging _dirtyShader.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 reduces unnecessary shader-variant invalidation during unified Gaussian Splat (gsplat) material synchronization, especially when users drive animated uniforms via material.setParameter(...) + material.update() each frame. It does this by making chunk/define syncing incremental and by ensuring _dirtyShader is properly reset for all Material subclasses after variants are cleared.

Changes:

  • Make ShaderChunkMap.copy() incremental (delete missing keys + set only when values differ) to avoid marking shader chunks dirty when nothing changed.
  • Fix Material.updateUniforms() to reset _dirtyShader after clearVariants(), and remove the previous StandardMaterial-specific reset in getShaderVariant().
  • Update unified gsplat quad renderer material syncing to diff defines via setDefine() and only re-copy shader chunks when the source chunk key changes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/scene/shader-lib/shader-chunk-map.js Makes shader chunk map copying diff-based to avoid unnecessary dirtying.
src/scene/materials/standard-material.js Removes _dirtyShader reset from getShaderVariant() (now handled generically).
src/scene/materials/material.js Resets _dirtyShader after clearVariants() in updateUniforms() for all materials.
src/scene/gsplat-unified/gsplat-quad-renderer.js Avoids per-frame define/chunk churn during unified material sync by diffing and keying chunk copies.
examples/src/examples/gaussian-splatting/multi-splat.example.mjs Demonstrates driving animated uniforms via setParameter + update() on the unified gsplat material.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mvaligursky mvaligursky merged commit 435cc37 into main May 26, 2026
9 checks passed
@mvaligursky mvaligursky deleted the mv-gsplat-material-sync branch May 26, 2026 10:05
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.

2 participants