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

Background: Fix update when changing env map. #28966

Merged
merged 1 commit into from
Jul 25, 2024
Merged

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Jul 25, 2024

Related issue: -

Description

Similar to WebGLRenderer, WebGPURenderer should automatically update the background when the environment map assigned to Scene.background changes. The existing check in Background was not 100% correct.

For reproduction: https://jsfiddle.net/1pxtb75k/ (the background does not change to the equirect version)

@Mugen87 Mugen87 added this to the r168 milestone Jul 25, 2024
Copy link

github-actions bot commented Jul 25, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
684 kB (169.4 kB) 684 kB (169.4 kB) +0 B

🌳 Bundle size after tree-shaking

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

Filesize dev Filesize PR Diff
460.9 kB (111.2 kB) 460.9 kB (111.2 kB) +0 B

@@ -89,8 +85,11 @@ class Background extends DataMap {

if ( sceneData.backgroundCacheKey !== backgroundCacheKey ) {

sceneData.backgroundMeshNode.node = vec4( backgroundNode ).mul( backgroundIntensity );
const backgroundMeshNode = getBackgroundMeshNode( backgroundNode );
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sunag Maybe there is a better way to fix this but using a fresh backgroundMeshNode the material is properly updated.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Many of the current issues are related to #27904, the improvement brought better performance but broke some features that need to be reviewed.

Maybe just adding a node.needsUpdate could solve the problem?

sceneData.backgroundMeshNode.needsUpdate = true;
if ( sceneData.backgroundCacheKey !== backgroundCacheKey ) {

	sceneData.backgroundMeshNode.node = vec4( backgroundNode ).mul( backgroundIntensity );
	sceneData.backgroundMeshNode.needsUpdate = true;

	backgroundMesh.material.needsUpdate = true;

	sceneData.backgroundCacheKey = backgroundCacheKey;

}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, that fixes it! I'll update the PR.

@Mugen87 Mugen87 merged commit 95f1142 into mrdoob:dev Jul 25, 2024
11 checks passed
brunosimon pushed a commit to brunosimon/three.js that referenced this pull request Jul 25, 2024
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