450% worse performance when setting environmentIntensity

This is something I only noticed because I have 360hz monitor.
Replication of this is pretty easy but I can provide sample if anybody does not observe the same behavior. Babylon version: Babylon.js v5.0.0-beta.9 - WebGL2 - Parallel shader compilation

I’m loading an .hdr file with HDRCubeTexture, and loading a glb file and adding to the scene.
According to the performance monitor my total frame time is 3.50ms. My total frame time climbs to 17.3ms if I set environmentIntensity to anything except 1 (the default).

I go from 240-280FPS to under 60FPS frame rate while environmentIntensity is set. I should note that I tried this on a few other machines without high refresh rate, and it’s not as noticeable. Despite the performance impact the framerate is still around the native refresh. It’s still slower, but far less apparent.

The envmap intensity does appear to change as expected, but surely this massive performance impact isn’t intentional.

Nope seems definitely like a bug :frowning: can you spot the culprit in the perf analyzer ? I would like to fox it ASAP

I tried to repro without any luck, and the code is so straightforward I can not understand how this would happen :frowning: Could you create a repro in the playground ? just in case

The playground is a little slower to render than our app is for whatever reason but the effect of the envmapIntensity is still very visible.

Give it a shot here: https://playground.babylonjs.com/#PKMN0Q#2
Comment out line 28 and watch FPS tank.

In case this is relevant: I asked a few people to test this with Nvidia / Intel GPU and seems to impact both. That being said, the initial FPS is lower on Intel integrated GPU so the difference isn’t quite as apparent.

Okay so I noticed one thing in the trace that’s different for sure. After setting envmapIntensity it looks like this markAllMaterialsAsDirty is occuring every frame.

I’m not a babylonjs expert so I may be looking for the wrong things here, but I’m not seeing this happen unless envmapIntensity is being set.

Yup I am on it it is so strange and definitely a bug

I was surprised to see this behavior too. I’m very glad we were testing performance after adding each line because I would never have expected this to have such a massive impact.

Pushing a fix in 30 min you ll see the why there :slight_smile:

The fix is here Fix env intensity perf + axes vectors by sebavan · Pull Request #12025 · BabylonJS/Babylon.js · GitHub

Basically we were flagging as dirty without reason on intensity change and The Gltf transmission is toggling it from its value to 1 between every render causing a ton of unnecessary overhead

4 Likes