Skip to content

Feature Request: OnBeforeRender on Material #21305

@DavidPeicho

Description

@DavidPeicho

Is your feature request related to a problem? Please describe.

Let's say I have a custom material that is shared by two meshes. This material uses the inverse transform of the mesh. In this case, I have no way to send the inverse transform because it's dependent from the actual bound mesh.

When creating an app with Three.js, it's not really an issue because we control the flow of data. However, when wrapping Three.js in another library, it makes it somewhat difficult to share a ShaderMaterial whose parameters aren't independent from the camera / mesh drawn.

Describe the solution you'd like

On the top of my mind:

  • Create a onBeforeRender callback on the material, that would be in charge of updating per-object uniforms. This is similar
    to the onBeforeCompile callback, but called each time something is rendered with this material.

Describe alternatives you've considered

  • Use onBeforeRender on each meshes. Annoying because all meshes using this material must be updated and a user would need to attach the callback himself
  • Clone the material for each mesh

Additional context

This is highly related to the issue #16922. I think the problem is similar.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions