engine
engine copied to clipboard
Changing opacity of transparent material forces shader recompilation
Description
When changing the opacity intensity of a material which was initially set to 1, to some smaller value a shader recomplication is forced.
This seems to happen because MAPFLOAT isn't defined when the intensity is set to 1. Technically this is correct, because multiplying by 1 doesn't change the ouput. However this introduces micro stutter for the first time the transparent material is faded.
I advocate for always including the intensity in the shader code. As the advantages farly outweigh the disadvantage.
The same applies for emissive intensity and probably a few others.
Pros
- Fewer shader variants
- No additional shader compilation
Cons:
- Additional multiplication in shader
Steps to Reproduce
- Launch https://playcanvas.com/project/1200988/overview/bug-shader-generation
- After a delay of 2 seconds the cube fades in and out
- Shader of material
TransparentRed
is generated a second time - Shader generation is logged to console