Add Fog to a Scene
CreatiCode last edited by
Fog is a lighting effect that adds transparent color to objects, and the further away an object is from the camera, the less visible it becomes.
Fog can not only make your scene look more realistic, but also help hide objects far away, which makes it fun for the player to explore your scene.
To add the fog effect, you can use the following block:
There are 2 types of fog you can choose from.
- Linear: The linear range inputs will be used to specify where the fog will start and end based on the distance to the camera. Objects nearer than the “start” distance will not be covered by the fog at all, and objects further away than the “end” distance will be completely covered.
- Exponential: The “density” input will be used to specify the density of the fog based on the distance. All objects will be somewhat covered by the fog color, and the further away they are, the more invisible they become.
This is the color of the fog. You can use a high brightness value for day time fog, and a low brightness for nighttime.
Linear Range - Start and End
These 2 numbers are only used when the fog type is “linear”. Suppose their values are 1000 and 3000. That means:
- Any object within a distance of 1000 to the camera will not be affected by the fog color at all.
- Any object at a distance of 3000 or more will be completely covered up by the fog
- Objects at distances between 1000 and 3000 will gradually become invisible inside this range.
For example, this program adds 3 boxes at distances of about 500/1000/1500 from the camera. When we add a fog that begins at 500 distance and ends at 1500 distance, the nearest box is not affected by the fog at all, while the furthest box becomes hidden.
Density (For Exponential Type of Fog)
When the fog type is “exponential”, the linear range will be ignored, because all objects at all distances will be somewhat covered by the fog color. Instead, the “density” value controls how quickly the density of the fog grows with distance.
Here is a comparison of different density values: