WebGL Scene

A 3D scene built with WebGL

WebGL Scene cover

Key learnings

WebGL fundamentals including vertex management, texture mapping, and real-time rendering optimization, with attention to cross-device performance and memory efficiency

Custom OBJ file parsing and 3D model data processing from scratch

Shader programming with GLSL for toon rendering and non-photorealistic visual effects

Description

This is a small 3D world rendered with plain WebGL 2: a low-poly landscape with a cabin, trees and a river, a day-night cycle, and a toon-style look. There is no engine underneath. Apart from gl-matrix for the math, the model loading, the shaders and the render loop are all written by hand.

A textured sun and moon circle the scene, and the light changes with them: the colours blend smoothly from day into night and back. The toon shader splits the incoming light into a few hard bands instead of a continuous gradient, which gives the scene its flat, illustrated look. At dusk, the cabin windows and lanterns keep glowing while everything around them falls into shadow.

The scene at dusk with the cabin windows and lanterns glowing

The landscape is a low-poly model from TurboSquid, exported from Blender and loaded through an OBJ and MTL importer I wrote from scratch. It reads positions, normals, texture coordinates and faces, merges vertices that share all three, and draws each material group with its own colours. Because nothing in it is specific to the cabin, any triangulated model renders the same way, like this separately generated lighthouse island with its own materials:

A generated lighthouse island loaded through the same OBJ importer, by day
The lighthouse island at dusk with a lit lantern room

You can drag to orbit the camera, limited between the horizon and a top-down view, and scroll to zoom, which eases toward its target instead of jumping. Two sliders control how fast the day passes and how far away the sun and moon travel.

Reflection

This project taught me a lot about WebGL and real-time rendering. Writing the OBJ importer was the most educational part: parsing the file and laying out vertex data by hand showed me how 3D models actually reach the GPU.

The day-night cycle was the most challenging. Smooth transitions meant interpolating colours and light intensities over time, with easing so that dawn and dusk do not snap. The toon shader was my introduction to shader programming, and getting the light bands to look right taught me how much of a visual style comes down to a few lines of maths in a fragment shader.

Performance was the other lesson. WebGL leaves memory and draw calls to you, so I learned to think about how buffers are set up, how often state changes, and what each frame actually costs.

The project gave me a solid foundation in computer graphics that I want to build on with more advanced rendering techniques.

Last updated: Nov 11, 2026