Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,11 @@ 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!


for ( const material of object.material ) {
if ( material.isNodeMaterial === true ) {

if ( material.isNodeMaterial === true ) {

builders.set( material, new WebGLNodeBuilder( object, renderer, parameters, material ).build() );

}

}

} else if ( object.material.isNodeMaterial === true ) {

builders.set( object.material, new WebGLNodeBuilder( object, renderer, parameters ).build() );
builders.set( material, new WebGLNodeBuilder( object, renderer, parameters, material ).build() );

}

Expand Down