Use sky as fog color

MirceaKitsuneMirceaKitsune Posts: 43Member
in 3D

I was wondering if there's a way to make the fog color blend to the world / sky background. Any fog color and brightness I choose stand out against the sky, which is especially a problem since I'm using fog to cut the draw distance which looks bad:

Best Answer

Answers

  • MegalomaniakMegalomaniak Posts: 2,645Admin

    You could attach a script to your worldenvironment and control the color values of the sky backround and the fog color from there. Using the same color should probably get you what you are after?

  • MirceaKitsuneMirceaKitsune Posts: 43Member

    @Megalomaniak said:
    You could attach a script to your worldenvironment and control the color values of the sky backround and the fog color from there. Using the same color should probably get you what you are after?

    It would definitely be better. If I'm going that route I may as well make the ground color of the sky the same as the sky itself, then just set the fog to that. I was hoping I could instead use the fog as an alpha blend so it fades what it covers to transparency... kinda sounds like a nice feature for Godot 4.0 to have.

  • TwistedTwiglegTwistedTwigleg Posts: 2,655Admin

    If you want, you can make a proposal on the Godot Proposal repository, so it can (potentially) be included in Godot 4.0 :smile:

  • SIsilicon28SIsilicon28 Posts: 714Moderator

    What you have proposed sounds like an awesome idea! I've always wondered why most game engines haven't tried to do that. They usually just use one solid color instead of mixing the color with the background.

  • CalinouCalinou Posts: 417Admin Godot Developer

    This is technically possible, see an Unity shader which does it here: https://github.com/keijiro/KinoFog

  • MirceaKitsuneMirceaKitsune Posts: 43Member

    Posted a request on the tracker for this, thanks for that suggestion!

    https://github.com/godotengine/godot-proposals/issues/999

  • cyberealitycybereality Posts: 927Moderator

    I think this is possible. I wrote some code for grabbing the pixel color of the sky. I think you could use a variation of this, but pass the whole texture to a shader and then use the SCREEN_UV to grab the sky pixel color and add fog based on that. I haven't tried it, but it might be worth a look.
    https://godotforums.org/discussion/comment/38646#Comment_38646

  • mziskandarmziskandar Posts: 3Member
    Accepted Answer

    Hello. Try this on your camera.

  • SIsilicon28SIsilicon28 Posts: 714Moderator

    How will that achieve the effect they're looking for? They're asking for fog to blend with the sky colour, which won't always be a solid colour.

  • mziskandarmziskandar Posts: 3Member

  • MirceaKitsuneMirceaKitsune Posts: 43Member

    @mziskandar said:

    That looks exactly like what I was looking for! So I simply set the sky on the camera instead of the world to get those extra controls?

  • mziskandarmziskandar Posts: 3Member

    @MirceaKitsune said:

    @mziskandar said:

    That looks exactly like what I was looking for! So I simply set the sky on the camera instead of the world to get those extra controls?

    Sky horizon, ground bottom color, ground horizon color = fog color
    visibility range or camera clip end = fog end

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file