PBRBaseMaterial overwrites plugin's defines

For the PBRBaseMaterial, _callbackPluginEventPrepareDefines is called before PrepareDefinesForFrameBoundValues and PrepareDefinesForAttributes. This means that defines set by a material plugin can be overwritten by these.

But for the StandardMaterial, _callbackPluginEventPrepareDefines is called after PrepareDefinesForFrameBoundValues and PrepareDefinesForAttributes. This way the plugin gets the final say for these defines.

For example when setting defines for the uvs, they will be overwritten when using PBR materials but the uvs will work when using the plugin with a StandardMaterial.

So here’s a PR that simply moves the call to _callbackPluginEventPrepareDefines to be after the other two calls for PBRBaseMaterial, like it is for StandardMaterial. :slight_smile:

2 Likes

Also here’s a simple test PG using UVs in a material plugin that currently works only for StandardMaterial (left box) but also works for PBR materials (right box) with this change.

EDIT: It turns out that the anisotropy plugin is relying on the current order of calls so I changed the PR to a “draft” for now…

1 Like

You could potentially add a new event ?

Hmm I think for consistency ideally the new event should be added for both StandardMaterial and PBRBaseMaterial, maybe called prepareDefinesBeforeAttributes, with prepareDefines called after all the material plugin helpers like it is for StandardMaterial currently? :thinking:

Yup sounds good to me let s see if @Evgeni_Popov can think of any thing to not do it ?

1 Like

No, that seems ok to me as it won’t break anything anyway.

2 Likes

Okay I updated the PR with this new function and it’s passing validation now that the anisotropy plugin is using it, so changed from “draft” to “ready for review”. :slight_smile:

1 Like