Disable fog for 2nd camera

Hi community,
I’ve implemented a minimap by using a 2nd camera which shows the top-down view on the play-field of my game. Now I noticed that if fog is enabled for the scene, the 2nd camera is also affected by the fog. This is basically not what I want, so is there a way to disable fog for a camera?
Thanks in advance!


You can try to add an observer on onBeforeCameraRenderObservable:

scene.onBeforeCameraRenderObservable.add(() => scene.fogEnabled = false);

So you will also need:

scene.onBeforeRenderObservable.add(() => scene.fogEnabled = true);

Note however that it will retrigger all material reevaluation each time, because the fog setting impacts the generation of the shader code itself.

So you should check that it does not impair too much your fps by doing so.

What about calculating the fog through a post effect and screen space depth?

Then it effectively is not there and neither camera “sees” it but you would be over laying it.

Thank you very much this worked! It even hadn’t a noticable impacted on FPS.
This sounds interesting but I doubt I have enough knowledge for implementing such a solution :slight_smile: