Skip to content
Fog

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 ​

• Static get density(): number other

• Static set density(value): void other

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
@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, () => {
                // Increase fog density
                Fog.density += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog density
                Fog.density -= 1;
            });
        }
    }
}
@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, () => {
                // Increase fog density
                Fog.density += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog density
                Fog.density -= 1;
            });
        }
    }
}

Returns ​

numberFog density

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
@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, () => {
                // Increase fog density
                Fog.density += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog density
                Fog.density -= 1;
            });
        }
    }
}
@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, () => {
                // Increase fog density
                Fog.density += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog density
                Fog.density -= 1;
            });
        }
    }
}

Parameters ​

value numberUsage: Fog density

directionalInscatteringColor ​

• Static get directionalInscatteringColor(): LinearColor other

• Static set directionalInscatteringColor(value): void other

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
@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, () => {
                // Sunlight scattering color
                Fog.directionalInscatteringColor = LinearColor.red;
            });
        }
    }
}
@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, () => {
                // Sunlight scattering color
                Fog.directionalInscatteringColor = LinearColor.red;
            });
        }
    }
}

Returns ​

LinearColorSunlight scattering color

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
@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, () => {
                // Sunlight scattering color
                Fog.directionalInscatteringColor = LinearColor.red;
            });
        }
    }
}
@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, () => {
                // Sunlight scattering color
                Fog.directionalInscatteringColor = LinearColor.red;
            });
        }
    }
}

Parameters ​

value LinearColorUsage: Sunlight scattering color

directionalInscatteringExponent ​

• Static get directionalInscatteringExponent(): number other

• Static set directionalInscatteringExponent(value): void other

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
@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, () => {
                // Increase the solar scattering index
                Fog.directionalInscatteringExponent += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the solar scattering index
                Fog.directionalInscatteringExponent -= 0.1;
            });
        }
    }
}
@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, () => {
                // Increase the solar scattering index
                Fog.directionalInscatteringExponent += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the solar scattering index
                Fog.directionalInscatteringExponent -= 0.1;
            });
        }
    }
}

Returns ​

numberSolar scattering index

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
@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, () => {
                // Increase the solar scattering index
                Fog.directionalInscatteringExponent += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the solar scattering index
                Fog.directionalInscatteringExponent -= 0.1;
            });
        }
    }
}
@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, () => {
                // Increase the solar scattering index
                Fog.directionalInscatteringExponent += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the solar scattering index
                Fog.directionalInscatteringExponent -= 0.1;
            });
        }
    }
}

Parameters ​

value numberUsage: Solar Scattering Index

directionalInscatteringStartDistance ​

• Static get directionalInscatteringStartDistance(): number other

• Static set directionalInscatteringStartDistance(value): void 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

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
@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, () => {
                // Increase the initial distance of solar light scattering
                Fog.directionalInscatteringStartDistance += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the initial distance of solar light scattering
                Fog.directionalInscatteringStartDistance -= 0.1;
            });
        }
    }
}
@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, () => {
                // Increase the initial distance of solar light scattering
                Fog.directionalInscatteringStartDistance += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the initial distance of solar light scattering
                Fog.directionalInscatteringStartDistance -= 0.1;
            });
        }
    }
}

Returns ​

numberInitial distance of solar light scattering

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
@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, () => {
                // Increase the initial distance of solar light scattering
                Fog.directionalInscatteringStartDistance += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the initial distance of solar light scattering
                Fog.directionalInscatteringStartDistance -= 0.1;
            });
        }
    }
}
@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, () => {
                // Increase the initial distance of solar light scattering
                Fog.directionalInscatteringStartDistance += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the initial distance of solar light scattering
                Fog.directionalInscatteringStartDistance -= 0.1;
            });
        }
    }
}

Parameters ​

value numberUsage: Initial distance of solar light scattering

enabled ​

• Static get enabled(): boolean other

• Static set enabled(value): void other

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
@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, () => {
                // Activate fog effect
                Fog.enabled = true;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Turn off fog effect
                Fog.enabled = false;
            });
        }
    }
}
@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, () => {
                // Activate fog effect
                Fog.enabled = true;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Turn off fog effect
                Fog.enabled = false;
            });
        }
    }
}

Returns ​

booleanIs it enabled

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
@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, () => {
                // Activate fog effect
                Fog.enabled = true;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Turn off fog effect
                Fog.enabled = false;
            });
        }
    }
}
@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, () => {
                // Activate fog effect
                Fog.enabled = true;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Turn off fog effect
                Fog.enabled = false;
            });
        }
    }
}

Parameters ​

value booleanUsage: Is it enabled

height ​

• Static get height(): number other

• Static set height(value): void other

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
@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, () => {
                // Increase fog height
                Fog.height += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog height
                Fog.height -= 1;
            });
        }
    }
}
@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, () => {
                // Increase fog height
                Fog.height += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog height
                Fog.height -= 1;
            });
        }
    }
}

Returns ​

numberFog height

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
@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, () => {
                // Increase fog height
                Fog.height += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog height
                Fog.height -= 1;
            });
        }
    }
}
@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, () => {
                // Increase fog height
                Fog.height += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog height
                Fog.height -= 1;
            });
        }
    }
}

Parameters ​

value numberUsage: Fog height

heightFalloff ​

• Static get heightFalloff(): number other

• Static set heightFalloff(value): void other

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
@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, () => {
                // Increase fog attenuation height
                Fog.heightFalloff += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog attenuation height
                Fog.heightFalloff -= 1;
            });
        }
    }
}
@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, () => {
                // Increase fog attenuation height
                Fog.heightFalloff += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog attenuation height
                Fog.heightFalloff -= 1;
            });
        }
    }
}

Returns ​

numberFog attenuation height

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
@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, () => {
                // Increase fog attenuation height
                Fog.heightFalloff += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog attenuation height
                Fog.heightFalloff -= 1;
            });
        }
    }
}
@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, () => {
                // Increase fog attenuation height
                Fog.heightFalloff += 1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce fog attenuation height
                Fog.heightFalloff -= 1;
            });
        }
    }
}

Parameters ​

value numberUsage: Fog Weakness Height

inscatteringColor ​

• Static get inscatteringColor(): LinearColor other

• Static set inscatteringColor(value): void other

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
@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, () => {
                // Set fog scattering color
                Fog.inscatteringColor = LinearColor.red;
            });
        }
    }
}
@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, () => {
                // Set fog scattering color
                Fog.inscatteringColor = LinearColor.red;
            });
        }
    }
}

Returns ​

LinearColorMist scattering color

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
@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, () => {
                // Set fog scattering color
                Fog.inscatteringColor = LinearColor.red;
            });
        }
    }
}
@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, () => {
                // Set fog scattering color
                Fog.inscatteringColor = LinearColor.red;
            });
        }
    }
}

Parameters ​

value LinearColorUsage: Mist scattering color

maxOpacity ​

• Static get maxOpacity(): number other

• Static set maxOpacity(value): void 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.)

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
@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, () => {
                // Increase maximum transparency of fog
                Fog.maxOpacity += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce maximum transparency of fog
                Fog.maxOpacity -= 0.1;
            });
        }
    }
}
@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, () => {
                // Increase maximum transparency of fog
                Fog.maxOpacity += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce maximum transparency of fog
                Fog.maxOpacity -= 0.1;
            });
        }
    }
}

Returns ​

numberMaximum transparency of fog

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
@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, () => {
                // Increase maximum transparency of fog
                Fog.maxOpacity += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce maximum transparency of fog
                Fog.maxOpacity -= 0.1;
            });
        }
    }
}
@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, () => {
                // Increase maximum transparency of fog
                Fog.maxOpacity += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce maximum transparency of fog
                Fog.maxOpacity -= 0.1;
            });
        }
    }
}

Parameters ​

value numberUsage: Maximum transparency of fog

startDistance ​

• Static get startDistance(): number other

• Static set startDistance(value): void other

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
@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, () => {
                // Increase the starting distance of fog
                Fog.startDistance += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the starting distance of fog
                Fog.startDistance -= 0.1;
            });
        }
    }
}
@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, () => {
                // Increase the starting distance of fog
                Fog.startDistance += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the starting distance of fog
                Fog.startDistance -= 0.1;
            });
        }
    }
}

Returns ​

numberFog starting distance

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
@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, () => {
                // Increase the starting distance of fog
                Fog.startDistance += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the starting distance of fog
                Fog.startDistance -= 0.1;
            });
        }
    }
}
@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, () => {
                // Increase the starting distance of fog
                Fog.startDistance += 0.1;
            });
            InputUtil.onKeyDown(Keys.Two, () => {
                // Reduce the starting distance of fog
                Fog.startDistance -= 0.1;
            });
        }
    }
}

Parameters ​

value numberUsage: Starting distance of fog

Methods ​

setPreset ​

• Static setPreset(presetIndex): void other

Set fog preset

Parameters ​

presetIndex FogPresetUsage: 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

ts
@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)
            });
        }
    }
}