The Source Engine rendering pipeline in TF2 spans multiple subsystems coordinated by the view render system (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sr2echa/TF2-Source-Code/llms.txt
Use this file to discover all available pages before exploring further.
view.cpp, viewrender.cpp). Each frame, the engine traverses BSP leaves for visibility, draws world geometry and decals, renders studio models with bone transforms, applies lightmaps and dynamic lights, and composites shadows and post-process effects before presenting the final image.
Render loop overview
The client-side render entry point isCViewRender::RenderView() in game/client/viewrender.cpp. It coordinates the full draw sequence each frame.
Visibility determination
The engine walks the BSP tree from the current camera leaf, collecting all visible leaves via the PVS (Potentially Visible Set) stored in the
.bsp file. CClientLeafSystem tracks which renderable entities are in which leaves.World geometry
BSP surfaces and displacement meshes are drawn via
gl_rsurf.cpp. Lightmaps baked into the BSP are blended with dynamic light contributions from gl_lightmap.cpp.Studio model rendering
CStudioRender (studiorender/) draws all animated models. Bone matrices are computed per-frame from the animation system in baseanimating.cpp / bone_setup.cpp.Shadow rendering
CShadowMgr (engine/shadowmgr.cpp) manages projected texture shadows and blob shadows. Dynamic shadows are rendered as projected decals onto world surfaces.Particle systems
The particle system (
particles/) draws all active particle effects after opaque geometry, sorted by depth for correct blending.BSP world geometry
TF2 maps compile to.bsp files using the BSP format defined in public/bspfile.h. Key structures:
disp_defs.h, disp.cpp) extend flat BSP faces into terrain-like meshes used for ramps and hillsides across TF2 maps.
Studio model system
Studio models (.mdl) are rendered by IStudioRender. Bone setup is handled in public/bone_setup.cpp, which evaluates animation sequences, blends layers, and outputs a matrix3x4_t array for each bone.
Lighting and lightmaps
Static lightmaps
Static lightmaps
Baked during map compilation by VRAD. Stored in the BSP’s lighting lump and streamed into GPU textures by
gl_lightmap.cpp. TF2 uses HDR lightmaps (RGBE format) where available.Dynamic lights (dlights)
Dynamic lights (dlights)
Temporary point lights created via
engine/dynamiclight.cpp. Used for muzzle flashes, explosions, and rocket trails. Limited to MAX_DLIGHTS (32) active at once — defined in public/dlight.h.Projected texture shadows
Projected texture shadows
CProjectedTextureSystem (env_projectedtexture.cpp) renders shadow maps for dynamic shadow-casting entities. Used by the Spy’s flashlight and certain environmental effects.Color correction and post-process
Color correction volumes (colorcorrectionvolume.cpp) blend color lookup tables (LUTs) as the player moves through map areas. The CColorCorrection system (engine/colorcorrectionpanel.cpp) applies the blended LUT in the final post-process pass.
TF2 uses the
mat_hdr_level convar (0 = LDR, 1 = HDR bloom only, 2 = full HDR) to control tone mapping and HDR rendering. The default for most hardware is level 2.