My implementation of a rasterisation renderer in Zig. I am using this project to learn Zig for scientific computing applications and a rasteriser includes enough linear algebra to explore the language for this purpose. I come from a Python background with some limited experience in Cython and C but wanted a new high performance compiled language with good Python interop, hence Zig.
The rasteriser is built using Zig 0.14 and can be run using:
zig run -O ReleaseFast src/main.zig
This project is inspired by the rasteriser implementation on Scratchapixel, this taught me a lot about computer graphics! See their description of the rasterisation process here and their code here.
The test case for rendering is a finite element solid mechanics simulation of a linear elastic cylinder loaded in compression, see visualisation below of the vertical displacement field using Paraview. The goal of the test case is to render the vertical displacement field based on given camera parameters. I performed this simulation using Gmsh to create the mesh and MOOSE as the physics solver. The Gmsh .geo
and MOOSE input .i
file can be found in the data directory. I skinned the 3D mesh using pyvista
then I parsed the surface mesh (nodal coordinates and connectivity table) and the output displacement field to .csv
files to be read into Zig (files are in the data directory). Note that the simulation itself is in SI units but the .csv
files have been scaled to mm
.
![]() |
---|
Rasterisation rendering test case: a linear elastic cylinder loaded in compression showing the vertical displacement field. |
This project provides support for basic linear algebra operations on vectors and matrices through the Vector
and Matrix
types. This supports small vectors and matrices through the types: Vec2f
, Vec3f
, Mat22f
, Mat33f
and Mat44f
.