engine icon indicating copy to clipboard operation
engine copied to clipboard

Changing opacity of transparent material forces shader recompilation

Open lucaheft opened this issue 11 months ago • 6 comments

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

  1. Launch https://playcanvas.com/project/1200988/overview/bug-shader-generation
  2. After a delay of 2 seconds the cube fades in and out
  3. Shader of material TransparentRed is generated a second time
  4. Shader generation is logged to console

lucaheft avatar Mar 18 '24 15:03 lucaheft