How to create a 3D Fog effect using shaders?

Hey guys,
I posted this same question on the Godot Q&A, but I didn't have a decisive answer; since Godot Facebook group is getting crowded (and somewhat messy too), I thought on posting here.

Thing is, from my understanding, the only way to apply Shaders on a 3D environment is by the use of materials; I'm completely clueless on how to apply this sort of Shader as other implementations I found online. I would have to get information on 3D distances and stuff, and I didn't found any documentation regarding that on the Godot Shader page. Is there a way to do it?

BTW, I tried using the WorldEnvironment node to no success. Maybe the way I set it up is wrong, but another user reported it looked broken ( The project that I want to apply this in is a 3D Dungeon Crawler demo, you can check it out on my GitHub:


  • MegalomaniakMegalomaniak Posts: 227Member

    Typically done with depth buffer in screen-space, there should indeed be a simple to enable feature for fog in the WorldEnvironment, though I too find it a bit awkward to use. I have however gotten it to work before, just can't recall what I did for that off the top of my head.

  • henriquelalveshenriquelalves Posts: 2Member

    I'll copy paste here the answer that I got from Kokemohr on Facebook; maybe this will also be useful to other devs:

    "I had another look at your project and now I can tell you a little more. There are quite a few caveats in the current implementation, I'd even say it's buggy, but this is how you can work around it. If someone else has more insight on how fog works in Godot 2.1.1 and notices mistakes in my comment I'd appreciate them to correct me.

    • Fog doesn't work with Ambient Light. Use directional lights instead.
    • Fog always goes from the value entered under Environment -> Fog -> Begin to the far clip distance. So if your far clip distance is too large you won't see much of the fog. Also if your begin distance is greater than the far clip distance everything will be behind 100% fog.
    • Fog doesn't work with Sprites that don't have a material on them. Apply a FixedMaterial in "material override". The "unshaded" flag in that material may not be set or the fog will be disabled for the object.

    There seems to be at least one other issue since the sprites for the floor and the ceiling (which was upside down by the way) seem to be affected stronger than the walls. My first theory was that the distance to the object was factored in in some way but if I move the player to the center of the map the effect is the same."

Sign In or Register to comment.