Table of Contents
This project is a C++ and OpenGL implementation of a volumetric fog shader. It demonstrates a common computer graphics technique used to add depth, atmosphere, and mood to a 3D scene.
-
Procedural Noise and Fog - Dynamic, atmospheric fog is created using multiple layers of procedural noise, making it appear turbulent and natural. The fog's density realistically increases with distance and decreases with altitude, adding depth to the scene.
-
RayMarching - This technique renders the procedural landscape by casting a ray for each pixel and "marching" it through the scene. The final color is determined by where this ray intersects with the terrain surface.
-
Terrain Formation - The terrain's shape is procedurally generated using layered sine waves to create rolling hills and valleys. The surface is then shaded by calculating its normals for realistic lighting and applying a base texture color.
-
Main Execution - This function serves as the entry point, setting up the animated camera's position and view for the scene. It then coordinates the raymarching and shading processes for every pixel to produce the final image.
To set up a local instance of the application, follow the steps below.
The environment needed is just the shadertoy (Available online, so no further installations required)
This shader is designed to run directly in a web browser on the Shadertoy platform. No local installation or setup is required.
-
View the shader live:
- You can see the volumetric fog shader in action by visiting the project page on Shadertoy:
- Click here to view the Fog Shader
-
Experiment with the code:
- The shader is interactive in the sense that you can edit the code directly on the Shadertoy website to see real-time changes.
- Try modifying these constants at the top of the code to see how they affect the visuals:
density_fog: Increase this value for thicker, more opaque fog, or decrease it for a lighter haze.height_fog: Adjust this to control how the fog settles in the valleys versus on the hilltops.lightdirn: Change thevec3values to alter the direction of the light source and see how shadows and highlights are affected.
The currently active maintainer(s) of this project.
Honoring the original creator(s) and ideator(s) of this project.