Skip to Content
RecipesLighting

Lighting

Target API: 5 · Target build: bbb6l5 (2026-11-20, production and preprod) · Status: Verified (ported to the current API — on-device re-check recommended)

Contrast S-curve

fn pack_scurve(c: vec3f, strength: f32) -> vec3f { let c01 = clamp(c, vec3f(0.0), vec3f(1.0)); return mix(c01, c01 * c01 * (vec3f(3.0) - 2.0 * c01), strength); }

Distance haze (custom fog)

fn bloxdTerrainLight(s: BloxdSurface, l: BloxdLightIn) -> BloxdLight { var out = bloxdDefaultLight(s, l); let dist = distance(bloxdEyePosition(), l.position); // add 0..0.35 of custom fog from 64 to 192 blocks let haze = clamp((dist - 64.0) / 128.0, 0.0, 1.0) * 0.35; out.colour = mix(out.colour, l.fogColour, haze); return out; }

Night (skyLight-driven blue shift + lamp protection)

fn bloxdTerrainLight(s: BloxdSurface, l: BloxdLightIn) -> BloxdLight { var out = bloxdDefaultLight(s, l); if (bloxdLit()) { let sky = clamp(l.skyLight, 0.0, 1.0); out.colour = mix(out.colour, out.colour * vec3f(0.55, 0.68, 1.0), sky * 0.55); let blockAmt = max(l.blockLight.r, max(l.blockLight.g, l.blockLight.b)); out.colour += vec3f(1.0, 0.72, 0.38) * blockAmt * 0.30; } return out; }

Pitch-dark caves (darken skyless areas further)

fn bloxdTerrainLight(s: BloxdSurface, l: BloxdLightIn) -> BloxdLight { var out = bloxdDefaultLight(s, l); if (bloxdLit()) { let sky = clamp(l.skyLight, 0.0, 1.0); let underground = 1.0 - sky; out.colour *= mix(1.0, 0.35, underground * underground); } return out; }

skyLight arrives post-lift (section 10), so shallow occlusion (e.g. under trees: raw 0.87 → lifted 0.97) barely darkens with this method. It works for caves (raw 0). To sharpen “tree shade”, use the lift-inversion + threshold method in R9.12.

Blue night ambience (pseudo look without moon direction)

In this API, bloxdSunDirection() is zero when the sky has no sun. The following is not directional moonlight, just a faint blue ambient added when the sky is dark. Moon direction itself is available via -bloxdSunDirection() (day/night-cycle worlds only — The sun and the moon).

fn bloxdTerrainLight(s: BloxdSurface, l: BloxdLightIn) -> BloxdLight { var out = bloxdDefaultLight(s, l); if (bloxdLit()) { let sunPresent = smoothstep(0.0, 0.5, length(bloxdSunDirection())); let night = 1.0 - sunPresent; let sky = clamp(l.skyLight, 0.0, 1.0); let upward = clamp(l.normal.y, 0.0, 1.0); out.colour += vec3f(0.025, 0.04, 0.075) * night * sky * upward; } return out; }

Sunset warmth (tint by sun elevation)

fn bloxdTerrainLight(s: BloxdSurface, l: BloxdLightIn) -> BloxdLight { var out = bloxdDefaultLight(s, l); let sunLen = length(bloxdSunDirection()); if (sunLen > 0.5) { let sunDir = bloxdSunDirection() / sunLen; let lowness = clamp(1.0 - sunDir.y, 0.0, 1.0); // 1 at horizon / 0 overhead let sunset = lowness * lowness; out.colour = mix(out.colour, out.colour * vec3f(1.12, 0.88, 0.72), sunset * 0.55); } return out; }

Full engine-output replacement (simplest relighting)

fn bloxdTerrainLight(s: BloxdSurface, l: BloxdLightIn) -> BloxdLight { if (bloxdLit()) { // NOTE: direct BloxdLight(...) construction is prohibited; rewrite colour from default var out = bloxdDefaultLight(s, l); let sky = clamp(l.skyLight, 0.0, 1.0); let block = max(l.blockLight.r, max(l.blockLight.g, l.blockLight.b)); let level = clamp(sky * 0.7 + block, 0.0, 1.0); // discard engineColour (the engine lighting result) and use "base color × self-computed brightness" var col = clamp(s.colour, vec3f(0.0), vec3f(1.0)) * level; col = mix(l.fogColour, col, (1.0 - l.fogAlpha)); // discarded engineColour, so fog redo is required out.colour = col + s.emission * (1.0 - l.fogAlpha); // add emission yourself too (required) return out; } else { return bloxdDefaultLight(s, l); } }