Shader Material

Is there a way of knowing if a shader material is ready? Just that I am creating a rayMarching tool and thus a lot of shader compilations are done. I want to display a message when the current shader is compiling and hide it when not. Used the onCompiled to hide the message. But sometimes I do a hot swap and the shader does not need compiling and therefore doesnt so the message appears but doesn’t go.

I could just add a .compiled=true to the shader material in the onCompiled event and test for that, but am hesitant to modify core code. So just checking if there is any current method?

Additionally this seems to be the case but is just a question. Whenever a new shape is added/removed a new shader is needed in this application. However, is someone adds five shapes quickly in a row it will trigger 5 different shader requests, of which only the last is valid. Does BABYLON still try and compile them all or can it figure out that some are now defunct. If not will have to put something in my code to deal with it. It seems to. But nice to make sure.

For your second question: Babylon.js will run the 5 compilations.

The best way to know if your material is ready is to query material.isReady actually.

Do you want to try to repro your system in the playground so we can see how we can improve it maybe?

Thanks for the info.
Hmm might create a little queueing system then where the shader submits are delayed a bit and if any subsequent request made cancelled, 500ms or so should be alright. That would allow for quick component addition without compiling endless shaders. Could also do a batch button. Where you could add all the objects then submit the shaders creation. Can move them around freely once created as that is parameterised at this stage.

Is there an event that triggers when a compilation starts?

Yep the call to isReay either done manually or when the mesh is queued for rendering

The mesh.onBeforeRenderObservable will be called before compiling the material

Marvelous. That is great. Thanks very much.