Homework 3: Volumetric Clouds with Ray Marching
Setup: The magic happens on the shaders. The CPU only handles camera movement, static skybox rendering, and screen-size quad rendering. I have also passed the uv coordinates for the quad, as it will be helpful in casting rays. Ray Casting: Getting rays cast correctly is tricky because the camera's orientation must be considered. Initially, they are cast towards the plane at z=-1 (with respect to camera basis) by utilizing uv coordinates passed. To rotate the rays, a rotation matrix should be used with the camera basis as the rotated coordinate axes. Each basis vector should correspond to a column in the matrix. Rendering Clouds: After setting up the rays, rendering clouds is not hard. I use ray marching to obtain the volumetric clouds with a certain number of steps with a predefined step size. At each step, the point at the tip of the ray is marched by the step size, and a density is sampled at that point from the density field defined by Perlin Noise on the fly. Then, this density...