☑ Customizing standard shader / changing fshader property

I’m trying to customize a standard shader by inserting specific instructions into material.shader.definition.fshader string. Turns out, even though the string is successfully patched, the material doesn’t implement the new shader, even with material.update() or material.setShader() being called. What should I do?

You can create own shader new pc.Shader and patch it. then attach it to material.shader, and call material.update.
If you want totally custom shader, then I suggest making BasicMaterial and overriding updateShader method.
If you need to change only some behaviour of StandardMaterial, then it is better to use chunks of a material, and change them. There are some topics around forum on how to change chunks.

Thanks max, I’ve already solved my issue by using material.chunks.

But still, before that I’ve been trying to create a new shader with attributes of the old one, and with patched vshader and fshader programs. Then I was calling material.setShader() and material.update(), to no avail. Seems like a bug?

I think StandardShader on update will always generate own shader and ignore custom ones.
If you want to have custom shader, don’t use StandardMaterial.

Ok I see, thanks.
Seems like using chunks is the only reasonable way.

It is a way to extend and modify existing material system, that is respecting lights and many other scene related things.
But if you need something totally bespoke, then BasicMaterial with overwrite of updateShader is the way to go.

There is always many options :slight_smile:

1 Like