Architecture Overview
The rendering system is organized into several key components:- GameRenderer - Main rendering coordinator and camera management
- LevelRenderer - Terrain chunk rendering and world visualization
- EntityRenderer - Entity and mob rendering with model system
- ParticleEngine - Particle effects management and rendering
- TileRenderer - Block/tile rendering
- TileEntityRenderer - Special block entity rendering (chests, signs, etc.)
Rendering Pipeline
The rendering process follows this general order:-
Camera Setup (
GameRenderer::setupCamera)- Position and orientation calculation
- FOV and projection matrix setup
- Third-person camera handling
- Smooth camera movement interpolation
-
Sky Rendering (
LevelRenderer::renderSky)- Skybox with sun, moon, and stars
- Dimension-specific sky (Overworld, Nether, End)
- Time-of-day based coloring
- Rain brightness adjustment
-
Terrain Rendering (
LevelRenderer::render)- Chunk frustum culling
- Opaque geometry (layer 0)
- Transparent geometry (layer 1)
- Platform-specific optimizations
-
Entity Rendering (
LevelRenderer::renderEntities)- Entity frustum culling
- Model-based rendering
- Shadow rendering
- Name tag rendering
-
Particle Rendering (
ParticleEngine::render)- Sorted by texture type
- Billboarded quads
- Lighting integration
-
Weather Effects (
GameRenderer::renderSnowAndRain)- Rain and snow particles
- Weather-based audio
-
Cloud Rendering (
LevelRenderer::renderClouds)- Simple and advanced cloud modes
- Dynamic movement
- Lighting integration
-
Hand Rendering (
GameRenderer::renderItemInHand)- First-person hand and item
- Animation and bobbing
-
UI Rendering (
GameRenderer::setupGuiScreen)- HUD elements
- Menus and screens
Texture Management
Textures are managed through theTextures class:
- Terrain Atlas - Block textures compiled into a single atlas
- Item Atlas - Item textures
- Entity Textures - Mob skins and entity textures
- Particle Textures - Particle effects
- UI Textures - GUI elements
Dynamic Textures
The engine supports dynamic texture loading:Lighting System
Lighting is handled through multiple mechanisms:Light Texture
GameRenderer::updateLightTexture manages dynamic lighting:
- Per-level light textures (up to 4 for split-screen)
- Night vision effects
- Dimension-specific lighting (Nether has different lighting)
- Smooth transitions between light levels
Texture Lighting
WhenSharedConstants::TEXTURE_LIGHTING is enabled:
- Vertices receive light color via
GL_TEXTURE1 - Per-chunk lighting calculations
- Smooth lighting across block boundaries
Performance Optimizations
Chunk Management
The system uses several optimization strategies:- Frustum Culling - Only render visible chunks
- Occlusion Culling - Skip chunks behind other chunks
- Empty Chunk Flags - Skip rendering empty chunks
- Dirty Chunk System - Only rebuild modified chunks
- Command Buffers - Pre-compiled rendering commands
Split-Screen Support
Multi-player rendering is optimized:- Shared chunk pool across players
- Per-player frustum culling
- Dynamic render distance based on player count
- Reference counting for shared resources
Platform-Specific Optimizations
PS3 SPU Acceleration
The PS3 version offloads culling to SPU:LevelRenderer_cull- Chunk frustum culling on SPULevelRenderer_zSort- Depth sorting on SPULevelRenderer_FindNearestChunk- Nearest chunk finding on SPU
LevelRenderer.cpp:102 (SPU task implementation)
PS Vita Optimizations
- Reduced render distance in split-screen
- Alpha cutout optimization (separate pass)
- Forced LOD control for cutout geometry
- Camera position-based fog calculations
Xbox One/PS4
- Larger command buffer allocations (512MB Xbox One, 448MB PS4)
- Enhanced memory management
Anaglyph 3D Support
The system supports stereoscopic rendering:GameRenderer.h:18-19 (anaglyph pass tracking)
Render Distance
Render distance is dynamically calculated:- Single player: Maximum render distance
- Split-screen: Reduced per-player to maintain performance
- Configurable via
Options::viewDistance
LevelRenderer.cpp:420 (render area calculation)
Multi-Threading
The rendering system supports threaded chunk updates:GameRenderer::m_updateThread- Background chunk rebuilding- Critical sections for dirty chunk management
- Thread-safe renderable tile entity tracking
- Deferred deletion of rendering resources
GameRenderer.h:146-170 (multi-threading support)
Debug Information
Rendering Stats
-
LevelRenderer::gatherStats1()- Chunk statistics- Rendered chunks / Total chunks
- Frustum culled (F), Occluded (O), Empty (E)
-
LevelRenderer::gatherStats2()- Entity statistics- Rendered entities / Total entities
- Culled (B), Invisible (I)
LevelRenderer.cpp:606-614 (statistics gathering)
Command Buffer System
Chunk rendering uses OpenGL display lists (command buffers):- Pre-compiled geometry for each chunk
- Two render lists per chunk (opaque and transparent)
- Global chunk indexing system
- Memory-limited allocation (platform-specific)
LevelRenderer.h:46-56 (command buffer limits)
Next Steps
- Level Renderer - Detailed chunk rendering
- Entity Renderer - Entity and mob rendering
- Particle Engine - Particle effects system