# Make fog hide emissive mesh

**URL:** <https://forum.babylonjs.com/t/make-fog-hide-emissive-mesh/12054>\
**Category:** Questions\
**Created:** [June 29, 2020, 12:48pm UTC](https://forum.babylonjs.com/t/make-fog-hide-emissive-mesh/12054 "2020-06-29T12:48:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ignite](https://avatars.discourse-cdn.com/v4/letter/i/34f0e0/32.png) [@ignite](https://forum.babylonjs.com/u/ignite)\
**Post date:** [June 29, 2020, 12:48pm UTC](https://forum.babylonjs.com/t/make-fog-hide-emissive-mesh/12054/1 "2020-06-29T12:48:46Z")

</div>

Is it even possible to make a fog hide an emissive mesh? I couldn’t find anything on it.

 ![ss](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/7/73a8ce814a305590f2ca5a680a215e2fbcd2c3a1.jpeg)  
I want the fog to hide the glowing pink ball in this image

---

<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:** [June 29, 2020, 1:01pm UTC](https://forum.babylonjs.com/t/make-fog-hide-emissive-mesh/12054/2 "2020-06-29T13:01:24Z")

</div>

The fog does not take into account the fact that you are emissive or not it should hide it the same as the rest of the meshes. If not, could you create a quick repro in the playground ?

---

<div class="post-metadata">

**Author:** ![ignite](https://avatars.discourse-cdn.com/v4/letter/i/34f0e0/32.png) [@ignite](https://forum.babylonjs.com/u/ignite)\
**Post date:** [June 29, 2020, 1:15pm UTC](https://forum.babylonjs.com/t/make-fog-hide-emissive-mesh/12054/3 "2020-06-29T13:15:40Z")

</div>

Thank you for your quick reply. Here’s the [playground](https://playground.babylonjs.com/#FFUYU3). I believe the problem arises due to my use of glow layer. This playground has the exact fog and sphere settings as in my project.

---

<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:** [June 29, 2020, 1:20pm UTC](https://forum.babylonjs.com/t/make-fog-hide-emissive-mesh/12054/4 "2020-06-29T13:20:53Z")

</div>

ohhhhh yes totaly, the glow layer does not account for fog at all. Is it something you want to contribute ???

Or anybody else from the community ???

It is a nice first time contribution and pretty isolated that I can help somebody to achieve.

Else in 3 days I ll volunteer @PirateJC to do it 🙂 I know he loves to contributes.

---

<div class="post-metadata">

**Author:** ![ignite](https://avatars.discourse-cdn.com/v4/letter/i/34f0e0/32.png) [@ignite](https://forum.babylonjs.com/u/ignite)\
**Post date:** [June 29, 2020, 1:28pm UTC](https://forum.babylonjs.com/t/make-fog-hide-emissive-mesh/12054/6 "2020-06-29T13:28:56Z")

</div>

I would love to do it! This is a great opportunity. I’ve never contributed to a big software project like this before. Thank you!

---

<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:** [June 29, 2020, 3:07pm UTC](https://forum.babylonjs.com/t/make-fog-hide-emissive-mesh/12054/7 "2020-06-29T15:07:49Z")

</div>

The idea would be to add into this effect the fog support: [Babylon.js/effectLayer.ts at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/src/Layers/effectLayer.ts#L536)

It should be a couple of modifications in the shader like this:

1. Add fog declaration include in the vertex shader: [Babylon.js/default.vertex.fx at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/default.vertex.fx#L84)
2. Add fog vertex computation [Babylon.js/default.vertex.fx at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/default.vertex.fx#L270)
3. Add fog declaration include in the vertex shader: [Babylon.js/default.fragment.fx at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/default.fragment.fx#L160)
4. Add fog vertex computation [Babylon.js/default.fragment.fx at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/default.fragment.fx#L456)

And also adding all the required js side code:

1. call into PrepareDefinesForMisc in order to add the required defines in the shader
2. add the 2 new required uniforms in the list of uniforms for the effect creation: “vFogInfos”, “vFogColor”,
3. call to MaterialHelper.BindFogParameters(scene, mesh, effect); in order to bind the required info

At this point the fog should work like in the scene but what you want is the fog to only go from white to black without color for the glow so the last trick would be to force a special color for the bindFogParameters function.

There might be a need for the view matrix as well which is currently not passed in but it is a nice exercise to check those 🙂

---

<div class="post-metadata">

**Author:** ![ignite](https://avatars.discourse-cdn.com/v4/letter/i/34f0e0/32.png) [@ignite](https://forum.babylonjs.com/u/ignite)\
**Post date:** [June 29, 2020, 3:40pm UTC](https://forum.babylonjs.com/t/make-fog-hide-emissive-mesh/12054/8 "2020-06-29T15:40:23Z")

</div>

Alright, I’ll read up on everything and start working soon. I’ll message you in case I encounter any difficulty.
