The Definitive Guide to 3D Graphics with Perl#

The 2D guide ended by naming the third dimension as the road out, and this is that road. It covers the same ground for 3D that the first book covered for 2D: the theory you eventually need, the geometry and the file formats, the way a triangle actually reaches the screen, and how Perl talks to the hardware and to the engines everyone else uses. It ends with three programs you can run.

3D has a reputation for being gatekept by C++ and by engines, and the reputation is mostly about tooling rather than about the subject. The mathematics is a handful of ideas that fit on one page. The rendering pipeline is a sequence you can implement yourself before you ever hand it to a graphics card. Perl can drive that graphics card, and this guide shows exactly how.

What this guide runs on#

Worth stating plainly at the top, because it shapes every chapter. pperl cannot load a compiled extension: XS binds to perl5’s C-level ABI and pperl has no such ABI to bind to. That rules out the historical Perl 3D bindings, which are all XS. What it leaves is better than it sounds, and it is what this guide is built on:

  • Plain Perl, for the mathematics, the meshes, the file formats and a software renderer you write yourself. Every example in the first two arcs runs with nothing installed.

  • The native SDL2 binding, which pperl ships, for a window, the event loop and timing.

  • PDL, for arithmetic over a whole grid at once without a Perl loop.

  • Peta::WebGPU, the GPU binding, for drawing and for compute work. The GPU arc puts the earlier chapters’ geometry on the screen through the graphics card, and the world generator writes its terrain stages in plain Perl, PDL and GPU compute and measures what each costs.

Which chapter do I want?#

I want to …

Start here

understand the maths and the transform pipeline

foundations

fill a triangle, or know what a depth buffer is for

software-rasteriser

light a surface, or paint a texture onto it

shading

store geometry, or diagnose a broken model

meshes

read or write OBJ, STL, PLY or glTF

model-formats

extrude, revolve, subdivide, or combine solids

modelling-operations

arrange a scene, steer a camera, or click on an object

scene-graphs

open a window, reach the GPU, or run a frame loop

gpu-device-and-window

draw a first triangle with shaders and buffers

gpu-pipeline

render a lit 3D scene with depth on the GPU

gpu-3d-scene

generate a landscape, or compare Perl, PDL and GPU compute

capstone-world-generator

build an interactive modeller

capstone-modeller

build a small 3D game

capstone-3d-game

A note on the second dimension#

This guide assumes the 2D guide’s foundations: the difference between raster and vector, the top-left screen coordinate system, RGB and alpha, and source-over compositing. It does not repeat them. Where a 2D idea returns in a new form, the chapter says so and links back rather than re-explaining.

The one place the earlier book deliberately stopped short was the Z-buffer. It named the idea, said that in two dimensions draw order is your depth buffer, and left it there. This guide picks it up properly.