Course
QMUL Computer Graphics (ECS610U), Fall 2025
Completed: December 2025
Graphics API: WebGL 1.0, GLSL ES 1.0
Platform: Web browser
Role: Graphics programmer (solo coursework)
Software Used: JavaScript, GLSL, VS Code
Debug Visualization is a set of shaders that show what the GPU is actually working with instead of the final lit image. Rendering raw vertices, the triangle wireframe, linearized depth and surface normals makes geometry and lighting bugs much easier to diagnose, and they are the same kinds of views engines expose in their buffer visualizers.
The normal view maps each surface direction to a color: hue comes from the normal's XY direction and saturation from how far it tilts away from the camera, so surfaces facing the viewer read white while the silhouette edges sweep through the full color wheel.
All of these run on the same Suzanne mesh and camera as the lighting work, so they can be compared directly.
Overview:
What I Did:
-
Reconstructed linear scene depth from the non-linear depth buffer
-
Mapped surface normals to an HSV color wheel for orientation debugging
-
Rendered vertex clouds and wireframes from the same buffers with different draw modes
-
Used fragment discard to cut into the mesh and expose the missing visibility term in local lighting
-
Compared max() and abs() clamping on the specular term to show why back-facing highlights appear
-
Documented every step in a written lab report with renders and code excerpts



How It Works
The depth view reconstructs real scene depth from gl_FragCoord.z. The hardware depth buffer is non-linear, packing most of its precision close to the near plane, so a scene_depth() function reverses the perspective projection to recover eye-space distance, which is then remapped between the near and far planes to a grayscale ramp.
The point and line views reuse the same vertex and index buffers with different draw modes. Seeing the bare vertex cloud and the triangle edges makes it obvious where the mesh spends its geometry and where interpolation has to stretch across large faces.
To test the lighting model I cut a hole in the mesh by discarding fragments, then moved the light in front of and behind the opening. Light still reaches the inside faces from behind, because Phong is a purely local model with no visibility or shadow term. Clamping the specular term with abs() instead of max() makes the problem worse, adding highlights on surfaces facing away from the light.

