Space, gradient, solid-colour, and image-based skyboxes with animation control
The Skybox API lets you set any kind of background for your 3D scene β procedural star fields, gradient skies, flat colours, or full cube-map images. Only one skybox is active at a time; calling a new create*Skybox function automatically replaces the previous one.
Creates a procedural space background with stars and optional nebulae.
// Space combat scene
createSpaceSkybox({ starCount: 10000, nebulaColor: 0x4400ff });
Creates a smooth two-colour gradient sky β ideal for outdoor scenes.
createGradientSkybox(0x1a6aa8, 0xf4a460); // warm sunset
createGradientSkybox(0x87ceeb, 0x228b22); // daytime with green ground tint
Sets the background to a single flat colour β useful for caves, indoor rooms, or stylised scenes.
createSolidSkybox(0x000000); // pitch-black cave
createSolidSkybox(0x1a1a2e); // deep navy interior
Loads six cube-face images as the skybox. Also sets them as the scene's environment map, enabling image-based lighting (IBL) for PBR materials β reflections and light come from the sky.
await in your init()Loading is async β await the call so objects are fully lit before the first frame.
export async function init() {
await createImageSkybox([
'/assets/sky/studio/px.png',
'/assets/sky/studio/nx.png',
'/assets/sky/studio/py.png',
'/assets/sky/studio/ny.png',
'/assets/sky/studio/pz.png',
'/assets/sky/studio/nz.png',
]);
// PBR spheres now receive correct reflections
createSphere(1, 0xffffff, [0, 1, 0], { material: 'metallic', roughness: 0.1 });
}
Removes the active skybox, leaving a transparent/black background.
clearSkybox();
Advances the skybox rotation by dt seconds. Call this manually inside your update(dt) loop, or use enableSkyboxAutoAnimate() to let the engine do it automatically.
export function update(dt) {
animateSkybox(dt); // manual control
}
Tells the engine to automatically call animateSkybox(dt) every frame, so you don't need to do it manually in update().
enableSkyboxAutoAnimate(); // default speed
enableSkyboxAutoAnimate(0.25); // slow drift
enableSkyboxAutoAnimate(-1); // reverse
Stops the engine from automatically rotating the skybox each frame.
disableSkyboxAutoAnimate();
Changes the rotation speed of the active skybox animation without disabling/re-enabling it.
0 = frozen, 1 = normal, 2 = double, -1 = reversesetSkyboxSpeed(0); // freeze during a cutscene
setSkyboxSpeed(2); // warp-speed effect
setSkyboxSpeed(1); // restore normal speed
| Function | Use case |
|---|---|
createSpaceSkybox(opts?) | Space games, sci-fi |
createGradientSkybox(top, bottom) | Outdoor, sunset, underwater |
createSolidSkybox(color) | Caves, indoor, stylised |
createImageSkybox([6 urls]) | Photorealistic + IBL for PBR |
clearSkybox() | Remove background |
animateSkybox(dt) | Manual frame-by-frame rotation |
enableSkyboxAutoAnimate(speed?) | Set-and-forget rotation |
disableSkyboxAutoAnimate() | Stop auto rotation |
setSkyboxSpeed(mult) | Adjust speed at runtime |