Skip to content

[code-simplifier] Simplify GaussianSplatting ShaderMaterial creation by extracting helper method#18166

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
code-simplifier/gaussian-splatting-material-20260325-157c1da889eb3132
Draft

[code-simplifier] Simplify GaussianSplatting ShaderMaterial creation by extracting helper method#18166
github-actions[bot] wants to merge 1 commit intomasterfrom
code-simplifier/gaussian-splatting-material-20260325-157c1da889eb3132

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Code Simplification - March 25, 2026

This PR simplifies recently modified code to improve clarity, consistency, and maintainability while preserving all functionality.

Files Simplified

  • packages/dev/core/src/Materials/GaussianSplatting/gaussianSplattingMaterial.ts - Extracted helper method to reduce duplication in ShaderMaterial creation

Improvements Made

1. Reduced Duplication

Extracted common ShaderMaterial creation logic into a private static helper method _CreateGaussianSplattingDepthShaderMaterial. This eliminates code duplication between two methods:

  • makeDepthRenderingMaterial (instance method)
  • _MakeGaussianSplattingShadowDepthWrapper (static method)

Before:
Both methods contained nearly identical ShaderMaterial construction code with the same configuration properties and backFaceCulling = false assignment.

After:
Common logic consolidated in a single helper method, called from both locations with appropriate parameters.

+    private static _CreateGaussianSplattingDepthShaderMaterial(
+        name: string,
+        scene: Scene,
+        shaderLanguage: ShaderLanguage,
+        defines?: string[],
+        needAlphaBlending?: boolean
+    ): ShaderMaterial {
+        const shaderMaterial = new ShaderMaterial(
+            name,
+            scene,
+            {
+                vertex: "gaussianSplattingDepth",
+                fragment: "gaussianSplattingDepth",
+            },
+            {
+                attributes: GaussianSplattingMaterial._Attribs,
+                uniforms: GaussianSplattingMaterial._Uniforms,
+                samplers: GaussianSplattingMaterial._Samplers,
+                uniformBuffers: GaussianSplattingMaterial._UniformBuffers,
+                shaderLanguage: shaderLanguage,
+                defines: defines,
+                needAlphaBlending: needAlphaBlending,
+            }
+        );
+        shaderMaterial.backFaceCulling = false;
+        return shaderMaterial;
+    }

2. Enhanced Maintainability

  • Changes to ShaderMaterial configuration now need to be made in only one place
  • Consistent configuration guaranteed across both use cases
  • Clear separation of concerns between material creation and usage

3. Applied Project Standards

  • Used private static method naming convention (_MethodName)
  • Added complete doc comment with parameter descriptions
  • Maintained all existing functionality and behavior

Changes Based On

Recent changes from:

Testing

  • ✅ TypeScript syntax validated
  • ✅ All changes are purely structural - no functional changes
  • ✅ ShaderMaterial configuration remains identical
  • ✅ Both methods maintain their specific logic (defines, wrapper creation)

Review Focus

Please verify:

  • Functionality is preserved in both methods
  • ShaderMaterial configuration matches the original exactly
  • Helper method naming follows project conventions
  • Doc comment is complete and accurate
  • No unintended side effects

Impact

Lines changed:

  • +44 lines (new helper method with documentation)
  • -28 lines (removed duplicate code)
  • Net: Reduced duplication while improving maintainability

Automated by Code Simplifier Agent - analyzing code from the last 24 hours

AI generated by Code Simplifier

  • expires on Mar 26, 2026, 1:01 AM UTC

…er method

Extract common ShaderMaterial creation logic into a private static helper
method to reduce duplication between makeDepthRenderingMaterial and
_MakeGaussianSplattingShadowDepthWrapper.

Both methods were creating ShaderMaterial with nearly identical configuration
and setting backFaceCulling = false. The new _CreateGaussianSplattingDepthShaderMaterial
helper consolidates this logic while maintaining all existing functionality.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Popov72
Copy link
Copy Markdown
Contributor

Popov72 commented Mar 25, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 25, 2026

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 25, 2026

Snapshot stored with reference name:
refs/pull/18166/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18166/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18166/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/18166/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/18166/merge
https://gui.babylonjs.com/?snapshot=refs/pull/18166/merge
https://nme.babylonjs.com/?snapshot=refs/pull/18166/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/18166/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 25, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 25, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 25, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants