Alexander Aseme
GitHub IconLinkedIn Icon

Rendering Heightfields

This project implements a heightfield renderer using OpenGL and GLSL shaders. A grayscale JPEG image is interpreted as terrain elevation data and rendered in various geometric modes, mainly points, wireframes, and solid triangles. The user can rotate, scale, and translate the terrain interactively, and toggle between rendering modes using keyboard input.

In addition to standard rendering, a custom vertex shader provides a smoothing mode that averages each vertex with its neighbors and applies a height-based exponentiation and rescaling. The user can control these smoothing parameters in real time with key bindings. Vertex positions and their neighbors are passed in as vertex attributes using separate VBOs.

To visualize heightmaps, I first parsed grayscale JPEGs into terrain meshes using varying primitive types. Each rendering mode—points, wireframes, triangles—was assigned to a keypress and implemented with distinct VAOs and VBOs to adhere to core profile restrictions. I created additional VBOs to pass in neighbor vertex positions as attributes for use in the smoothing shader mode.

The smoothing shader included uniforms for scale and exponent, which users could modify live. The scale parameter linearly scales the height of the terrain, while the exponent parameter determines the degree applied to the height value (which also affects the final color).

Key Features

  • Interactive terrain navigation (rotate, scale, translate via mouse input)
  • Supports four render modes: points, wireframe, triangles, and smooth-shaded triangles
  • Vertex neighbor smoothing logic implemented in vertex shader
  • Screenshot-based animation capture system

Extra Credit Features

  • Element Arrays: I used indexed rendering to avoid vertex duplication and reduce memory footprint, particularly for large meshes.
  • Triangle Strip Rendering: For triangle mode, I used GL_TRIANGLE_STRIP wherever feasible to further reduce redundant geometry.
  • Jet Colormap Mode: Added an alternate shader-based colormap for height visualization.
  • Wireframe Overlay: Implemented a combined mode that draws wireframes over solid triangles.

Technical Details

  • API: OpenGL 3.2 Core Profile
  • Language: C++ and GLSL
  • Special Skills: VBO/VAO management, writing shaders in HLSL

Project Demo