26 Rendering: Sky Map
This tour examines sky rendering in Doom, covering: - Sky interface constants and functions in r_sky.h
- Sky texture initialization in r_sky.c
- Sky column sampling and drawing in r_plane.c
File: linuxdoom-1.10/r_sky.h
Declares sky rendering.
Lines 34–41.
ANGLETOSKYSHIFT
(line 35) defines the bit shift to convert screen X into a 360° sky texture column index. skytexture
(line 37) holds the texture ID, and skytexturemid
(line 38) its vertical midpoint. R_InitSkyMap()
(line 41) is called whenever the view size changes.
File: linuxdoom-1.10/r_sky.c
R_InitSkyMap sets the vertical offset for sky drawing.
Lines 57–61.
R_InitSkyMap()
sets skytexturemid
to position the sky texture’s horizon line.
Next we’ll examine how the engine
identifies and renders sky planes
in the visplane rendering loop
.
File: linuxdoom-1.10/r_plane.c
Sky planes are identified by comparing pl->picnum
to skyflatnum
.
Lines 395–398.
When pl->picnum == skyflatnum
(line 396), the engine treats the visplane as sky and switches to full-bright mapping.
The engine sets full-bright colormaps and skytexturemid when rendering sky planes.
Lines 404–407.
dc_texturemid = skytexturemid
(line 405) applies the vertical shift calculated during sky map initialization.
ANGLETOSKYSHIFT converts the combined viewangle and x-direction angle into a sky texture column index by right-shifting the sum.
Line 413.
By shifting the 32-bit fixed-point viewangle sum right by ANGLETOSKYSHIFT
(line 413), the engine discards excess precision and maps the result into the 0–255 range of sky texture columns.
Each column maps to a sky texture via angle.
Lines 414–417.
angle = (viewangle + xtoviewangle[x]) >> ANGLETOSKYSHIFT
(line 414) computes the sky column index.
dc_source = R_GetColumn(skytexture, angle)
(line 416) fetches that column from the sky texture.
colfunc()
(line 417) draws it.
The sky map renderer converts view angles to texture coordinates and draws each sky column at full brightness.