Skip to content

AfterImageNode: Fix usage of multiple nodes. #30834

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

Merged
merged 2 commits into from
Apr 1, 2025

Conversation

Makio64
Copy link
Contributor

@Makio64 Makio64 commented Mar 31, 2025

Fixed #30832

Description

Fix afterImage when multiple PostProcessing & afterImage are used

@@ -1,9 +1,6 @@
import { RenderTarget, Vector2, QuadMesh, NodeMaterial, RendererUtils, TempNode, NodeUpdateType } from 'three/webgpu';
import { nodeObject, Fn, float, uv, texture, passTexture, uniform, sign, max, convertToTexture } from 'three/tsl';

const _size = /*@__PURE__*/ new Vector2();
const _quadMeshComp = /*@__PURE__*/ new QuadMesh();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using a quad mesh in module scope is a pattern frequently used in FX classes.

Does the error mentioned in #30832 happen with other classes as well? E.g. AnamorphicNode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just did a quick test and it seems to works fine on anamorphic node

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Mugen87 the main difference between anamorphic and afterImage is one set the material in the nodeBuilder ( afterImage ) , the other one in the updateBefore

Copy link
Collaborator

Choose a reason for hiding this comment

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

one set the material in the nodeBuilder ( afterImage )

Do you mind explaining in more detail. I'm afraid I don't understand yet.

If possible, I would prefer a solution that avoids handling quad meshes differently.

Copy link
Contributor Author

@Makio64 Makio64 Mar 31, 2025

Choose a reason for hiding this comment

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

afterImage : _quadMeshComp.material = materialComposed is in setup( builder )
So the material is override by the last afterImage node built and it create the bug with multiple afterImage / PostProcessing.

anamorphic :_quadMesh.material = this._material is set in updateBefore( frame ) so before the rendering, therefore it allow one _quadMesh to be share between all anamorphic instance with no problem.

The second approach (anamorphic) is better and functionnal with multiple node /PostProcessing, but then I'm wondering why there is more than one _quadMesh for all fx node and why not only one quadMesh share between all of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

interesting, maybe its time as threejs orient itself to support webgpu ? also looking at caniuse es2020 & es2020 Feature support list i think it will be safe on new version of threejs to go for it. @mrdoob

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Mugen87 i change the fix , using updateBefore( frame ) , tested on my project and it works correctly now with multiple postprocessing / afterImage node

Copy link
Collaborator

@Mugen87 Mugen87 Apr 1, 2025

Choose a reason for hiding this comment

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

Regarding ES2020: The big blocker were build tools like Webpack 4 at that time. Since we don't transpile, we must make sure tools like Webpack 4 are compatible with the raw code base, see #25168.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understand, just checked and webpack4 it isnt support anymore ( last commit 6years ago ) so I guess its safe to assume users using latest threejs also evolve but i dont have the full scope / policy of threejs and let you guys decide! thanks for validate the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another note: I did a quick analyze using ai on other node and afterImageNode looks like an isolated case ;)

@Mugen87 Mugen87 added this to the r176 milestone Apr 1, 2025
@Mugen87 Mugen87 changed the title fix afterImageNode when multiple afterImage exist AfterImageNode: Fix usage of multiple nodes. Apr 1, 2025
@Mugen87 Mugen87 merged commit 838d357 into mrdoob:dev Apr 1, 2025
11 checks passed
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.

Multiple postprocessing with afterImage dont work
2 participants