Skip to content

WebGPU support#131

Open
ionox0 wants to merge 22 commits into
agargaro:masterfrom
ionox0:ionox0/webgpu
Open

WebGPU support#131
ionox0 wants to merge 22 commits into
agargaro:masterfrom
ionox0:ionox0/webgpu

Conversation

@ionox0
Copy link
Copy Markdown

@ionox0 ionox0 commented Jun 16, 2025

Support for ThreeJS WebGPURenderer

  • TSL for getBoneMatrix getInstancedMatrix getColorTexture
  • New prototype extensions for webGPU / webGL
  • WebGPU version uses the TSL shaders by setting .fragmentNode and .colorNode

Todo:

  • New SquareDataTextureGPU
    • Make use of InstancedBufferAttribute for texture data?
  • Need to use Uniforms for SquareDataTexture`s?
  • Incorporate existing InstancedMesh2 features

Comment thread src/core/InstancedMesh2.ts Outdated
Comment thread src/core/InstancedMesh2.ts Outdated
Comment thread src/core/InstancedMesh2.ts Outdated
*/
public onFrustumEnter: OnFrustumEnterCallback = null;
/** @internal */ _renderer: WebGLRenderer = null;
/** @internal */ _renderer: WebGLRenderer | WebGPURenderer = null;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Maybe we can use just Renderer type

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Possibly can leave this file untouched if the separate InstancedMeshGPU module works

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

WebGLRenderer and WebGPURenderer do not inherit from a shared Renderer base class, so there are unfortunately many issues when I tried to use Renderer here

Comment thread src/core/InstancedMesh2.ts Outdated
this.uniformsTexture?.update(renderer);
this.boneTexture?.update(renderer);
// TODO convert also morph texture to squared texture to use partial update
if (renderer instanceof WebGLRenderer) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'd prefer to have separate files for webgl and webgpu for better tree shaking, as I did in this repository

@agargaro
Copy link
Copy Markdown
Owner

Thanks!

I would be curious to see the tsl part, after which we can proceed with refactoring.

@ionox0
Copy link
Copy Markdown
Author

ionox0 commented Jun 20, 2025

I included some basic TSL for the shaders.

Also I guess the new InstancedMeshGPU class would be better as a subclass or separate interface instead of duplicating code

Copy link
Copy Markdown

@github-advanced-security github-advanced-security AI left a comment

Choose a reason for hiding this comment

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

ESLint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@Glavin001
Copy link
Copy Markdown

Thanks for starting this PR! I also really want to use InstancedMesh2 for a WebGPU project. Anything I could do to help move this forward? Happy to try to contribute. 😄

@Glavin001
Copy link
Copy Markdown

My WIP adding WebGPU support: #154

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.

4 participants