Clouds use a noise based fast-cloud approach:
- Flat 2D cloud pieces (no volumetric mesh).
- Fixed cloud height (
layer_y, default108.5f, the .5 is to prevent z-figthing for now). - Constant westward drift (
speed_x < 0).
The system is lightweight and generated once at startup.
Cloud runtime data lives in Clouds (src/gfx/clouds.h):
scroll_x: horizontal movement offset for cloud drift.speed_x: horizontal drift speed (-0.9fdefault, westward).cell_size: world size of one cloud cell (8.0fdefault).layer_y: fixed Y level for cloud layer (108.0fdefault).radius_cells: draw radius around camera in cell units (26default).noise_size: generated source image size (256default).block_px: pixels per cloud cell in source map (8default).grid_size: derived map side length in cells (noise_size / block_px).cloud_opacity: final alpha multiplier for cloud tiles (0.7fdefault).cell_map: binary occupancy map (0 = empty,1 = cloud).
Clouds_Init() generates cloud layout once:
GenImagePerlinNoise()creates a grayscale noise image.- Image is divided into
block_px x block_pxblocks. - Each block average brightness is thresholded (
avg >= 142) into one binary cloud cell. - Result is stored in
cell_mapand reused every frame.
This gives a procedural clouds.png-style repeating bitmap map.
Clouds_Update() only advances drift:
scroll_x += speed_x * dt
No per-cell simulation or regeneration runs every frame.
Clouds_Draw():
- Converts camera position into cloud-cell coordinates.
- Iterates a bounded square (
radius_cells) around the camera. - Wraps world cell coordinates into
cell_mapindices (infinite tiling). - Draws one flat quad for every occupied cell using
DrawTriangle3D.
Render state:
- Depth test and depth writes are disabled during cloud draw.
- Backface culling is disabled so tiles are visible from below.
- State is restored after cloud pass.
Coloring:
- Brightness tint is derived from ambient (
220 + 35 * ambient_multiplier). - Alpha comes from
cloud_opacity(cloud_opacity * 255).
Cloud pass order is sky-first in game_draw_world_pass():
Clouds_Draw(...)World_Draw(...)
So terrain draws over clouds naturally.
Primary parameters in Clouds_Init() (src/gfx/clouds.c):
cell_size: larger = chunkier cloud pieces.radius_cells: larger = farther cloud horizon, more draw cost.layer_y: cloud layer altitude.speed_x: drift speed and direction.noise_size: map repeat period (world tiling frequency).block_px: cell granularity from source image (higher = bigger blob features).cloud_opacity: overall transparency of clouds.- threshold constant (
avg >= 142): controls cloud coverage density.