# Fade in and out on camera switch

**URL:** <https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561>\
**Category:** Questions\
**Created:** [August 20, 2020, 10:49pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561 "2020-08-20T22:49:33Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![simran\_jain](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@simran\_jain](https://forum.babylonjs.com/u/simran_jain)\
**Post date:** [August 20, 2020, 10:49pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/1 "2020-08-20T22:49:33Z")

</div>

I have 2 different camera, I want to animation switching scene something like screen fades in and out showing new camera’s target. What would be the most effective and simple way of doing it?

---

<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 21, 2020, 9:21am UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/2 "2020-08-21T09:21:04Z")

</div>

See [this PG](https://playground.babylonjs.com/#QUM4H3) from [this thread](https://forum.babylonjs.com/t/fade-in-and-fade-out-between-vr-scenes/7593/2) to fade out/in to/from black.

You can also use a post process, as said in the thread.

---

<div class="post-metadata">

**Author:** ![simran\_jain](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@simran\_jain](https://forum.babylonjs.com/u/simran_jain)\
**Post date:** [August 21, 2020, 1:39pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/5 "2020-08-21T13:39:31Z")

</div>

I tried this, my meshes have emissive texture and colours so its not working. Do we have something else I can use?

---

<div class="post-metadata">

**Author:** ![Robin\_McLaut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/robin_mclaut/32/5503_2.png) [@Robin\_McLaut](https://forum.babylonjs.com/u/Robin_McLaut)\
**Post date:** [August 21, 2020, 1:43pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/6 "2020-08-21T13:43:34Z")

</div>

Had a similar issue with PBR Materials (which ignore Lights) and a GlowLayer (which ignores everything, even the fogDensity)

I do:

- fade the fogDensity of scene 1 from X to 10 (or any other high amount) and the intensity of the glowLayer to 0
- fade the fogDensity of scene 2 from 10 to X and the intensity of the glowLayer to X

---

<div class="post-metadata">

**Author:** ![simran\_jain](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@simran\_jain](https://forum.babylonjs.com/u/simran_jain)\
**Post date:** [August 21, 2020, 1:50pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/7 "2020-08-21T13:50:25Z")

</div>

What if I am using only one scene when I am switching? also is the postProcess is easy to use?

---

<div class="post-metadata">

**Author:** ![Robin\_McLaut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/robin_mclaut/32/5503_2.png) [@Robin\_McLaut](https://forum.babylonjs.com/u/Robin_McLaut)\
**Post date:** [August 21, 2020, 1:53pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/8 "2020-08-21T13:53:06Z")

</div>

Using the fogDensity can be a tool for one or more scenes. Also it has a nice “reveal” effect, just try it.  
PostProcessing would be another way to solve this I guess. Requires additional shaders tho. I first tried the Vignette Shader but it did not work to hide the whole screen properly.

---

<div class="post-metadata">

**Author:** ![simran\_jain](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@simran\_jain](https://forum.babylonjs.com/u/simran_jain)\
**Post date:** [August 21, 2020, 2:01pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/9 "2020-08-21T14:01:55Z")

</div>

I see, Is it possible to share any PG example so I can have a look, I am doing scene.fogDensity = 10; but its not working.

---

<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 21, 2020, 2:06pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/10 "2020-08-21T14:06:12Z")

</div>

If you want to do it with a post process, you can take example on the ascii art post process:

PG: [https://www.babylonjs-playground.com/#2I28SC#3](https://www.babylonjs-playground.com/#2I28SC#3)  
Doc: [Using the Ascii Art post-process - Babylon.js Documentation](https://doc.babylonjs.com/extensions/asciiartpostprocess)  
Code: [Babylon.js/asciiArtPostProcess.ts at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/postProcessLibrary/src/asciiArt/asciiArtPostProcess.ts)

---

<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 21, 2020, 2:12pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/11 "2020-08-21T14:12:52Z")

</div>

You can also use the NME:

PG: [Babylon.js Playground](https://www.babylonjs-playground.com/#QY6FRP)  
Material: [https://nme.babylonjs.com/#PV60TY#1](https://nme.babylonjs.com/#PV60TY#1)

---

<div class="post-metadata">

**Author:** ![Robin\_McLaut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/robin_mclaut/32/5503_2.png) [@Robin\_McLaut](https://forum.babylonjs.com/u/Robin_McLaut)\
**Post date:** [August 21, 2020, 2:18pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/12 "2020-08-21T14:18:21Z")

</div>

[https://playground.babylonjs.com/#QYFDDP#433](https://playground.babylonjs.com/#QYFDDP#433)

You’ll need something like a Skybox (or another mesh, that also get’s affected by the fog) around your scenery

---

<div class="post-metadata">

**Author:** ![simran\_jain](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@simran\_jain](https://forum.babylonjs.com/u/simran_jain)\
**Post date:** [August 21, 2020, 3:23pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/14 "2020-08-21T15:23:08Z")

</div>

@Evgeni_Popov Thank you so much, I would try methods you suggested if the fog idea does’t work properly. Thanks. 😊

---

<div class="post-metadata">

**Author:** ![simran\_jain](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@simran\_jain](https://forum.babylonjs.com/u/simran_jain)\
**Post date:** [August 21, 2020, 6:56pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/16 "2020-08-21T18:56:59Z")

</div>

@Robin_McLaut Is their way to not use Math.sin and use something else, Because I just need this fade in and out effect once. Currently I just did scene.fogDensity = 8, and its like just going black, I want it to give some fade in effect. 😅

---

<div class="post-metadata">

**Author:** ![Robin\_McLaut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/robin_mclaut/32/5503_2.png) [@Robin\_McLaut](https://forum.babylonjs.com/u/Robin_McLaut)\
**Post date:** [August 24, 2020, 6:57am UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/17 "2020-08-24T06:57:20Z")

</div>

Hey, this is just an example. Use whatever animation method you want to. I use animejs and sometimes GSAP for animations in my projects.  
Babylon has it’s own animation possibilities, but I’ve never used them

---

<div class="post-metadata">

**Author:** ![simran\_jain](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@simran\_jain](https://forum.babylonjs.com/u/simran_jain)\
**Post date:** [August 24, 2020, 1:20pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/18 "2020-08-24T13:20:18Z")

</div>

@Robin_McLaut Can you please share one example with fade in and out once, I am doing fade in by change the fogDensity to 8 and using setTimeout to make fogDensity 0 again. But I want a little slow to make it fade in and out. I am stuck here, not sure how to do that. I am searching online but it would a great help you would just share an example?

---

<div class="post-metadata">

**Author:** ![Robin\_McLaut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/robin_mclaut/32/5503_2.png) [@Robin\_McLaut](https://forum.babylonjs.com/u/Robin_McLaut)\
**Post date:** [August 24, 2020, 2:10pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/19 "2020-08-24T14:10:30Z")

</div>

I don’t know what kind of libraries you use besides BabylonJS.  
As an example, if you use [GitHub - juliangarnier/anime: JavaScript animation engine](https://github.com/juliangarnier/anime/) AnimeJS this would be quite simple:

```
anime(SCENE, { fogDensity: [0, 8], duration: 5000, easing: 'easeOutQuad' });

```

if you want to do something when it’s done, anime provides callbacks

```
anime(SCENE, { fogDensity: [0, 8], duration: 5000, easing: 'easeOutQuad', complete: function () { /* do something here */ });
```

---

<div class="post-metadata">

**Author:** ![simran\_jain](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@simran\_jain](https://forum.babylonjs.com/u/simran_jain)\
**Post date:** [September 4, 2020, 5:01pm UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/20 "2020-09-04T17:01:25Z")

</div>

Thank you it worked, Very sorry for very late response.

---

<div class="post-metadata">

**Author:** ![jamessimo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jamessimo/32/26847_2.png) [@jamessimo](https://forum.babylonjs.com/u/jamessimo)\
**Post date:** [April 22, 2023, 5:33am UTC](https://forum.babylonjs.com/t/fade-in-and-out-on-camera-switch/13561/21 "2023-04-22T05:33:23Z")

</div>

Wouldn’t it be possible to edit those values just using the built-in Babylon JS animate methods?

I’m really looking for a way to fade the camera in and out using built-in Babylon functions because then I can have a on complete call back.

I like the Fog Idea but isn’t that quite expensive computationally if the scene is quite busy?
