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

Welcome to the forum!

Regarding your PG, try this:

https://www.babylonjs-playground.com/#RBVU6M#3

You need to update the uniform at the right time: onBeforeDraw is the very last callback before calling OpenGL drawing, so it seems to fit the bill.

To modify existing material shaders without messing with the shader store, you can try CustomMaterial and PBRCustomMaterial from the material library.

Some docs here: Babylon.js/materialsLibrary/src/custom at master · BabylonJS/Babylon.js · GitHub

They seem not up to date (for eg SelectVersion does not exist), but it should get you started.