~/cheatsheets $ man 1 graphics

GRAPHICS(1)hachem.wtf manualGRAPHICS(1)

name

graphics - the pipeline, rasterization, raycasting, bsp, and raytracing

synopsis

graphics [--pipeline-spaces] [--projection] [--rasterization] [--raycasting-wolfenstein-3d] [--bsp-doom-2-5-d] [--raytracing]

description

the rendering math i look up mid-implementation. wolf3d is raycasting (grid dda), doom is bsp (2.5-d), and true raytracing gets its own section. all three are below.

pipeline & spaces

projection

perspective, right-handed, clip $z\in[-1,1]$, with $c = \cot(\text{fovy}/2)$, aspect $a$, near $n$, and far $f$.

\begin{pmatrix}
c/a & 0 & 0 & 0 \\
0 & c & 0 & 0 \\
0 & 0 & \frac{f+n}{n-f} & \frac{2fn}{n-f} \\
0 & 0 & -1 & 0
\end{pmatrix}

rasterization

raycasting (wolfenstein 3d)

for each screen column $x$, $\text{cameraX} = 2x/W - 1$ and $\text{rayDir} = \text{dir} + \text{plane}\cdot\text{cameraX}$, where dir is forward and plane $\perp$ dir with $|\text{plane}| = \tan(\text{fov}/2)$.

deltaDist.x = |1 / rayDir.x|              # dist between x grid lines
step, sideDist = initial cell + direction
loop:
    advance on the axis with the smaller sideDist
    sideDist[axis] += deltaDist[axis];  side = axis
until map[cell] is solid
perpDist = sideDist[side] − deltaDist[side]   # perpendicular, NOT euclidean

bsp / doom (2.5-d)

raytracing

e1 = v1−v0;  e2 = v2−v0
h = D × e2;   a = e1 · h           # |a| < ε  ⇒  ray ∥ triangle
f = 1/a;  s = O − v0
u = f (s · h);        miss if u < 0 or u > 1
q = s × e1
v = f (D · q);        miss if v < 0 or u+v > 1
t = f (e2 · q);       hit if t > ε
L_o(\mathbf{x},\boldsymbol{\omega}_o) = L_e + \int_\Omega f_r(\mathbf{x},\boldsymbol{\omega}_i,\boldsymbol{\omega}_o)\,L_i(\mathbf{x},\boldsymbol{\omega}_i)\,(\boldsymbol{\omega}_i\cdot\mathbf{n})\,d\omega_i

see also

gdb-lldb(1), interrupts(1), math(1), quantum(1), x86-64(1), cheatsheets(1), hachem(1)

author

hachem <im@hachem.wtf>

~/cheatsheets $