Scene / Fog
Fog Class
Environmental fog
Environmental fog is an atmospheric effect that can simulate the rendering of real atmospheric effects such as fog and atmospheric dust, creating a misty atmosphere in the scene.
The property and method in the environment fog are static. Fog can set the environment fog by call directly. Among them, the more commonly used ones are:
enabled The environment fog function can only be used when the static attribute is set to TRUE.
directionalInscatteringColor The static property represents the color of the fog.
density The static attribute represents the density of fog.
startDistance The static property indicates the distance between the fog and the camera.
Table of contents
Accessors
density(): number other |
---|
Get fog density |
directionalInscatteringColor(): LinearColor other |
Obtain the color of sunlight scattering, control the color of directional scattering, which is used to approximate the scattering of sunlight |
directionalInscatteringExponent(): number other |
Obtain the solar scattering index and control the size of the directional scattering cone, which is used to approximate the scattering from sunlight |
directionalInscatteringStartDistance(): number other |
Obtain the initial distance of sunlight scattering, control the initial distance with the directional scattering viewer, and use directional scattering to approximate the scattering of sunlight |
enabled(): boolean other |
Get whether to enable enable |
height(): number other |
Obtain fog height |
heightFalloff(): number other |
Obtain fog attenuation height (control how density increases as height decreases. The smaller the value, the larger the visible transition.) |
inscatteringColor(): LinearColor other |
Obtain fog scattering color |
maxOpacity(): number other |
Get the maximum transparency of the fog (a value of 1 means the fog can become completely opaque at a distance and completely replace the scene color; a value of 0 means the fog color will not be considered at all.) |
startDistance(): number other |
Get fog start distance (distance to camera) |
Methods
setPreset(presetIndex : FogPreset ): void other |
---|
Set fog preset |
Accessors
density
• | • | ||||
---|---|---|---|---|---|
Get fog density Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script called 'FogExample', place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the fog density through the 1 and 2 keys ts
Returns
| Set fog density Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script called 'FogExample', place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the fog density through the 1 and 2 keys ts
Parameters
|
directionalInscatteringColor
• | • | ||||
---|---|---|---|---|---|
Obtain the color of sunlight scattering, control the color of directional scattering, which is used to approximate the scattering of sunlight Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the sunlight scattering color through 1 key ts
Returns
| Set the color of sunlight scattering to control the color of directional scattering, which is used to approximate the scattering of sunlight Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the sunlight scattering color through 1 key ts
Parameters
|
directionalInscatteringExponent
• | • | ||||
---|---|---|---|---|---|
Obtain the solar scattering index and control the size of the directional scattering cone, which is used to approximate the scattering from sunlight Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the solar scattering index through the 1 and 2 keys ts
Returns
| Set the solar light scattering index to control the size of the directional scattering cone, which is used to approximate the scattering of sunlight Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the solar scattering index through the 1 and 2 keys ts
Parameters
|
directionalInscatteringStartDistance
• | • | ||||
---|---|---|---|---|---|
Obtain the initial distance of sunlight scattering, control the initial distance with the directional scattering viewer, and use directional scattering to approximate the scattering of sunlight Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you can control the initial distance of sunlight scattering by pressing 1 and 2 ts
Returns
| Set the initial distance of sunlight scattering to control the initial distance from the directional scattering viewer. Directional scattering is used to approximate the scattering of sunlight Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you can control the initial distance of sunlight scattering by pressing 1 and 2 ts
Parameters
|
enabled
• | • | ||||
---|---|---|---|---|---|
Get whether to enable enable Usage example: You can control the real-time effects of post-processing in the editor as follows. Create a script called 'FogExample', place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the fog on and off with the 1 and 2 keys ts
Returns
| Set whether to enable enable Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you can control the fog on and off by pressing 1 and 2 ts
Parameters
|
height
• | • | ||||
---|---|---|---|---|---|
Obtain fog height Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script called 'FogExample', place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the fog height through the 1 and 2 keys ts
Returns
| Set fog height Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script called 'FogExample', place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the fog height through the 1 and 2 keys ts
Parameters
|
heightFalloff
• | • | ||||
---|---|---|---|---|---|
Obtain fog attenuation height (control how density increases as height decreases. The smaller the value, the larger the visible transition.) Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the fog attenuation height through the 1 and 2 keys ts
Returns
| Set fog attenuation height (controls how density increases as height decreases. The smaller the value, the larger the visible transition.) Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the fog attenuation height through the 1 and 2 keys ts
Parameters
|
inscatteringColor
• | • | ||||
---|---|---|---|---|---|
Obtain fog scattering color Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you can control the fog scattering color through 1 key ts
Returns
| Set fog scattering color Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you can control the fog scattering color through 1 key ts
Parameters
|
maxOpacity
• | • | ||||
---|---|---|---|---|---|
Get the maximum transparency of the fog (a value of 1 means the fog can become completely opaque at a distance and completely replace the scene color; a value of 0 means the fog color will not be considered at all.) Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you can control the maximum transparency of the fog through the 1 and 2 keys ts
Returns
| Set the maximum transparency of the fog (a value of 1 means the fog can become completely opaque at a distance and completely replace the scene color; a value of 0 means the fog color will not be considered at all.) Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you can control the maximum transparency of the fog through the 1 and 2 keys ts
Parameters
|
startDistance
• | • | ||||
---|---|---|---|---|---|
Get fog start distance (distance to camera) Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the fog start distance through the 1 and 2 keys ts
Returns
| Set fog starting distance (distance to camera) Usage example: You can control the real-time effect of post-processing in the editor by following the steps below Create a script named "FogExample", place it in the object bar, open the script, enter the following code, run the game, and you will be able to control the fog start distance through the 1 and 2 keys ts
Parameters
|
Methods
setPreset
• Static
setPreset(presetIndex
): void
other
Set fog preset
Parameters
presetIndex FogPreset | Usage: Fog preset default: null |
---|
Example usage: You can control the editor to post process real-time effects by following these steps to create a script called "FogExample". Place it in the object bar, open the script, enter the following code, run the game, and you will be able to control fog presets with the 1 key
@Component
export default class FogExample extends Script {
// When the script is instantiated, this function will be called before the first frame update
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// Fog preset
Fog.setPreset(FogPreset.NearFog)
});
}
}
}
@Component
export default class FogExample extends Script {
// When the script is instantiated, this function will be called before the first frame update
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// Fog preset
Fog.setPreset(FogPreset.NearFog)
});
}
}
}