Skip to content

Skybox

Skybox is a technique for representing an infinite background in 3D space. It is rendered by creating a SkyBox object and assigning it to the skybox property of a View3D.

1. Basic Usage

Unlike general meshes, a SkyBox is not added to the Scene but is connected directly to a View3D.

javascript
// 1. Create a SkyBox (Texture required)
const skybox = new RedGPU.Display.SkyBox(redGPUContext, texture);

// 2. Apply to a View (Required)
view.skybox = skybox;

2. Texture Creation Methods

There are two main methods for creating textures to be applied to a SkyBox. We'll look at them in order, starting with IBL, the most recommended method, followed by traditional CubeMaps.

When a RedGPU.Resource.IBL object is created, an Environment Texture is automatically generated internally. This method utilizes that texture for the SkyBox.

  • Pros: You get Physically Based Lighting (Diffuse and Specular) data that perfectly matches the background.
  • Usage: A modern method mainly used to achieve the most realistic rendering results.

[HDR File Usage Guide]

To use a single HDR (.hdr) panorama image as a skybox in RedGPU, you must go through IBL. SkyBoxes require cube-formatted data, and IBL automatically converts 2D panoramas into cubemaps.

javascript
// Create IBL (Lighting data + background texture created)
const ibl = new RedGPU.Resource.IBL(
    redGPUContext, 
    '/RedGPU/examples/assets/hdr/2k/the_sky_is_on_fire_2k.hdr'
);

// Use the environmentTexture inside IBL as the SkyBox
const skybox = new RedGPU.Display.SkyBox(redGPUContext, ibl.environmentTexture);

2.2 6 Images (CubeTexture)

A traditional method of combining 6 standard images (JPG, PNG, etc.)—top, bottom, left, right, front, and back—to create a CubeTexture. The image array must be passed in the following order: px, nx, py, ny, pz, nz.

  • Pros: Resources are easy to obtain and intuitive to understand.
  • Cons: It is difficult to achieve realistic lighting effects as it does not contain HDR information.
javascript
const cubeTexture = new RedGPU.Resource.CubeTexture(redGPUContext, [
    './posx.jpg', './negx.jpg', 
    './posy.jpg', './negy.jpg', 
    './posz.jpg', './negz.jpg'
]);

const skybox = new RedGPU.Display.SkyBox(redGPUContext, cubeTexture);

3. Comparison of Implementation Methods

CategoryUsing IBL (Recommended)CubeTexture
Source1 HDR image6 images
TypeIBLCubeTextureCubeTexture
Lighting DataYes (Auto-generated)No
Main UsageBackground + PBR LightingSimple background

4. Live Demo

A. IBL Method (Including Lighting)

B. CubeMap Method (6 Images)

Key Summary

  • A SkyBox is set on a view (View3D) to render the background.
  • If realistic lighting is required, it is best to use an environment texture created via IBL.
  • Use HDRTexture or CubeTexture for a simple background.

Next Steps