Skip to main content
The LevelRenderer class is responsible for rendering the Minecraft world terrain, managing chunks, and coordinating level-wide visual effects.

Class Overview

See: LevelRenderer.h:35

Core Responsibilities

  • Chunk rendering and management
  • Frustum and occlusion culling
  • Sky and atmospheric effects
  • Weather rendering
  • Entity and tile entity coordination
  • Particle system integration

Chunk Architecture

Chunk Dimensions

See: LevelRenderer.h:39-45

Command Buffer Allocation

Platform-specific memory limits for chunk rendering: See: LevelRenderer.h:46-56

Global Chunk System

Chunks are managed in a global indexing system that supports multiple dimensions:

Dimension Layout

See: LevelRenderer.cpp:80-99

Chunk Flags

Each chunk has flags stored in a global array:
  • CHUNK_FLAG_COMPILED (0x01) - Chunk has compiled geometry
  • CHUNK_FLAG_DIRTY (0x02) - Chunk needs rebuilding
  • CHUNK_FLAG_EMPTY0 (0x04) - Opaque layer is empty
  • CHUNK_FLAG_EMPTY1 (0x08) - Transparent layer is empty
  • CHUNK_FLAG_NOTSKYLIT (0x10) - Chunk is not lit by sky
  • CHUNK_FLAG_CRITICAL (0x20) - Critical chunk (Vita only)
  • CHUNK_FLAG_CUT_OUT (0x40) - Contains alpha cutout geometry
  • Reference count bits - Track player references
See: LevelRenderer.h:243-258

Rendering Pipeline

Main Render Function

See: LevelRenderer.cpp:672 Parameters:
  • player - The viewing player/mob
  • layer - Render layer (0 = opaque, 1 = transparent)
  • alpha - Frame interpolation (0.0 to 1.0)
  • updateChunks - Whether to update dirty chunks
Returns: Number of chunks rendered

Render Order

  1. Chunk Sorting - Position chunks relative to player
  2. Frustum Culling - Determine visible chunks
  3. Layer Rendering - Render opaque, then transparent
  4. Lighting - Apply light texture

Render Chunk Implementation

See: LevelRenderer.cpp:737 On PS3, this uses SPU-accelerated culling:
See: LevelRenderer.cpp:757-770

Chunk Culling

Frustum Culling

Determines which chunks are visible in the view frustum.

SPU Culling (PS3)

See: LevelRenderer.h:102-106 Offloads culling calculations to the PS3’s SPU cores:
  • LevelRenderer_cull - Frustum culling task
  • LevelRenderer_FindNearestChunk - Nearest chunk finding
  • LevelRenderer_zSort - Depth sorting for transparency
See: LevelRenderer_cull.h:14-34 (SPU data structures)

Dirty Chunk Management

Marking Chunks Dirty

Marks a region of chunks as needing a rebuild. See: LevelRenderer.h:96

Updating Dirty Chunks

Rebuilds modified chunks, returns true if any chunks were updated. See: LevelRenderer.h:89

Lock-Free Stack

Dirty chunks are tracked using a lock-free stack:
See: LevelRenderer.h:260

Multi-Threading

Chunk Rebuild Threads

For large worlds, chunks can be rebuilt on background threads:
See: LevelRenderer.h:266-274

Sky Rendering

Sky System

See: LevelRenderer.cpp:932 Features:
  • Dimension-specific skies
  • Sun and moon rendering with phases
  • Star field (1500 procedural stars)
  • Sunrise/sunset gradient
  • Rain brightness adjustment
  • Anaglyph 3D support

Halo Ring (Special Sky)

See: LevelRenderer.cpp:1184 Renders a special Halo-themed ring in the sky (texture pack feature).

Cloud Rendering

Simple Clouds

See: LevelRenderer.cpp:1234 Fast cloud rendering using textured quads.

Advanced Clouds

See: LevelRenderer.cpp:1506 Full 3D volumetric clouds:
  • Cube-per-texel geometry
  • 6 directional render lists + 1 combined
  • Conditional backface culling based on player height
  • Frustum culling per 8×8 section
  • Reduced radius in 3-4 player split-screen

Cloud Mesh Generation

See: LevelRenderer.cpp:1340 Pre-generates cloud geometry into 7 display lists:
  • Lists 0-5: Individual face directions
  • List 6: All faces combined

Platform-Specific Optimizations

PS Vita Alpha Cutout

Vita renders alpha cutout geometry in a separate pass:
See: LevelRenderer.cpp:775-824

Large World Support

Large worlds use different parameters:
See: LevelRenderer.h:212-217

Split-Screen Support

The renderer supports up to 4 simultaneous players:
See: LevelRenderer.h:132-157

Dynamic Render Distance

Render distance decreases with more players to maintain performance. See: LevelRenderer.cpp:420

Destroyed Tile Management

Temporary collision tracking for recently destroyed blocks:
See: LevelRenderer.h:175-200 Provides temporary collision while chunk render data updates.

Entity and Tile Entity Rendering

Entity Rendering

See: LevelRenderer.cpp:494
  • Prepares render dispatchers
  • Culls entities to frustum
  • Renders regular entities
  • Renders global entities (always visible)
  • Renders tile entities

Tile Entity Storage

See: LevelRenderer.h:123 Stored by global chunk index for fast dimension filtering.

Statistics

Chunk Statistics

Returns: "C: rendered/total. F: frustum_culled, O: occluded, E: empty" See: LevelRenderer.cpp:606

Entity Statistics

Returns: "E: rendered/total. B: culled, I: invisible" See: LevelRenderer.cpp:611