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!
Hi,
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.
@Evgeni_Popov
Thank you very much this worked! It even hadn’t a noticable impacted on FPS.
@Pryme8
This sounds interesting but I doubt I have enough knowledge for implementing such a solution
Hello,
I’m digging up this post because I’m having the same problem.
I generate a map of all my ground (in one image) on another camera. But the image generated is in the fog.
If I use what Evgeni_Popov offers, the fog disappears on all my cameras.
this.scene.onBeforeCameraRenderObservable.add(() => {this.scene.fogEnabled = false});
this.scene.onBeforeRenderObservable.add(() => { this.scene.fogEnabled = true});
I tried putting this in a setTimeOut, but same thing. when onBeforeCameraRender and onBeforeRender run the fog disappears on all cameras.
Is there any other solution ?
The only solution I’ve managed is to enable fog after the image is generated. But I don’t find it good, because it surprises when the fog activates in offset from the loading of the scene.
I made a PG here which shows that the fog is disabled on all cameras and not on camera 2
Thanks
I am not sure I understand correctly. Is it in a viewport, one with fog and one without?
Or are you just switching cameras?
I believe you can wait until camera rendering, set the fog first and then set the activeCamera… something like this but i think it creates some sort of a small ‘lag’ waiting for the fog to quick in (it’s not obvious but…)
Edit: Sry, just want up to the post. Is that actually for your minimap?
Hi Mawa,
No, it’s for the world map that I generate on an image. The camera is high enough to see the full terrain (y: 930 or so), but this camera sees fog at this height and renders the image completely foggy.
Currently I deactivate the fog while generating the image then reactivate it when the image is generated. I can’t turn off the fog on camera 2. I have the impression that it’s not possible.
Oh, ok. Meanwhile, took one of your old PGs and made this change
Not sure this can help, but eventually working around layerMasks and reattaching the camera…?
Ok I see. Thanks for the idea.