27 Rendering: Lookup Tables
This tour examines DOOM’s lookup tables used for efficient rendering calculations, including angle tables, color maps, and view mapping tables.
tables.h declares lookup tables used for fast trigonometry calculations: - finesine and finecosine store pre-calculated sine/cosine values - finetangent stores pre-calculated tangent values - tantoangle converts slope values to angles
File:
linuxdoom-1.10/tables.h(lines 56–65)
We’ll look at how Doom loads its color lookup tables from the COLORMAP lump into memory.
colormapsholds lighting and color tables loaded from WAD data
> File:linuxdoom-1.10/r_data.c(lines 160–164)R_InitColormapsloads the COLORMAP lump into memory, aligned for efficient indexing
> File:linuxdoom-1.10/r_data.c(lines 639–644)
Binary Angle Measurement (BAM):
FINEANGLESdefines 8192 discrete angle steps
FINEMASKenables fast angle wrapping using bitwise AND
> File:linuxdoom-1.10/tables.h(lines 50–51)These constants define key BAM angles (e.g., ANG90, ANG180)
> File:linuxdoom-1.10/tables.h(lines 68–71)
Explanation: BAM angles are converted to table indices by shifting right and masking. This maps the full 0–360° BAM range to table entries, with 90° aligning to quarter-points.
Trigonometric and Angle Tables:
finetangent: tangent lookup table
> File:linuxdoom-1.10/tables.c(lines 67–75)finesine: fixed-point sine table (cosine via 90° offset)
> File:linuxdoom-1.10/tables.c(lines 583–590)tantoangle: converts slope values to BAM angles
> Header:linuxdoom-1.10/tables.h(lines 82–84)
> Impl:linuxdoom-1.10/tables.c(lines 1870–1872)
Dynamic Lighting and View Mapping Tables:
R_InitLightTablesusescolormapsto fillscalelightandzlightfor shading
> File:linuxdoom-1.10/r_main.c(lines 614–640)scalelightstores color ramps for light levels and scale
> Decl:linuxdoom-1.10/r_main.c(lines 116–118)
> Usage:linuxdoom-1.10/r_main.c(lines 755–759)
Texture Mapping:
R_InitTextureMappingsets up view-angle-to-screen conversions
>viewangletox: angle → x-coordinate
> File:linuxdoom-1.10/r_main.c(lines 551–577)
>xtoviewangle: x-coordinate → angle
> File:linuxdoom-1.10/r_main.c(lines 579–588)
The next steps explore lookup tables used in DOOM’s rendering system. We’ll examine arctangent lookups, dynamic lighting calculations, and texture mapping tables.
And that was it.