I would like to say “material plugins” is a great feature! It opens the door to extend while keeps the solid implement of PBRMaterial.
But the document is not detailed enough to get more people like me to release the power of plugins.
For example, I want to create a plugin which adds a texture as a mask to PBRMaterial. And I struggled several hours but could not make it work. Until I saw this comment:
Because I followed the doc firstly. And the doc mentions “PBR material includes several complex plugins”. (at the end of link) So I opened the source code such as material.detailMapConfiguration.ts and lost my way.
We can compare the example in the comment and detailMapConfiguration
. For learning purpose, detailMapConfiguration is too complex. Taking detailSampler
for example:
First, it has no getCustomCode
method. Which is main logic as usual. Though I found related code in the bumpFragment.fx
, I cannot find where defined “uniform sampler2D detailSampler”. I even used Spector.js to check the fragment code. And since there are methods like getSamplers
, I thought it will add the declaration for me.
Second, it lacks key point as an example. The code considers too many cases. Like, blocking before texture ready, texture dirty resolving, many operations between on and off, etc. It even has a special defines
. They mislead me to think I have to handle all of logics.
Third, it is not a good resource to follow if I want to write the plugin as good as it. As I cannot know why I have to write code like that. Special case? Performance? Are there other cases I have to handle? As a result, I can only write something like a demo. It may be broken in the case I don’t know, or is not efficient.
To clarify, code insides getCustomCode
should not be the main part of the doc. It is shader logic. And the doc should focus on the “plugin logic”.
BTW, as the plugin mechanism is like a “inject”, is it possible to open these inject point to node material? It is more convenient to deem PBRMaterial as blocks and we can add more. Yes there are PBRMetallicRoughnessBlock in node material right now. But it lacks some handles like fog. If I want to replace the imported gltf model’s PBRMaterial with node material, how many things I have to align with?