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

NodeMaterial: Use materialReference() for env maps. #28982

Merged
merged 4 commits into from
Aug 1, 2024
Merged

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Jul 26, 2024

Related issue: -

Description

It is currently not possible to dynamically update material.envMap: https://jsfiddle.net/br8ezgfw/1/

That works in WebGLRenderer and it also works to exchange normal textures (e.g. material.map) with WebGPURenderer .

The issue can be resolved by using materialReference() when setting up the env node in NodeMaterial but that leads unfortunately to a cyclic dependency:

src/nodes/accessors/MaterialNode.js -> 
src/nodes/accessors/ReferenceNode.js -> 
src/nodes/accessors/CubeTextureNode.js -> 
src/nodes/accessors/ReflectVectorNode.js -> 
src/nodes/accessors/MaterialNode.js

@sunag I wonder if you have any ideas to solve this issue. What I find not optimal is the fact that CubeTextureNode.getDefaultUV() has a material dependency since refractVector relies on the refraction ratio of the material.

Would it be an option to move the uv computation into the place where the sampling actually happens (that is BasicLightingModel)? However, without proper default uvs, it might be inconvenient to use cubeTexture() elsewhere in the code base and on app level.

@Mugen87 Mugen87 marked this pull request as draft July 26, 2024 10:15
Copy link

github-actions bot commented Jul 26, 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

@sunag
Copy link
Collaborator

sunag commented Jul 29, 2024

A few time ago I started this approach #28422 avoiding classes and directing everything to the TSL approach, there are certainly a lot of classes to review with this.

let envNode = this.envNode;

if ( envNode.isTextureNode ) {
if ( envNode.isTextureNode || envNode.isMaterialReferenceNode ) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FYI: I had to add this check otherwise PMREM generation was broken.

Copy link
Collaborator Author

@Mugen87 Mugen87 Jul 29, 2024

Choose a reason for hiding this comment

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

Exchanging the env map for basic, lambert and phong works now as expected. Great!

However, EnvironmentNode needs an enhancement since the PMREM isn't regenerated when envMap is changed.

updateBefore() might be a good spot for checking the status but I'm not sure how to access the material without the builder reference. Besides, ideally we only update the PMREM node without regenerating the radiance and irradiance node. Is that even possible?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like having a reference()/materialReference() supporting pmrem we could be removed this cacheEnv using MeshStandardNodeMaterial.setupEnvironment() for create this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's tackle this in a different PR.

@Mugen87 Mugen87 marked this pull request as ready for review July 29, 2024 09:07
@Mugen87 Mugen87 marked this pull request as draft July 29, 2024 09:07
@Mugen87 Mugen87 marked this pull request as ready for review August 1, 2024 11:07
@Mugen87 Mugen87 merged commit 423f285 into mrdoob:dev Aug 1, 2024
12 checks passed
@Mugen87 Mugen87 added this to the r168 milestone Aug 1, 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