Sheet 6: Volume Rendering 2
Exercise: Volumetric Shadows (20 points)
In this exercise you will extend the direct volume renderer from the previous sheet with simple single-scattering style illumination. The primary raycaster is already implemented and still uses the analytic sphere, wave pattern, and shell volumes.
Your task is to complete the function traceShadowRay in
Shader/cubeFS.glsl. The surrounding code already sends the light direction,
ambient and direct light colors, shadow density scale, shadow alpha threshold, and
shadow step count to the shader.
Implement shadow-ray transmittance:
- Start at
rayStartand march toward the light usingrayDirection. - Use
distanceToVolumeExitto limit the ray to the clipped volume. - Sample the volume and apply the transfer function at each shadow sample.
- Use the transfer-function alpha as the local shadow density.
- Accumulate optical depth with the geometric
stepLength. - Convert optical depth to transmittance with
exp(-shadowDensityScale * opticalDepth).
The primary ray only traces a shadow ray for samples whose alpha is above
shadowAlphaThreshold. This avoids unnecessary work in transparent regions
and makes the transfer function control both visible opacity and shadow casting.
The most relevant shader functions are:
traceShadowRay: computes light transmittance through the volume.estimateLighting: combines ambient light and shadowed direct light.distanceToVolumeExit: computes the remaining ray length inside the clipped volume.
Test the result with the sphere first: with the light initially coming from above, the top should be brighter and the lower parts should darken. Then rotate the volume and adjust the light direction to check that the shadow follows the light, not the camera.
Reference Solution
V toggle volume, R reset, T toggle transfer-function editor
1 clip in X, 2 clip in Y, 3 clip in Z
4 move clip in X, 5 move clip in Y, 6 move clip in Z
Q increase oversampling, W decrease oversampling
J/L move light in X, I/K move light in Y, U/O move light in Z
Up zoom in, Down zoom out
Left mouse drag rotate, Right mouse drag quick edit transfer function