# Physically based scene with dark skybox

**URL:** <https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777>\
**Category:** Questions\
**Tags:** material, pbr\
**Created:** [August 3, 2021, 3:58pm UTC](https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777 "2021-08-03T15:58:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ladevieq](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ladevieq/32/11077_2.png) [@ladevieq](https://forum.babylonjs.com/u/ladevieq)\
**Post date:** [August 3, 2021, 3:58pm UTC](https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777/1 "2021-08-03T15:58:23Z")

</div>

Hello BabylonJS folks

I’m setting up a fully PBR scene, all materials are PBR ones, i use physical light units and falloff, aswell as physical exposure computations based on ISO, aperture and shutter speed.

It looks great, and seems physically correct. Unfortunately the old StandardMaterial skybox is really dark, almost black, due to the exposure computations.

I changed the reflection texture to use a HDR one, with the idea that if the luminance stored in the HDR is the same as in a real life scene, it would behave correctly, but the skybox remains almost black.

So i was wondering were is my mistake, did my assumption about a HDR with real life luminance value is false, did i load it in correctly, or maybe the texture values in Babylon are automatically remapped to [0; 1] range.

I would like to bring a playground to show you what it looks like, but in order to make things physically correct i had to remove the `clamp(finalcolor.rgb, 0.0, 30.0)` done in `pbrBlockImageProcessing.fragment.fx. This part of the shader totally breaks the luminance values received by the camera. Otherwise is there a way to ignore this part of the shader ?

Thanks in advance

---

<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:** [August 3, 2021, 5:03pm UTC](https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777/2 "2021-08-03T17:03:48Z")

</div>

Why not using a PBRMaterial on the skybox ?

---

<div class="post-metadata">

**Author:** ![ladevieq](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ladevieq/32/11077_2.png) [@ladevieq](https://forum.babylonjs.com/u/ladevieq)\
**Post date:** [August 4, 2021, 8:23am UTC](https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777/3 "2021-08-04T08:23:05Z")

</div>

I just tried with a `.dds`, a `.env` and a `.hdr` as reflection textures for a PBRMaterial and the result is the same. The scene looks correctly exposed, but the skybox looks like it’s night time.

This is what i get

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/f/b/fb51a734e404e0c62ab42af0c0dfcea107a97082.jpeg)

And here what the skybox is supposed to look like

> **[Noon Grass HDRI • Poly Haven](https://polyhaven.com/a/noon_grass)**
>
> Download this free HDRI from Poly Haven

Maybe i load those textures incorrectly

`new BABYLON.CubeTexture(url, scene, undefined, false, undefined, resolve, reject, undefined, undefined, undefined, false, 1.0, 0.0, undefined, true);`

`BABYLON.CubeTexture.CreateFromPrefilteredData(url, scene);`

`new BABYLON.HDRCubeTexture(url, scene, 1024, false, true, undefined, true, resolve);`

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [August 4, 2021, 9:44am UTC](https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777/4 "2021-08-04T09:44:04Z")

</div>

The 3rd one should work with a .hdr file.

If you could setup a repro in the Playground it would help a lot.

---

<div class="post-metadata">

**Author:** ![ladevieq](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ladevieq/32/11077_2.png) [@ladevieq](https://forum.babylonjs.com/u/ladevieq)\
**Post date:** [August 4, 2021, 10:07am UTC](https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777/5 "2021-08-04T10:07:00Z")

</div>

> I would like to bring a playground to show you what it looks like, but in order to make things physically correct i had to remove the `clamp(finalcolor.rgb, 0.0, 30.0)` done in `pbrBlockImageProcessing.fragment.fx. This part of the shader totally breaks the luminance values received by the camera. Otherwise is there a way to ignore this part of the shader ?

---

<div class="post-metadata">

**Author:** ![Vinc3r](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/vinc3r/32/25340_2.png) [@Vinc3r](https://forum.babylonjs.com/u/Vinc3r)\
**Post date:** [August 4, 2021, 10:12am UTC](https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777/6 "2021-08-04T10:12:16Z")

</div>

Have you tried to simply disableLighting in your skybox standardMaterial? In this playground it works: [Babylon.js Playground](https://playground.babylonjs.com/#ALSR53) (line 18)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [August 4, 2021, 10:44am UTC](https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777/7 "2021-08-04T10:44:41Z")

</div>

You can overwrite the **pbrBlockImageProcessing** shader block:

```javascript
BABYLON.Effect.IncludesShadersStore['pbrBlockImageProcessing'] = `
#if defined(IMAGEPROCESSINGPOSTPROCESS) || defined(SS_SCATTERING)
    // Sanitize output incase invalid normals or tangents have caused div by 0 or undefined behavior
    // this also limits the brightness which helpfully reduces over-sparkling in bloom (native handles this in the bloom blur shader)
    //
    // Subsurface scattering also requires to stay in linear space
    //finalColor.rgb = clamp(finalColor.rgb, 0., 30.0);
#else
    // Alway run to ensure we are going back to gamma space.
    finalColor = applyImageProcessing(finalColor);
#endif

    finalColor.a *= visibility;

#ifdef PREMULTIPLYALPHA
    // Convert to associative (premultiplied) format if needed.
    finalColor.rgb *= finalColor.a;
#endif
`;

```

---

<div class="post-metadata">

**Author:** ![ladevieq](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ladevieq/32/11077_2.png) [@ladevieq](https://forum.babylonjs.com/u/ladevieq)\
**Post date:** [August 4, 2021, 1:13pm UTC](https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777/8 "2021-08-04T13:13:36Z")

</div>

Thank you, i’m gonna setup a repro asap.

---

<div class="post-metadata">

**Author:** ![ladevieq](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ladevieq/32/11077_2.png) [@ladevieq](https://forum.babylonjs.com/u/ladevieq)\
**Post date:** [August 5, 2021, 7:45am UTC](https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777/9 "2021-08-05T07:45:15Z")

</div>

Here is a playground : [https://playground.babylonjs.com/#DG842Q#16](https://playground.babylonjs.com/#DG842Q#16)

You can choose between two hemispherical lights emitting 20k lux (see [this](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@7.1/manual/Physical-Light-Units.html#indoor) for my source on the sky/sun intensity), and an HDR/env texture to do image based lighting.

1. The light emitted by the textures is not powerfull enough compared to the hemi lights.

2. The skybox is darkenned as the values present in the textures are not real luminance values, so the exposure darken it a lot.

---

<div class="post-metadata">

**Author:** ![ladevieq](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ladevieq/32/11077_2.png) [@ladevieq](https://forum.babylonjs.com/u/ladevieq)\
**Post date:** [August 5, 2021, 8:18am UTC](https://forum.babylonjs.com/t/physically-based-scene-with-dark-skybox/22777/10 "2021-08-05T08:18:02Z")

</div>

Ok i think i got it. I am just extremely stupid. In a HDR, env or dds texture, the luminance values are already post processed (rexposed, tonemapped, …).  
So in order to have absolute luminance values, i have to invert the transformations done by the camera that captured the textures. In my case setting the `environmentIntensity` to maxLuminance works well.
