Skip to content

Commit 1a96d82

Browse files
committed
Add Distance and Atmospheric Fog support (#6412)
<img width="1392" alt="image" src="https://user-images.githubusercontent.com/418473/203873533-44c029af-13b7-4740-8ea3-af96bd5867c9.png"> <img width="1392" alt="image" src="https://user-images.githubusercontent.com/418473/203873549-36be7a23-b341-42a2-8a9f-ceea8ac7a2b8.png"> # Objective - Add support for the “classic” distance fog effect, as well as a more advanced atmospheric fog effect. ## Solution This PR: - Introduces a new `FogSettings` component that controls distance fog per-camera. - Adds support for three widely used “traditional” fog falloff modes: `Linear`, `Exponential` and `ExponentialSquared`, as well as a more advanced `Atmospheric` fog; - Adds support for directional light influence over fog color; - Extracts fog via `ExtractComponent`, then uses a prepare system that sets up a new dynamic uniform struct (`Fog`), similar to other mesh view types; - Renders fog in PBR material shader, as a final adjustment to the `output_color`, after PBR is computed (but before tone mapping); - Adds a new `StandardMaterial` flag to enable fog; (`fog_enabled`) - Adds convenience methods for easier artistic control when creating non-linear fog types; - Adds documentation around fog. --- ## Changelog ### Added - Added support for distance-based fog effects for PBR materials, controllable per-camera via the new `FogSettings` component; - Added `FogFalloff` enum for selecting between three widely used “traditional” fog falloff modes: `Linear`, `Exponential` and `ExponentialSquared`, as well as a more advanced `Atmospheric` fog;
1 parent adae877 commit 1a96d82

File tree

18 files changed

+1439
-15
lines changed

18 files changed

+1439
-15
lines changed

Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,26 @@ description = "A scene showcasing the built-in 3D shapes"
297297
category = "3D Rendering"
298298
wasm = true
299299

300+
[[example]]
301+
name = "atmospheric_fog"
302+
path = "examples/3d/atmospheric_fog.rs"
303+
304+
[package.metadata.example.atmospheric_fog]
305+
name = "Atmospheric Fog"
306+
description = "A scene showcasing the atmospheric fog effect"
307+
category = "3D Rendering"
308+
wasm = true
309+
310+
[[example]]
311+
name = "fog"
312+
path = "examples/3d/fog.rs"
313+
314+
[package.metadata.example.fog]
315+
name = "Fog"
316+
description = "A scene showcasing the distance fog effect"
317+
category = "3D Rendering"
318+
wasm = true
319+
300320
[[example]]
301321
name = "blend_modes"
302322
path = "examples/3d/blend_modes.rs"

assets/models/terrain/Mountains.bin

280 KB
Binary file not shown.

assets/models/terrain/Mountains.gltf

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
{
2+
"asset" : {
3+
"generator" : "Khronos glTF Blender I/O v3.3.17",
4+
"version" : "2.0"
5+
},
6+
"extensionsUsed" : [
7+
"KHR_materials_specular",
8+
"KHR_materials_ior"
9+
],
10+
"scene" : 0,
11+
"scenes" : [
12+
{
13+
"name" : "Scene",
14+
"nodes" : [
15+
0,
16+
1
17+
]
18+
}
19+
],
20+
"nodes" : [
21+
{
22+
"mesh" : 0,
23+
"name" : "Grid"
24+
},
25+
{
26+
"mesh" : 0,
27+
"name" : "Grid.001",
28+
"translation" : [
29+
0.0018983177142217755,
30+
-2.7217100068810396e-05,
31+
0.0012765892315655947
32+
]
33+
}
34+
],
35+
"materials" : [
36+
{
37+
"doubleSided" : true,
38+
"extensions" : {
39+
"KHR_materials_specular" : {
40+
"specularColorFactor" : [
41+
0,
42+
0,
43+
0
44+
]
45+
},
46+
"KHR_materials_ior" : {
47+
"ior" : 1.4500000476837158
48+
}
49+
},
50+
"name" : "Material.001",
51+
"pbrMetallicRoughness" : {
52+
"baseColorFactor" : [
53+
0.12338346652686596,
54+
0.35653680562973022,
55+
0.065849664583802223,
56+
1
57+
],
58+
"metallicFactor" : 0,
59+
"roughnessFactor" : 0.9980237483978271
60+
}
61+
}
62+
],
63+
"meshes" : [
64+
{
65+
"name" : "Grid",
66+
"primitives" : [
67+
{
68+
"attributes" : {
69+
"POSITION" : 0,
70+
"NORMAL" : 1,
71+
"TEXCOORD_0" : 2
72+
},
73+
"indices" : 3,
74+
"material" : 0
75+
}
76+
]
77+
}
78+
],
79+
"accessors" : [
80+
{
81+
"bufferView" : 0,
82+
"componentType" : 5126,
83+
"count" : 6561,
84+
"max" : [
85+
1.0000003576278687,
86+
0.2493455857038498,
87+
1.0051095485687256
88+
],
89+
"min" : [
90+
-1.0000003576278687,
91+
-0.08555418252944946,
92+
-1.0000003576278687
93+
],
94+
"type" : "VEC3"
95+
},
96+
{
97+
"bufferView" : 1,
98+
"componentType" : 5126,
99+
"count" : 6561,
100+
"type" : "VEC3"
101+
},
102+
{
103+
"bufferView" : 2,
104+
"componentType" : 5126,
105+
"count" : 6561,
106+
"type" : "VEC2"
107+
},
108+
{
109+
"bufferView" : 3,
110+
"componentType" : 5123,
111+
"count" : 38400,
112+
"type" : "SCALAR"
113+
}
114+
],
115+
"bufferViews" : [
116+
{
117+
"buffer" : 0,
118+
"byteLength" : 78732,
119+
"byteOffset" : 0
120+
},
121+
{
122+
"buffer" : 0,
123+
"byteLength" : 78732,
124+
"byteOffset" : 78732
125+
},
126+
{
127+
"buffer" : 0,
128+
"byteLength" : 52488,
129+
"byteOffset" : 157464
130+
},
131+
{
132+
"buffer" : 0,
133+
"byteLength" : 76800,
134+
"byteOffset" : 209952
135+
}
136+
],
137+
"buffers" : [
138+
{
139+
"byteLength" : 286752,
140+
"uri" : "Mountains.bin"
141+
}
142+
]
143+
}

0 commit comments

Comments
 (0)