How to add a custom shader to the standard or PBR material shaders?

I want to konw how to add the effect of HeapMap based on existing pbr material?
Now I have completed the effect of HeapMap,but I don’t want to change the existing PBR effect of the model.

You can create a material plugin for your code:

2 Likes

Hello,according to the case you gave me, I have completed customization of PBR material with custom shader code.

However, I encountered a new difficulty. I want to add heat maps to the model where the pick occurred when the mouse clicks on the model ,but now heat maps appear at random places in the model after Material Plugins.

When I use the custom material alone, the position of heat maps is correct,just appeared where I clicked.

I can’t find a case for transferring float arrays in Material Plugins. Did I make an error in the array processing?

var mPoints = new Float32Array(32 * 3);
HeatMapPluginMaterial._Marks=mPoints;

static _Marks = new Float32Array(32 * 3);
{ name: “_Marks”, size: 3 * 32, type: “float[24]” },
uniform float[3 * 32] _Marks;
uniformBuffer.updateFloatArray(“_Marks”, HeatMapPluginMaterial._Marks);

What you are doing seems to work, but it would be better to declare it as such in getUniforms :

    { name: "_Marks", size: 1, type: "float", arraySize: 96 },

If I click 3 or 4 times on the same spot, the circle appears there. Maybe there is a problem somewhere in the picking or updating of the uniforms?

You can see what is going on better with Spector, as you will be able to see what values are being transferred for your uniforms, as well as update the shader code and see the result in real time.

I set three datas to be transmitted by clicking once, and the uniform printed out by Spector also displays three datas. However, in the actual calculation of shader, only one data is transmitted by clicking once, which leads to problems in clicking display.
I don’t know how to solve this problem. I hope to get your help.



Follow this link:

You should not mess with the UniformBuffer._dynamic property, it’s an internal property that is not meant to be modified by external code:

2 Likes

It’s been very helpful.Thank you very much for your help.