Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: Introduce PostProcessingUtils #29595

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Oct 8, 2024

Description

It is common when we create some rendering passes to change the renderer settings, this is a common approach and currently we are doing it value by value instead of a function to handle it.

  1. PostProcessingUtils has resetRendererState() that will reset the renderer to default values. This is important not only to store and restore but also to reset so that some pre-rendering or post-processing layers are not affected by specific settings.

  2. Using getRendererState() and setRendererState() simplifies the process to modify the rendering settings that need to be restored later, and makes the system more controlled if we add new features to the renderer.

// store current settings
const rendererState = PostProcessingUtils.resetRendererState( renderer );

renderer.setClearColor( 0xffffff, 1 );
renderer.setRenderTarget( renderTarget );
renderer.setMRT( myMRT );

renderer.renderer( scene, camera );

// restore previous settings
PostProcessingUtils.setRendererState( renderer, rendererState );

@sunag sunag added this to the r170 milestone Oct 8, 2024
Copy link

github-actions bot commented Oct 8, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 689.82
170.9
689.82
170.9
+0 B
+0 B
WebGPU 809.96
218.19
811.56
218.6
+1.6 kB
+416 B
WebGPU Nodes 809.47
218.05
811.07
218.47
+1.6 kB
+424 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 462.84
111.78
462.84
111.78
+0 B
+0 B
WebGPU 535.76
144.59
535.78
144.59
+24 B
+7 B
WebGPU Nodes 491.87
134.33
491.89
134.34
+24 B
+7 B

@sunag sunag marked this pull request as ready for review October 8, 2024 22:44
@sunag sunag merged commit aedf298 into mrdoob:dev Oct 8, 2024
12 checks passed
@sunag sunag deleted the dev-renderer-state branch October 8, 2024 22:46
@@ -50,6 +51,10 @@ class AfterImageNode extends TempNode {

const { renderer } = frame;

_rendererState = PostProcessingUtils.resetRendererState( renderer, _rendererState );
Copy link
Collaborator

@Mugen87 Mugen87 Oct 9, 2024

Choose a reason for hiding this comment

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

Regarding the name: I would expect something like saveRendererState() since what we doing here is essentially saving a snapshot of the current render state which is later restored. So how about:

const rendererState = PostProcessingUtils.saveRendererState( renderer );
PostProcessingUtils.restoreRendererState( renderer, rendererState );

CodyJasonBennett added a commit to CodyJasonBennett/three.js that referenced this pull request Oct 10, 2024
Mugen87 added a commit that referenced this pull request Nov 8, 2024
* Codesplit WebGL/WebGPU entrypoints

* Keep src/Three.js as WebGL entrypoint

* Restore unused three.webgpu.nodes.js

* Restore duplicate entrypoint

* Remove duplicate WebGPU.Nodes artifact

* Revert "Remove duplicate WebGPU.Nodes artifact"

This reverts commit 418db9b.

* Prevent duplicate core artifacts

* Updated builds.

* Try removing builds.

* Revert "Try removing builds."

This reverts commit 880e8bb.

* Puppeteer: inject into core chunk

* Updated builds.

* Remove builds.

* Three.WebGPU: resolve conflicts

#29595

* Isolate Nodes bundles due to chunking

* WebGPU.Nodes: restore individual exports

* Revert isolation of WebGPU.Nodes build

* Isolate Nodes bundles due to chunking

* Revert "Isolate Nodes bundles due to chunking"

This reverts commit ba0c5b4.

* Try isolating Nodes in different order

* Cleanup

---------

Co-authored-by: Michael Herzog <[email protected]>
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