Rendering Real-Time Heat Distortion and Mirage Effects
Simulating realistic desert environments requires rendering atmospheric anomalies like shimmering heat haze and mirages. Game developers achieve these real-time effects using a combination of screen-space refraction shaders, dynamic noise textures, depth-aware masking, and grazing-angle reflection techniques. By manipulating how light rays reach the virtual camera through varying air densities, engines recreate the illusion of baking ambient heat without incurring prohibitive rendering overhead.
The Science Behind the Shader
Heat distortion occurs naturally when intense surface heat creates a sharp temperature gradient directly above the ground. Because hot air is less dense than cool air, light bends as it passes through the fluctuating air layers. In game development, rather than simulating full volumetric thermodynamics, developers simulate this optical refraction at the surface or post-processing level by displacing pixels directly on the rendered screen buffer.
Screen-Space Refraction via UV Distortion
The foundational technique for heat shimmer involves modifying the UV coordinates of the rendered scene color buffer:
- Scene Color Capture: The game renders all opaque geometry in the desert scene to an off-screen texture (often called the scene color or background buffer).
- Noise and Vector Fields: An animated distortion map—typically composed of two overlapping Perlin or Simplex noise textures scrolling at different speeds and directions—acts as a vector field.
- UV Offset: A custom screen-space shader reads this noise map and applies subtle offsets to the UV coordinates used to sample the background scene color. When pixels sample the background slightly off-center over time, a dynamic, fluid shimmering effect is produced.
Depth and Distance Attenuation
Distortion must interact properly with the environment to prevent artifacts such as foreground characters refracting against the sky, or distant mountains warping excessively.
- Depth Buffer Reading: Shaders query the camera depth buffer to ensure the heat effect is only applied to pixels that are farther away than the heat volume itself. If an object passes between the camera and the heat emitter, the distortion is masked out.
- Vertical Fade: Developers attenuate the distortion strength along the vertical axis, concentrating the strongest shimmer within the first few meters above the desert floor where the temperature gradient is steepest.
- Camera Distance Scaling: Distortion frequency and intensity scale based on distance from the camera. At close range, distortion is nearly invisible; at mid-to-long ranges, it intensifies to reflect the accumulation of refracted light through thick layers of turbulent air.
Rendering Inferior Mirages
A mirage—often appearing as a pool of water on distant hot asphalt or sand—is an extreme refraction that bends light from the sky down toward the ground and up into the observer's eye. Developers render this phenomenon using specialized surface shaders on the terrain:
- Planar and Screen-Space Reflections: Ground planes sample either a low-resolution planar reflection camera, an atmospheric cube map, or the upper half of the screen-space reflection (SSR) buffer.
- Fresnel Masking: The reflection is masked using a strong Fresnel term. Viewed from directly above, the ground displays its standard diffuse sand texture. At shallow, grazing angles, the surface blends smoothly into the reflected sky.
- Edge Softening and Blur: The reflected sky is blurred and modulated by the same scrolling noise maps used for heat distortion, causing the apparent "water" to ripple and break apart dynamically as the player moves.
Implementation Methods: Particles vs. Volumes
To control where heat occurs, developers choose between localized emitters and global volumes:
- Particle Systems: Quad particles mapped with distortion shaders are placed above localized heat sources like campfires, vehicle exhausts, or sun-baked rock outcroppings. Particles allow artist-driven placement and natural dissipation over time.
- Post-Process Global Volumes: For vast desert landscapes, global post-processing volumes apply atmospheric shimmer across the entire horizon. The shader activates beyond a set distance threshold, reducing per-particle draw calls and ensuring uniform coverage across vast open worlds.
Optimization Strategies
Because screen-space refraction requires an extra copy of the scene color buffer, developers optimize heat effects to maintain high frame rates. Downsampling the distortion pass to a half-resolution or quarter-resolution buffer significantly reduces memory bandwidth. The final distorted result is then upscaled and composited back onto the full-resolution image, introducing a natural atmospheric softness that complements the blur of real-world heat haze.