# 450% worse performance when setting environmentIntensity

**URL:** <https://forum.babylonjs.com/t/450-worse-performance-when-setting-environmentintensity/27867>\
**Category:** Bugs\
**Created:** [February 21, 2022, 11:56pm UTC](https://forum.babylonjs.com/t/450-worse-performance-when-setting-environmentintensity/27867 "2022-02-21T23:56:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nowayz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nowayz/32/26674_2.png) [@Nowayz](https://forum.babylonjs.com/u/Nowayz)\
**Post date:** [February 21, 2022, 11:56pm UTC](https://forum.babylonjs.com/t/450-worse-performance-when-setting-environmentintensity/27867/1 "2022-02-21T23:56:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 22, 2022, 11:10am UTC](https://forum.babylonjs.com/t/450-worse-performance-when-setting-environmentintensity/27867/2 "2022-02-22T11:10:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 22, 2022, 2:04pm UTC](https://forum.babylonjs.com/t/450-worse-performance-when-setting-environmentintensity/27867/3 "2022-02-22T14:04:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nowayz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nowayz/32/26674_2.png) [@Nowayz](https://forum.babylonjs.com/u/Nowayz)\
**Post date:** [February 22, 2022, 6:14pm UTC](https://forum.babylonjs.com/t/450-worse-performance-when-setting-environmentintensity/27867/4 "2022-02-22T18:14:03Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Nowayz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nowayz/32/26674_2.png) [@Nowayz](https://forum.babylonjs.com/u/Nowayz)\
**Post date:** [February 22, 2022, 6:34pm UTC](https://forum.babylonjs.com/t/450-worse-performance-when-setting-environmentintensity/27867/5 "2022-02-22T18:34:58Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/e/4e5bb113b29c7d1f6f2b35392644cb9775daf77c.png)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 22, 2022, 6:43pm UTC](https://forum.babylonjs.com/t/450-worse-performance-when-setting-environmentintensity/27867/6 "2022-02-22T18:43:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nowayz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nowayz/32/26674_2.png) [@Nowayz](https://forum.babylonjs.com/u/Nowayz)\
**Post date:** [February 22, 2022, 7:17pm UTC](https://forum.babylonjs.com/t/450-worse-performance-when-setting-environmentintensity/27867/7 "2022-02-22T19:17:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 22, 2022, 7:32pm UTC](https://forum.babylonjs.com/t/450-worse-performance-when-setting-environmentintensity/27867/8 "2022-02-22T19:32:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [February 22, 2022, 7:38pm UTC](https://forum.babylonjs.com/t/450-worse-performance-when-setting-environmentintensity/27867/9 "2022-02-22T19:38:52Z")

</div>

The fix is here [Fix env intensity perf + axes vectors by sebavan · Pull Request #12025 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/pull/12025/files#diff-aaa03e8b4cbd33903d9c974800fabdd6e385ded90bc08c2ccacdbbbf8354ac95L213)

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
