Sheet 09: Overdraw
Exercise: Visualizing Overdraw
Start from the completed solution of exercise 08. The supplied city already includes the working HZB construction, occlusion test, camera, and overview. There is no overdraw visualization in the starter code. Implement the new render mode, shader output, blending state, and keyboard control yourself.
Overdraw occurs when several submitted surfaces cover the same pixel. Although depth testing can reject hidden fragments during normal rendering, a diagnostic mode can deliberately accumulate their contributions to reveal geometric overlap.
Task: Add an Overdraw Render Mode
Add a mode that draws the same submitted scene in faint white on a black background.
Replace lighting and material colors with a small constant contribution, for example
1.0 / 64.0 per fragment. Use additive blending so overlapping fragments
become brighter. The reference solution uses V to switch modes.
Disable depth testing and depth writes for this diagnostic pass so hidden surfaces contribute as well. The supplied scene also has back-face culling disabled, so both front and back surfaces of a closed brick contribute. Restore all changed state before drawing the overview or starting the next depth/HZB pass.
Keep the normal color rendering available. Compare the visualization with occlusion
culling enabled and disabled using C. Frustum rejection remains active.
Do not change the occluder depth pass: only the final camera rendering should use
the additive diagnostic mode.
This is a visualization of submitted surface overlap, not a measurement of actual fragment shader invocations or GPU time. With an 8-bit output, brightness eventually saturates; the example weight reaches white after roughly 64 contributions.
Reference Solution
V: normal/overdraw rendering; C: occlusion culling; O: overview; R: reset camera and history. W/S: forward/backward; A/D: strafe; left mouse drag: look around; mouse wheel: move forward/backward.
Text description and demo controls
The camera moves through a city of colored buildings arranged in street blocks. In normal mode, buildings use their material colors and window pattern. In overdraw mode, submitted surfaces add a small white contribution over a black background. Brighter areas have more overlapping surfaces; sufficiently dense overlap saturates to white.
The overview is hidden by default and can be enabled with O. It remains a normal diagnostic view: all buildings are drawn, red if at least one brick was selected for the camera and white otherwise. Occlusion culling changes the submitted geometry, so it can reduce brightness in the overdraw view.
Focus the demo with Tab. V toggles overdraw; C toggles occlusion culling; O toggles the overview; R resets the camera and visibility history. Hold W/S to fly along the viewing direction or A/D to move sideways. Looking around requires left mouse dragging; the mouse wheel also moves forward or backward.