+4 votes

I'm interested in simulating 3D fog using shaders, but the problem is that I have no clue on where the shader script should be; from my understanding, Shader scripts on 3D scenes are only available in materials. In which type of node this material should be? Can it be a Sprite3D node with the color I'll set as fog?

On a side-note, I tried using a GlobalEnvironment node to create the fog effect, but for some reason the distances limitations weren't enough for the game I'm creating.

in Engine by (299 points)
retagged by

Can't you just scale down your whole game for your world staying in the limited area?

I don't have experience with shaders, but I found it relatively easy to find a shader I like on shadertoy.com, and convert the code from there in Godot code. The conversion is not difficult but rather tedious.

Isn't the fog effect built-in with the WorldEnvironment? (it's a distance-correct one btw, which is nice)
What kind of distances your game has? Are you working in meters?

I'm new so forgive me if this sounds silly. Is it possible to add a shader to viewport? That probably doesn't help. What about particle emitter?

Thanks for all the replies!
@Timoshwarzer: I tried scaling the game to match the WorldEnvironment fog, but that wasn't working too. I'm not too sure how WorldEvironment fog even work; the game is on my GitHub account, if you want to check it out: https://github.com/henriquelalves/simple_dungeon_demo

@MrMonk: Thanks, I'll check it out! I'm still unsure on where I should put the script, thought, haha.

@Zylann: Well, I'm working on normal "Godot units", which in Blender should be a meter each. But I tested changing the scale of the game and the distance of the fog on the WorldEnvironment node, and now I'm just confused on how does it work. If you want to check it out, the game is on my GitHub: https://github.com/henriquelalves/simple_dungeon_demo

@CraftyManiac: I didn't thought on using viewports, actually; apparently I can add an Environment property to the viewport itself, so maybe I can use this to create the fog Effect that I want. A particle emitter probably wouldn't work, because the shader would be on each particle material (I guess, I'm not even sure on this one haha).

I kind of meant instead of using a shader you can use a particle emitter. Maybe it can be attached to the viewport or player camera.

@CraftyManiac
I just tested this idea and its actually working! Fortunately there are a lot of Particle Emitter characteristics that I can play around to actually have the effect that I have in mind, so thanks a lot man! The only thing that I'm worried about is how processing heavy is it, and I'm still curious if there is a way to do it as a shader, haha.

EDIT: I think I found a problem; apparently, particles don't follow the particle emitter transformation - so when you change the camera fast, you will see the fog being created at a distance.

EDIT.2: Aaaand there is an option to use the local coordinates, hahaha. I'll explore more of this option before I say anything else.

Did you write a bug report on GitHub regarding the fog in the WorldEnvironment? I tried to set it up correctly and it does seem broken indeed.

Tried with the Platformer 3D demo (which has a dim fog enabled), if you set the attenuation low, you will get a more dense fog, but don't know if is the kind of fog you want.

1 Answer

0 votes

Check this link out not sure if this info will help since it's not Godot related. But it is however shader related. Sorry I can't be of more help I'm super new to game dev. Messed around with unity and unreal for a bit. I really enjoy the process of game dev. It's like a difficult puzzle. More enjoyable than playing most games.

by (30 points)

Didn't mean to put this as an answer. On mobile at the moment.

Hahaha, no worries. We were commenting possible solutions to the fog on the comment section above, but I'm still looking for a shader answer.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.