Make fog hide emissive mesh

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


I want the fog to hide the glowing pink ball in this image

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 ?

Thank you for your quick reply. Here’s the playground. 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.

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 :slight_smile: I know he loves to contributes.

2 Likes

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!

The idea would be to add into this effect the fog support: Babylon.js/effectLayer.ts at master · BabylonJS/Babylon.js · GitHub

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
  2. Add fog vertex computation Babylon.js/default.vertex.fx at master · BabylonJS/Babylon.js · GitHub
  3. Add fog declaration include in the vertex shader: Babylon.js/default.fragment.fx at master · BabylonJS/Babylon.js · GitHub
  4. Add fog vertex computation Babylon.js/default.fragment.fx at master · BabylonJS/Babylon.js · GitHub

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 :slight_smile:

2 Likes

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

2 Likes