Linear Fog
Task
Enhance a scene rendered using deferred shading by adding a linear fog effect. The fog should start at a distance of 8.0 units from the camera and become fully opaque at a distance of 13.0 units. Use fogColor for blending.
Theory
Fog is a technique used in computer graphics to simulate the effect of fog in a scene. It helps to create a sense of depth and atmosphere by gradually blending objects with the fog color based on their distance from the camera. It can also be used to limit the view distance, reducing the number of objects that need to be rendered and thus improving performance.
How Linear Fog Works:
Linear fog calculates the fog factor based on the distance between the camera and the object. The fog factor determines how much of the object's color is blended with the fog color. The formula for the fog factor in linear fog is:
fogFactor = 1.0 - (fogEnd − fragDistance) / (fogEnd − fogStart)
The fog factor is then clamped to the range [0.0, 1.0] to ensure it stays within valid bounds.