Fog Shader

Fog shader for characters with a moving camera. With adjustments for color, density, speed, and pulse.

The fog follows the camera’s movement but remains fixed in the world.

 

A colorrect within a parallax layer within a parallax background.

Make the colorect twice the size of your resolution and set the same size to the parallax layer’s mirroring.

Add the shader and a noisetexture with opensimplynoise

Godot 3

Shader code
shader_type canvas_item;

uniform sampler2D noise_texture : hint_albedo;
uniform vec4 fog_color : hint_color = vec4(0.9, 0.7, 0.3, 1.0);
uniform float density : hint_range(0.0, 1.0) = 0.25;
uniform float speed_x : hint_range(-1.0, 1.0) = 0.02;
uniform float speed_y : hint_range(-1.0, 1.0) = 0.01;
uniform float pulse_speed : hint_range(0.01, 5.0) = 0.5;

void fragment() {
	vec2 speed = vec2(speed_x, speed_y);
	vec2 uv = UV + speed * TIME;
	float noise = texture(noise_texture, uv).r;
	float local_time = TIME * pulse_speed + noise * 20.0;
	float pulse = 0.5 + 0.5 * sin(local_time);
	float shape = smoothstep(0.3, 1.0, noise);
	float fog = shape * pulse;
	COLOR = vec4(fog_color.rgb, fog * density * fog_color.a);}
Live Preview
Tags
Fog, godot 3, theruinedhouse
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments