Files
godot-demo-projects/3d/volumetric_fog/volumetric_fog.tscn
Hugo Locurcio c423f3bfc6 Improve volumetric fog demo (#1014)
- Add fog shader example courtesy of alghost
  (https://godotshaders.com/shader/moving-gradient-noise-fog-mist-for-godot-4/).
- Add textured floor to make volumetric fog easier to see.
- Add keys to adjust volumetric fog quality (higher values are sharper).
- Increase volumetric fog energy on one of the SpotLights to show
  the difference.
2024-02-01 17:30:35 +01:00

426 lines
15 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
[gd_scene load_steps=26 format=3 uid="uid://d1d6jy84lcpg7"]
[ext_resource type="Script" path="res://camera.gd" id="1_mfjvp"]
[ext_resource type="CompressedTexture3D" uid="uid://bpvy0e34otmhk" path="res://icon_outlined.png" id="2_8fjmj"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_fefkn"]
sky_top_color = Color(0.568627, 0.698039, 0.807843, 1)
sky_horizon_color = Color(0.672549, 0.704902, 0.734314, 1)
ground_bottom_color = Color(0.121569, 0.121569, 0.129412, 1)
ground_horizon_color = Color(0.672549, 0.704902, 0.734314, 1)
[sub_resource type="Sky" id="Sky_5gwha"]
sky_material = SubResource("ProceduralSkyMaterial_fefkn")
[sub_resource type="Environment" id="Environment_gsgar"]
background_mode = 2
sky = SubResource("Sky_5gwha")
tonemap_mode = 2
glow_enabled = true
volumetric_fog_enabled = true
[sub_resource type="Gradient" id="Gradient_cqs75"]
offsets = PackedFloat32Array(0, 0.313433, 1)
colors = PackedColorArray(0, 0, 0, 1, 0.473976, 0.473976, 0.473976, 1, 1, 1, 1, 1)
[sub_resource type="FastNoiseLite" id="FastNoiseLite_cjmew"]
frequency = 0.005
fractal_type = 2
fractal_octaves = 4
fractal_lacunarity = 3.0
fractal_gain = 2.0
fractal_weighted_strength = 0.4
domain_warp_enabled = true
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_6pkhb"]
seamless = true
as_normal_map = true
bump_strength = 0.5
color_ramp = SubResource("Gradient_cqs75")
noise = SubResource("FastNoiseLite_cjmew")
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_8w53i"]
seamless = true
color_ramp = SubResource("Gradient_cqs75")
noise = SubResource("FastNoiseLite_cjmew")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_qrpkj"]
albedo_color = Color(0, 0, 0, 1)
roughness_texture = SubResource("NoiseTexture2D_8w53i")
normal_enabled = true
normal_texture = SubResource("NoiseTexture2D_6pkhb")
uv1_scale = Vector3(0.25, 0.25, 0.25)
uv1_triplanar = true
texture_filter = 5
[sub_resource type="FogMaterial" id="FogMaterial_sfd8y"]
density = -1.6842
[sub_resource type="FogMaterial" id="FogMaterial_v1f5u"]
density = 0.2
emission = Color(0, 1, 0.501961, 1)
edge_fade = 2.2779e-05
[sub_resource type="FogMaterial" id="FogMaterial_16tep"]
density = 0.2
emission = Color(0.980392, 0.164706, 1, 1)
edge_fade = 2.2779e-05
[sub_resource type="FogMaterial" id="FogMaterial_blauf"]
density = 0.2
emission = Color(0, 1, 0.501961, 1)
height_falloff = 1e+06
edge_fade = 2.2779e-05
[sub_resource type="FogMaterial" id="FogMaterial_yvnd5"]
density = 0.3
emission = Color(1, 0.290196, 0.419608, 1)
[sub_resource type="FogMaterial" id="FogMaterial_gcgmm"]
density = 0.3
emission = Color(1, 0.290196, 0.419608, 1)
height_falloff = 1e+06
[sub_resource type="FogMaterial" id="FogMaterial_8xcc6"]
density = 0.1
albedo = Color(1, 15, 10, 1)
[sub_resource type="Animation" id="Animation_jg7qq"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("MovingBox:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector3(0, 2, 10)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("MovingBox:rotation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector3(0, 0, 0)]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("MovingBox:scale")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector3(1, 1, 1)]
}
[sub_resource type="Animation" id="Animation_axnf8"]
resource_name = "move_fog_volume"
length = 10.0
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("MovingBox:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 3, 6),
"transitions": PackedFloat32Array(-2, -2, -2),
"update": 0,
"values": [Vector3(0, 2, 10), Vector3(-5.20189, 2, 12.7464), Vector3(-0.764091, 6.11944, 20.2665)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("MovingBox:rotation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 3, 6),
"transitions": PackedFloat32Array(-2, -2, -2),
"update": 0,
"values": [Vector3(0, 0, 0), Vector3(0, 0.784368, 0), Vector3(-0.33128, 0.307663, 0.797063)]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("MovingBox:scale")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0, 3, 6),
"transitions": PackedFloat32Array(-2, -2, -2),
"update": 0,
"values": [Vector3(1, 1, 1), Vector3(1, 1, 1), Vector3(3, 3, 3)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_avffy"]
_data = {
"RESET": SubResource("Animation_jg7qq"),
"move_fog_volume": SubResource("Animation_axnf8")
}
[sub_resource type="BoxMesh" id="BoxMesh_fi43t"]
[sub_resource type="FogMaterial" id="FogMaterial_ktn3i"]
albedo = Color(0, 0, 4, 1)
edge_fade = 0.0
[sub_resource type="FogMaterial" id="FogMaterial_yomn8"]
density = 2.0
emission = Color(0, 0.501961, 1, 1)
edge_fade = 0.0
density_texture = ExtResource("2_8fjmj")
[sub_resource type="Shader" id="Shader_1xpcs"]
code = "shader_type fog;
/* main fog shader */
uniform float base_density: hint_range(0, 1) = 0.8;
uniform vec3 base_color: source_color;
uniform float fade_out_height = 2.0;
uniform float fade_out_distance = 1.5;
uniform vec3 noise_amounts = vec3(0.4, 0.35, 0.25); // should add up to 1
uniform vec3 noise_scales = vec3(1.0, 2.0, 4.0);
uniform vec3 noise_velocity1 = vec3(0.5, 0.0, 0.0);
uniform vec3 noise_velocity2 = vec3(1, 0.0, -1);
uniform vec3 noise_velocity3 = vec3(0.0, 0.6, 0.3);
/* gradient_noise_3d.gdshaderinc */
// The MIT License
// Copyright © 2013 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// All noise functions here:
//
// https://www.shadertoy.com/playlist/fXlXzf&from=0&num=12
vec3 hash(vec3 p) {
p = vec3(dot(p,vec3(127.1,311.7, 74.7)),
dot(p,vec3(269.5,183.3,246.1)),
dot(p,vec3(113.5,271.9,124.6)));
return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);
}
// 3D gradient noise function
float noise(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = f*f*(3.0-2.0*f);
return mix( mix( mix( dot( hash( i + vec3(0.0,0.0,0.0) ), f - vec3(0.0,0.0,0.0) ),
dot( hash( i + vec3(1.0,0.0,0.0) ), f - vec3(1.0,0.0,0.0) ), u.x),
mix( dot( hash( i + vec3(0.0,1.0,0.0) ), f - vec3(0.0,1.0,0.0) ),
dot( hash( i + vec3(1.0,1.0,0.0) ), f - vec3(1.0,1.0,0.0) ), u.x), u.y),
mix( mix( dot( hash( i + vec3(0.0,0.0,1.0) ), f - vec3(0.0,0.0,1.0) ),
dot( hash( i + vec3(1.0,0.0,1.0) ), f - vec3(1.0,0.0,1.0) ), u.x),
mix( dot( hash( i + vec3(0.0,1.0,1.0) ), f - vec3(0.0,1.0,1.0) ),
dot( hash( i + vec3(1.0,1.0,1.0) ), f - vec3(1.0,1.0,1.0) ), u.x), u.y), u.z );
}
void fog() {
vec3 base_pos = WORLD_POSITION * vec3(0.1, 0.5, 0.1);
DENSITY = base_density;
float noise1 = noise(base_pos * noise_scales.x + TIME * noise_velocity1) * noise_amounts.x;
float noise2 = noise(base_pos * noise_scales.y + TIME * noise_velocity2) * noise_amounts.y;
float noise3 = noise(base_pos * noise_scales.z + TIME * noise_velocity3) * noise_amounts.z;
DENSITY *= smoothstep(-0.1, 0.0, noise1 + noise2 + noise3);
DENSITY *= 1.0 - smoothstep(fade_out_height, fade_out_height + fade_out_distance, WORLD_POSITION.y);
ALBEDO = base_color;
}"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_481nw"]
shader = SubResource("Shader_1xpcs")
shader_parameter/base_density = 1.0
shader_parameter/base_color = Color(1, 0, 0, 1)
shader_parameter/fade_out_height = 0.0
shader_parameter/fade_out_distance = 8.0
shader_parameter/noise_amounts = Vector3(0.4, 0.35, 0.25)
shader_parameter/noise_scales = Vector3(1, 2, 4)
shader_parameter/noise_velocity1 = Vector3(0.5, 0, 0)
shader_parameter/noise_velocity2 = Vector3(1, 0, -1)
shader_parameter/noise_velocity3 = Vector3(0, 0.6, 0.3)
[node name="Node3D" type="Node3D"]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_gsgar")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.592126, -0.697883, 0.402923, -1.19487e-09, 0.5, 0.866026, -0.805846, 0.512796, -0.296063, 0, 0, 0)
shadow_enabled = true
shadow_bias = 0.04
shadow_blur = 1.5
directional_shadow_max_distance = 60.0
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -8, 6, 18)
fov = 74.0
script = ExtResource("1_mfjvp")
[node name="Label" type="Label" parent="Camera3D"]
offset_left = 16.0
offset_top = 16.0
offset_right = 812.0
offset_bottom = 299.0
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
theme_override_constants/outline_size = 4
text = "Fog density: 0.05
Temporal reprojection: Disabled
Volumetric fog quality: 64×64×64"
[node name="HelpLabel" type="Label" parent="Camera3D"]
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 16.0
offset_top = -120.0
offset_right = 909.0
offset_bottom = -16.0
grow_vertical = 0
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
theme_override_constants/outline_size = 4
text = "W/A/S/D/Mouse: Move
Left/Right arrows: Adjust global fog density
Space: Toggle temporal reprojection
Up/Down arrows or mouse wheel: Adjust temporal reprojection intensity
Page Up/Down: Adjust volumetric fog quality"
[node name="Ground" type="CSGBox3D" parent="."]
size = Vector3(1024, 1.99, 1024)
material = SubResource("StandardMaterial3D_qrpkj")
[node name="Ground2" type="CSGBox3D" parent="Ground"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10.282, 0, 5.62229)
operation = 2
size = Vector3(3, 2, 4)
material = SubResource("StandardMaterial3D_qrpkj")
[node name="Ground3" type="CSGBox3D" parent="Ground"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7.87312, 0, 2.69763)
operation = 2
size = Vector3(3, 2, 4)
material = SubResource("StandardMaterial3D_qrpkj")
[node name="CSGBox3D" type="CSGBox3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5, 0)
size = Vector3(8, 8, 8)
material = SubResource("StandardMaterial3D_qrpkj")
[node name="CSGBox3D" type="CSGBox3D" parent="CSGBox3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.4)
operation = 2
size = Vector3(7.5, 7.5, 7.5)
material = SubResource("StandardMaterial3D_qrpkj")
[node name="FogVolumeNegativeDensity" type="FogVolume" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5, 0)
size = Vector3(8, 8, 8)
material = SubResource("FogMaterial_sfd8y")
[node name="FogVolumeEllipsoid" type="FogVolume" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -13, 6, 6)
size = Vector3(4, 4, 4)
shape = 0
material = SubResource("FogMaterial_v1f5u")
[node name="FogVolumeCone" type="FogVolume" parent="."]
transform = Transform3D(-1, 8.74228e-08, 0, -8.74228e-08, -1, 0, 0, 0, 1, -12, 2, 12)
size = Vector3(4, 4, 4)
shape = 1
material = SubResource("FogMaterial_16tep")
[node name="FogVolumeCylinder" type="FogVolume" parent="."]
transform = Transform3D(-1, 8.74228e-08, 0, -8.74228e-08, -1, 0, 0, 0, 1, -12, 3, 17)
size = Vector3(4, 4, 4)
shape = 2
material = SubResource("FogMaterial_16tep")
[node name="FogVolumeEllipsoidHeightFalloff" type="FogVolume" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -13, 6, 2)
size = Vector3(4, 4, 4)
shape = 0
material = SubResource("FogMaterial_blauf")
[node name="FogVolumeBox" type="FogVolume" parent="."]
transform = Transform3D(0.707107, 0.5, -0.5, 0, 0.707107, 0.707107, 0.707107, -0.5, 0.5, -7.5189, 4.42465, -2.97368)
size = Vector3(4, 4, 4)
material = SubResource("FogMaterial_yvnd5")
[node name="FogVolumeBoxHeightFalloff" type="FogVolume" parent="."]
transform = Transform3D(0.707107, 0.5, -0.5, 0, 0.707107, 0.707107, 0.707107, -0.5, 0.5, -7.5189, 4.42465, -7.97368)
size = Vector3(4, 4, 4)
material = SubResource("FogMaterial_gcgmm")
[node name="OmniLight3D" type="OmniLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.823152, 1.836, 4.31818)
light_color = Color(1, 0.929412, 0, 1)
light_energy = 2.0
omni_range = 6.0
[node name="OmniLight3DHighVolumetricEnergy" type="OmniLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.67463, 1.836, -4.89264)
light_color = Color(1, 0.337255, 0, 1)
light_energy = 0.1
light_volumetric_fog_energy = 500.0
light_specular = 0.0
omni_range = 3.0
[node name="OmniLight3DShadow" type="OmniLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.82315, 1.836, 4.31818)
light_color = Color(1, 0.929412, 0, 1)
light_energy = 2.0
shadow_enabled = true
omni_range = 6.0
[node name="SpotLight3D" type="SpotLight3D" parent="."]
transform = Transform3D(0.966384, -0.226045, -0.1225, 0, 0.476461, -0.879196, 0.257105, 0.84964, 0.460444, -9.82684, -3.7099, 4.88511)
light_color = Color(0, 0.439216, 1, 1)
light_energy = 4.0
light_volumetric_fog_energy = 25.0
spot_angle = 35.0
[node name="FogVolumeAlbedoTweak" type="FogVolume" parent="."]
transform = Transform3D(-0.89393, -0.0897075, -0.439138, 0, 0.979766, -0.200148, 0.448207, -0.178918, -0.875842, -15.8913, -15.118, 8.26876)
size = Vector3(8, 8, 8)
material = SubResource("FogMaterial_8xcc6")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_avffy")
}
autoplay = "move_fog_volume"
[node name="MovingBox" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 10)
mesh = SubResource("BoxMesh_fi43t")
[node name="FogVolumeBlue" type="FogVolume" parent="MovingBox"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0)
material = SubResource("FogMaterial_ktn3i")
[node name="FogVolumeTexture3D" type="FogVolume" parent="."]
transform = Transform3D(-2.98023e-08, 4.82913e-08, -1, -4.2222e-08, -1, -4.82913e-08, -1, 4.2222e-08, -1.49012e-08, 17, 17, 12)
size = Vector3(32, 32, 4)
material = SubResource("FogMaterial_yomn8")
[node name="FogVolumeShader" type="FogVolume" parent="."]
transform = Transform3D(-2.98023e-08, 4.82913e-08, -1, -4.2222e-08, -1, -4.82913e-08, -1, 4.2222e-08, -1.49012e-08, -34.4124, 5, 12)
size = Vector3(32, 8, 32)
material = SubResource("ShaderMaterial_481nw")