Creating fog around the player

I try to get a circle around the player of what the player can see. Everything outside that circle must disappear into the dark. Since fog works from the position of the camera and my game is a third person game, I try to come up with an alternative.

At first I did this with a spotlight above the player, which made other objects invisible due to the lack of light. However, this only works if I use materials without Emessive and leave Gamma & Tonemap disabled. This does not give a nice result on the textures that I use on the material.

That is why I wonder if anyone knows the correct settings of the material for this, or has a better idea.

That’s an interesting problem. I imagine there are ways to fake it with semi transparent objects, though using fog would be the most realistic way of doingthis.

I think you could potentially override the default Playcanvas material shaders for fog, to use the character world position, instead of the camera. I haven’t tried it myself but I would be curious what the end visual result would be.

Hi @Leonidas! I think this is indeed the best way if that is possible. Where can I find the shader that is used for fog and how do I override the default shader for fog? I like to give it a try.

I think it’s not a single shader chunk, check the full list for fog params to find the affect shader parts:

To override any shader chunk check this example:

Though that means overriding all these for each affected material, take note.

Oops. I am afraid this is beyond my capabilities.
I see an uniform float fog_start, but I don’t see where or how this is set.

I’d say start with getting some experience on how to override a single material shader and do together some GLSL shader tutorials. Those will get you comfortable on writing shader code.