Notification of shader recompilation ?

Hi !

Is there a way to be notified a material’s shader was recompiled ?

I mean, such an event would be the ideal place to setup shader constants that don’t change across the entire shader and need to be uploaded only once.
Instead, I have to upload these constants every frame, which kind of sucks…

That makes the user write 2 scenarios : one for debug mode where the shaders get recompiled often and another one for release mode where the shader gets compiled only once, too bad.

You’re talking about saving on things like renderer.material.SetFloat("_Shininess", shininess);?

I thought constants needed to be sent every frame no matter what. Sure, the shader code is stored in the graphics card, but it doesn’t have a spot where it stores the uniform variables (specSize = 12 … .) Those are stored in the CPU, with the material. Since the specular shader, say, is used by lots of materials, remembering the most recent GPU setting for specSize wouldn’t be useful.

The only way you should be able to set a GPU constant once is if whatever register happens to never get overridden by any other shader, like when materials are batched.

I was talking more about texture uploads, not simple parameters that change per-instance…

Imagine the case where a material uses a texture as a precomputated table : that texture never changes for any instance of the material and needs to be uploaded only once and stay in video memory.

Any decent driver has a cache that allows to keep textures in video memory without having to upload them everytime. I don’t know how Unity processes the “material.SetTexture()” cases but I seriously hope that calling “SetTexture()” every frame doesn’t upload my texture again everytime, although it didn’t change from the last frame (hence my request to post the “SetTexture()” only once, when the shader gets recompiled)