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

WebGLNodes: Ensure onBuild() uses the correct material reference. #27097

Merged
merged 3 commits into from
Nov 1, 2023

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Nov 1, 2023

Fixed #27095.

Description

This PR ensures WebGLNodes can process renderings with an active overrideMaterial.

The fix is actually simple. Material.onBuild() does not extract the material from the 3D object anymore but uses this instead.

@Mugen87 Mugen87 added this to the r159 milestone Nov 1, 2023
@@ -8,21 +8,23 @@ export const nodeFrame = new NodeFrame();

Material.prototype.onBuild = function ( object, parameters, renderer ) {

if ( Array.isArray( object.material ) ) {
const material = this;
Copy link
Collaborator Author

@Mugen87 Mugen87 Nov 1, 2023

Choose a reason for hiding this comment

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

@sunag I don't think this fix is compatible with #26841 though. When onBuild() is called in WebGLRenderer, the material can't be an array of materials so using const material = this; and then Array.isArray( object.material ) will always evaluate to false. Any ideas how to avoid breakage of multi materials?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we can't fix this in WebGLNodes, I'll revert and add this to the renderer:

if ( scene.overrideMaterial === null ) material.onBuild( object, parameters, _this );

That means however Scene.overrideMaterial can't be of type node material. But at least #27095 will be fixed.

Copy link
Collaborator Author

@Mugen87 Mugen87 Nov 1, 2023

Choose a reason for hiding this comment

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

I think it would be good to fix this in WebGLNodes somehow since the assumption materials can be derived from the object reference isn't right. I've realized this does not only break overrideMaterial but shadow map rendering as well (since objects with node materials are rendered with depth/distance materials).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I added a remaining reference here, it looks ok to me now using overrideMaterial.

Copy link
Collaborator Author

@Mugen87 Mugen87 Nov 1, 2023

Choose a reason for hiding this comment

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

I have simplified the method a bit. The fiddle from #26811 (comment) still works and #27095 is also fixed. Hope, it looks good!

@Mugen87 Mugen87 marked this pull request as ready for review November 1, 2023 20:09
@Mugen87 Mugen87 merged commit 834d77d into mrdoob:dev Nov 1, 2023
18 checks passed
@Mugen87 Mugen87 changed the title WebGLNodes: Fix usage with overrideMaterial. WebGLNodes: Ensure onBuild() uses the correct material reference. Nov 2, 2023
TobiasNoell pushed a commit to TobiasNoell/three.js that referenced this pull request Nov 8, 2023
* WebGLNodes: Fix usage with `overrideMaterial`.

* follow the material choice by the renderer

* WebGLNodes: Simpify `onBuild()`.

---------

Co-authored-by: sunag <[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.

Crash if using OutlinePass in a scene with node materials and standard materials
2 participants