Skip to content

Commit

Permalink
Add Distance and Atmospheric Fog support (bevyengine#6412)
Browse files Browse the repository at this point in the history
<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;
  • Loading branch information
coreh authored and ItsDoot committed Feb 1, 2023
1 parent e0754b3 commit 98234dd
Show file tree
Hide file tree
Showing 18 changed files with 1,439 additions and 15 deletions.
20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,26 @@ description = "A scene showcasing the built-in 3D shapes"
category = "3D Rendering"
wasm = true

[[example]]
name = "atmospheric_fog"
path = "examples/3d/atmospheric_fog.rs"

[package.metadata.example.atmospheric_fog]
name = "Atmospheric Fog"
description = "A scene showcasing the atmospheric fog effect"
category = "3D Rendering"
wasm = true

[[example]]
name = "fog"
path = "examples/3d/fog.rs"

[package.metadata.example.fog]
name = "Fog"
description = "A scene showcasing the distance fog effect"
category = "3D Rendering"
wasm = true

[[example]]
name = "blend_modes"
path = "examples/3d/blend_modes.rs"
Expand Down
Binary file added assets/models/terrain/Mountains.bin
Binary file not shown.
143 changes: 143 additions & 0 deletions assets/models/terrain/Mountains.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"asset" : {
"generator" : "Khronos glTF Blender I/O v3.3.17",
"version" : "2.0"
},
"extensionsUsed" : [
"KHR_materials_specular",
"KHR_materials_ior"
],
"scene" : 0,
"scenes" : [
{
"name" : "Scene",
"nodes" : [
0,
1
]
}
],
"nodes" : [
{
"mesh" : 0,
"name" : "Grid"
},
{
"mesh" : 0,
"name" : "Grid.001",
"translation" : [
0.0018983177142217755,
-2.7217100068810396e-05,
0.0012765892315655947
]
}
],
"materials" : [
{
"doubleSided" : true,
"extensions" : {
"KHR_materials_specular" : {
"specularColorFactor" : [
0,
0,
0
]
},
"KHR_materials_ior" : {
"ior" : 1.4500000476837158
}
},
"name" : "Material.001",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.12338346652686596,
0.35653680562973022,
0.065849664583802223,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.9980237483978271
}
}
],
"meshes" : [
{
"name" : "Grid",
"primitives" : [
{
"attributes" : {
"POSITION" : 0,
"NORMAL" : 1,
"TEXCOORD_0" : 2
},
"indices" : 3,
"material" : 0
}
]
}
],
"accessors" : [
{
"bufferView" : 0,
"componentType" : 5126,
"count" : 6561,
"max" : [
1.0000003576278687,
0.2493455857038498,
1.0051095485687256
],
"min" : [
-1.0000003576278687,
-0.08555418252944946,
-1.0000003576278687
],
"type" : "VEC3"
},
{
"bufferView" : 1,
"componentType" : 5126,
"count" : 6561,
"type" : "VEC3"
},
{
"bufferView" : 2,
"componentType" : 5126,
"count" : 6561,
"type" : "VEC2"
},
{
"bufferView" : 3,
"componentType" : 5123,
"count" : 38400,
"type" : "SCALAR"
}
],
"bufferViews" : [
{
"buffer" : 0,
"byteLength" : 78732,
"byteOffset" : 0
},
{
"buffer" : 0,
"byteLength" : 78732,
"byteOffset" : 78732
},
{
"buffer" : 0,
"byteLength" : 52488,
"byteOffset" : 157464
},
{
"buffer" : 0,
"byteLength" : 76800,
"byteOffset" : 209952
}
],
"buffers" : [
{
"byteLength" : 286752,
"uri" : "Mountains.bin"
}
]
}

0 comments on commit 98234dd

Please sign in to comment.