# HDRI scene.background turns black when camera layer changed

**URL:** <https://discourse.threejs.org/t/hdri-scene-background-turns-black-when-camera-layer-changed/35129>\
**Category:** Questions\
**Tags:** loaders, camera, materials, textures\
**Created:** [February 21, 2022, 6:28pm UTC](https://discourse.threejs.org/t/hdri-scene-background-turns-black-when-camera-layer-changed/35129 "2022-02-21T18:28:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadman\_Yasar\_Sayem](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/sadman_yasar_sayem/32/24425_2.png) [@Sadman\_Yasar\_Sayem](https://discourse.threejs.org/u/Sadman_Yasar_Sayem)\
**Post date:** [February 21, 2022, 6:28pm UTC](https://discourse.threejs.org/t/hdri-scene-background-turns-black-when-camera-layer-changed/35129/1 "2022-02-21T18:28:41Z")

</div>

This is the code I used to load HDRI  
Full code: [GitHub - SadmanYasar/3D-Car-Viewer](https://github.com/SadmanYasar/3D-Car-Viewer)

```javascript
new RGBELoader()
    .load('textures/autoshop_01_2k.hdr', (texture: Texture) => {
      texture.mapping = EquirectangularReflectionMapping;

      // background remains same if color used instead of texture
      scene.background = texture;
      scene.environment = texture;

      texture.dispose();

      // load models asynchronously
      const loader = new GLTFLoader();

      loader
        .loadAsync(url)
        .then((gltf) => {
          gltf.scene.traverse((object) => {
            object.layers.set(layer);
          });

          scene.add(gltf.scene);
        });
    });

```

Initially the models and HDRI load fine but when I change camera layer, the models for that layer load but the scene background becomes black. I tried console logging scene.background when the layer changed but found no difference between the results. This issue is occurring after I started using Typescript and Webpack on this project. What could be done to solve this issue?

---

<div class="post-metadata">

**Author:** ![mayyar](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mayyar](https://discourse.threejs.org/u/mayyar)\
**Post date:** [February 21, 2022, 6:38pm UTC](https://discourse.threejs.org/t/hdri-scene-background-turns-black-when-camera-layer-changed/35129/2 "2022-02-21T18:38:03Z")

</div>

Hey  
In your render function try first to set camera layer 0  
Load hdri  
Change the camera layer

---

<div class="post-metadata">

**Author:** ![Sadman\_Yasar\_Sayem](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/sadman_yasar_sayem/32/24425_2.png) [@Sadman\_Yasar\_Sayem](https://discourse.threejs.org/u/Sadman_Yasar_Sayem)\
**Post date:** [February 21, 2022, 6:43pm UTC](https://discourse.threejs.org/t/hdri-scene-background-turns-black-when-camera-layer-changed/35129/3 "2022-02-21T18:43:20Z")

</div>

> [@mayyar](#):
>
> Hey  
> In your render function try first to set camera layer 0  
> Load hdri  
> Change the camera layer

I did it after initializing the camera but still it does not work ☹  
But when I set scene.background to a hex color, the background remains same when I change layers.

---

<div class="post-metadata">

**Author:** ![mayyar](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mayyar](https://discourse.threejs.org/u/mayyar)\
**Post date:** [February 21, 2022, 6:53pm UTC](https://discourse.threejs.org/t/hdri-scene-background-turns-black-when-camera-layer-changed/35129/4 "2022-02-21T18:53:51Z")

</div>

I mean chang it in each frame  
In this path  
Camera with layer0  
Set th hdri  
Camera with layer 1
