- Home /
Other / OP posted solution.
Custom Terrain shader - shader property doesn't update realtime
I'm using a custom terrain material (Unity 5.1.2) that has shader that is based on the built-in Standard terrain shader. I have a custom property that I'm setting each frame. It seems that the value of that property is only assigned once and changing it later on has no effect. I've played around and noticed that the only way to change the property (terrain.templateMaterial.SetMatrix("myMatrix", something) ) is to set the terrain custom material to null at the beginning of the frame and re-apply the material on LateUpdate or something like that. This solves the problem but the performance drops significantly due to reassigning of the material.
Does anyone know why this is happening? I can recall that in the past (Unity 4.x) there was no such problem.
UPDATE:
Even weirder! If the properties that you're setting each frame are matrices (terrain.templateMaterial.SetMatrix(...)) then changes don't get picked. BUT, if you also set a Float (terrain.templateMaterial.SetFloat(...)) then the matrix values AND the float values start getting picked up every frame.
So to anyone who stumbles uppon this: you can fix this issue by defining some random float property in your shader and setting to some random value each frame.