I got tired of manually setting my material opacities to 0.999 (annoying if you are fading an entire object and it has a lot of materials). I also just never liked the idea that a fully opaque material was being rendered as being a tiny bit transparent. So I just check to see if the material opacity is undefined or not. If it is, I set it to 0.999999 using material.update(), and then set it back to its initial value with setParameter(). That establishes the shader chunk for the material’s transparency and I can just use setParameter() from this point forward for any other opacity changes.
The opacity intensity of the material is set to 1 and it’s not altered anywhere in the script prior to setParameter, yet it works just fine. Why is that?
Hmm, actually it doesn’t work against the latest engine build. When launched from editor it doesn’t fade in/out for me.
The main reason for having to change a default parameter on a material channel, is to force the engine to include a shader program part (chunk) to the final compiled shader. So you can easily update a uniform using setParameter, without having to recompile the shader, using material.update().
Shouldn’t that chunk inclusion be determined from blend mode or something instead? It feels really silly to have to have slightly transparent materials if you want to alter opacity from code. Or is it supposed to be a feature or is it a bug? At least the example should be updated as it doesn’t work now.