Skip to content

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Aug 24, 2025

Closes #27628

Description

@aardgoose did a great job on PR #27628; this PR is a reinterpretation with a focus on simplification given the renderer’s current times.

With CanvasRenderTarget it’s possible to use multiple canvases sharing existing resources—such as the cache—from the same Renderer. Since the previous process, like webgpu_multiple_elements, can bring other difficulties—because it is a whole canvas on the screen rendering only the scissor—or creating a new Renderer with a new canvas does not reuse the previous renderer’s caches, this feature becomes the most recommended for this application, given that the focus is only the WebGPU backend; at least in this PR it will be used exclusively for this backend.

Usage

// -- setup --
const canvas = document.querySelector( '#mycanvas'  );
const canvasRenderTarget  = new THREE.CanvasRenderTarget( canvas );

// -- loop --
renderer.setOutputRenderTarget( canvasRenderTarget );
renderer.render( scene, camera );

Note that renderer.setOutputRenderTarget() must respect the renderer.outputColorSpace.

@sunag sunag added this to the r180 milestone Aug 24, 2025
Copy link

github-actions bot commented Aug 24, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 338.91
79.11
338.91
79.11
+0 B
+0 B
WebGPU 578.16
159.25
579.42
159.58
+1.26 kB
+327 B
WebGPU Nodes 576.76
159.01
578.03
159.34
+1.26 kB
+324 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 470.78
113.9
470.78
113.9
+0 B
+0 B
WebGPU 648.69
175.28
649.67
175.51
+975 B
+224 B
WebGPU Nodes 602.79
164.41
603.76
164.63
+975 B
+223 B

@@ -1519,6 +1527,8 @@ class Renderer {

this._renderOutput( renderTarget );

this.setRenderTarget( previousRenderTarget, activeCubeFace, activeMipmapLevel );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you mind explaining why you have added this line?

We should check if this addition does not break XR.

Copy link
Collaborator Author

@sunag sunag Aug 24, 2025

Choose a reason for hiding this comment

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

After setting setRenderTarget() as outputRenderTarget it does not restore the previous state, making the current getRenderTarget() the same as getOutputRenderTarget() after the render, thus being a bug.

Copy link
Collaborator

@Mugen87 Mugen87 Aug 24, 2025

Choose a reason for hiding this comment

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

I try to make a test with a Quest 2 tomorrorw. Just to be on the safe side since r180 is released next week.

@sunag sunag marked this pull request as ready for review August 24, 2025 20:11
if ( texture.isFramebufferTexture ) {

if ( options.renderTarget ) {

options.format = this.backend.utils.getCurrentColorFormat( options.renderTarget );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to keep updating the options object as before?

options is not only used in createTexture() but also in subsequent code like updateTexture(). To avoid side effects, it would be beneficial if options does not loose any information with these changes.

Copy link
Collaborator

@Mugen87 Mugen87 Aug 25, 2025

Choose a reason for hiding this comment

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

Could you please also temporarily update the builds? I can then build a rawgit URL for WebXR testing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm checking an issue with anti aliasing, I think it would be better to wait a bit for final testing.

image

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