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

Material: Remove obsolete callbacks. #28702

Merged
merged 1 commit into from
Jun 20, 2024
Merged

Material: Remove obsolete callbacks. #28702

merged 1 commit into from
Jun 20, 2024

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Jun 19, 2024

Related issue: -

Description

Material.onBuild() and Material.onBeforeRender() were undocumented methods and only relevant for the former node material integration in WebGLRenderer. Now that the integration has been removed, it's probably best to remove these callbacks as well.

@Mugen87 Mugen87 added this to the r166 milestone Jun 19, 2024
Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
679.7 kB (168.4 kB) 679.8 kB (168.4 kB) +66 B

🌳 Bundle size after tree-shaking

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

Filesize dev Filesize PR Diff
457.4 kB (110.4 kB) 457.5 kB (110.4 kB) +66 B
@mrdoob mrdoob merged commit 5557d53 into mrdoob:dev Jun 20, 2024
12 checks passed
@NikyJJ
Copy link

NikyJJ commented Jul 10, 2024

Hello Mugen87,
onBeforeRender was an excellent method that we used to extend our custom shader materials.
Is it possible to revert this callback and its call from WebGLRenderer?

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jul 10, 2024

Why can't you use Object3D.onBeforeRender() instead?

@NikyJJ
Copy link

NikyJJ commented Jul 10, 2024

It could be possible.
In this case we will need to extend the Mesh class in our code to call the Material.onBeforeRender() in our custom material.
The meshes are created by GLTFLoader now and we will need to go over all meshes and recreate them with the new extended class.
It was very clean solution before r166.

@nkallen
Copy link
Contributor

nkallen commented Jul 24, 2024

Yeah this change broke some stuff for me too, and the workaround is a bit inconvenient...

We have a post processing pass where there is an overrideMaterial on the scene. Material.onBeforeRender was setting a uniform (incrementing a counter to render each object with a distinct color). I'm trying to think about how to best workaround this now.

hybridherbst added a commit to needle-tools/three.js that referenced this pull request Jul 24, 2024
hybridherbst added a commit to needle-tools/three.js that referenced this pull request Jul 24, 2024
hybridherbst added a commit to needle-tools/three.js that referenced this pull request Jul 26, 2024
@gfodor
Copy link

gfodor commented Jul 31, 2024

This change broke the light probe work going on in this thread, since the extension being worked on relies upon onBeforeRender to manage the uniform updates for the irradiance probes, etc.

#18371

@nkallen
Copy link
Contributor

nkallen commented Jul 31, 2024

Yes can we PLEASE revert this change? having a material callback is super useful!

gfodor added a commit to Curiosity-Machines/three.js that referenced this pull request Jul 31, 2024
DOPPLE: Re-restore onBeforeRender on materials, to fix probes.

This reverts commit 5557d53.
@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jul 31, 2024

If we add Material.onBeforeRender() back, there will be only support in WebGLRenderer like with onBeforeCompile().

WebGPURenderer with its node material provides better alternatives. Everyone using Material.onBeforeRender() must be aware of that.

There seems to be no use case for Material.onBuild() so there is no reason to revert its removal.

@nkallen
Copy link
Contributor

nkallen commented Jul 31, 2024

I think that's fine -- we anticipate having to redo a few of our custom shaders when we move to webgpu. For now, the outline effect in Plasticity relies on setting a scene's override material and using a Material.onBeforeRender hook to assign a unique color (uniform) to objects. This is similar to how OutlineEffect.js works, but avoids having to swap out all of the Object3d.onBeforeRenders

You can see in the below picture how each object having a unique color allows edge detection to draw the outline "between" overlapping objects:

Screen Shot 2024-07-31 at 22 07 59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants