Global Fog
The global fog currently includes four types: Linear Fog, Exponential Fog, Exponential Squared Fog, and Layer Fog, please refer to the Global Fog Types section below for additional details.
Check Scene in the Hierarchy panel, then check the Enabled property in the Fog component of the Inspector panel to enable global fog.
Prior to v3.4, Creator used vertex fog by default, which caused unusual fog transitions on objects with a few vertices and a large volume. Starting with v3.4, Creator added the Accurate option to enable pixel fog to solve this problem.
The effect when the Accurate option is unchecked, i.e., the pixel fog is not enabled, is as follows:
The effect when the Accurate option is checked, i.e., the pixel fog is enabled, is as follows:
The original code is as follows:
After upgrading to v3.4, the original code needs to be changed to the following:
The types of global fog include Linear Fog, Exponential Fog, Exponential Squared Fog, and Layer Fog. The type depends on the calculation result of Camera and Model Vertex, which is called Fog Blend Factor. The fog blend factor determines how the fog color and the model color are blended, resulting in a different global fog effect.
The fog blend factor of Linear Fog is calculated by the formula:
f = (FogEnd - Cam_dis) / (FogEnd - FogStart)
When
Cam_dis = FogEnd
, i.e., the distance between the camera and the model vertex is equal to , the blend factor is calculated as 0, and the object is fully fogged.When
Cam_dis = FogStart
, i.e. the distance between the camera and the model vertex is equal toFogStart
, the blend factor is calculated as 1, and the object is not affected by fogging.
To increase the density of Linear Fog when the distance between the camera and the model vertex is fixed, there are two ways:
- Fix the value of
FogStart
and decrease the value ofFogEnd
. - Decrease the value of
FogStart
and fix the value of .
The properties of Exponential Fog and Exponential Squared Fog are the same, and the Exponential Fog is used here as an example:
The fog blend factor for Exponential Fog is calculated as:
f = e^(-max(0, distance-fogStart) * fogDensity)
The fog blend factor for Exponential Squared Fog is calculated as:
f = e^(-max(0, distance-fogStart) * fogDensity)²
Developers can adjust the distribution of global fog in the near and far distance with FogStart
, and the fog concentration at different locations with FogDensity
and FogAtten
.
Layered Fog is parallel to the horizontal plane and has a specific height. The height of the fog can be determined by setting the top of the Layered Fog at any position in the vertical direction of the scene world coordinate system.
Layered Fog is more common in reality, with towering mountains and buildings. If it is used wisely, it is believed to have a good effect on scene presentation, but at the same time, the computation will be increased, developers can decide according to their needs.