Skip to main content

Overview

The Scene class is an abstract base class that represents a 3D scene. It contains all lights and objects that are going to be rendered, and provides methods for updating the scene and handling input events.

Scene Class

Creating a Scene

To create a scene, inherit from the Scene class and implement the required virtual methods:
class MyScene : public Scene {
 public:
    void initialize(Window &window) override {
        // Initialize scene objects and lights here
    }

    void update(Window &window) override {
        // Update scene logic here
    }
    
    void onMouseMove(Window &window, Movement2d movement) override {
        // Handle mouse movement here
    }
};

Virtual Methods

initialize (Required)

virtual void initialize(Window &window) = 0;
Function that initializes the scene. This method is called once by the Window class.
window
Window&
The window in which the scene is going to be run.

update

virtual void update(Window &window);
Function that updates the scene. This method is called every frame.
window
Window&
The window in which the scene is being rendered.

onMouseMove

virtual void onMouseMove(Window &window, Movement2d movement);
Function that handles mouse movement events.
window
Window&
The window in which the scene is being rendered.
movement
Movement2d
The movement delta.

onMouseScroll

virtual void onMouseScroll(Window &window, Movement2d offset);
Function that handles mouse scroll events.
window
Window&
The window in which the scene is being rendered.
offset
Movement2d
The scroll offset.

Ambient Lighting

setAmbientIntensity

void setAmbientIntensity(float intensity);
Sets the intensity of the ambient light in the scene.
intensity
float
The desired ambient light intensity. This value is divided by 4 internally.

setAutomaticAmbient

void setAutomaticAmbient(bool enabled);
Enables or disables automatic ambient coloring derived from the scene’s skybox.
enabled
bool
Whether to enable automatic ambient sampling.

isAutomaticAmbientEnabled

bool isAutomaticAmbientEnabled() const;
Returns whether automatic ambient sampling is enabled.
return
bool
True if automatic ambient is enabled.

getAutomaticAmbientColor

Color getAutomaticAmbientColor() const;
Gets the ambient color computed from the skybox when automatic ambient is active.
return
Color
The automatic ambient color.

getAutomaticAmbientIntensity

float getAutomaticAmbientIntensity() const;
Gets the intensity derived from the skybox when automatic ambient is active.
return
float
The automatic ambient intensity.

getAmbientColor

Color getAmbientColor() const;
Returns the manually configured ambient light color.
return
Color
The ambient color.

getAmbientIntensity

float getAmbientIntensity() const;
Returns the manually configured ambient intensity.
return
float
The ambient intensity.

Light Management

addDirectionalLight

void addDirectionalLight(DirectionalLight *light);
Function that adds a directional light to the scene.
light
DirectionalLight*
The directional light to add.
The light object must be valid during the entire scene lifetime.

addLight

void addLight(Light *light);
Function that adds a point light to the scene.
light
Light*
The point light to add.
The light object must be valid during the entire scene lifetime.

addSpotlight

void addSpotlight(Spotlight *light);
Function that adds a spotlight to the scene.
light
Spotlight*
The spotlight to add.
The light object must be valid during the entire scene lifetime.

addAreaLight

void addAreaLight(AreaLight *light);
Adds an area light to the scene.
light
AreaLight*
The area light to add.
The light pointer must remain valid for the entire scene lifetime.

Skybox Management

setSkybox

void setSkybox(std::shared_ptr<Skybox> newSkybox);
Sets the skybox object for the scene.
newSkybox
std::shared_ptr<Skybox>
The new skybox to set.

getSkybox

std::shared_ptr<Skybox> getSkybox() const;
Gets the current skybox.
return
std::shared_ptr<Skybox>
The current skybox.

setUseAtmosphereSkybox

void setUseAtmosphereSkybox(bool enabled);
Enables or disables using the atmosphere-generated skybox as the scene skybox. When enabled, the renderer is expected to populate atmosphereSkybox, and the scene will expose it via getSkybox(). When disabled, the scene will use the user-provided skybox set through setSkybox().
enabled
bool
Whether to use the atmosphere-generated skybox.

isUsingAtmosphereSkybox

bool isUsingAtmosphereSkybox() const;
Returns whether the atmosphere-generated skybox is currently used.
return
bool
True if using atmosphere skybox.

setAtmosphereSkybox

void setAtmosphereSkybox(std::shared_ptr<Skybox> generatedSkybox);
Sets the internally stored atmosphere-generated skybox. This is intended to be called by the renderer/engine once it has generated or updated the sky cubemap from atmosphere.
generatedSkybox
std::shared_ptr<Skybox>
The atmosphere-generated skybox.

getAtmosphereSkybox

std::shared_ptr<Skybox> getAtmosphereSkybox() const;
Returns the internally stored atmosphere-generated skybox.
return
std::shared_ptr<Skybox>
The atmosphere-generated skybox.

Environment Configuration

setEnvironment

void setEnvironment(Environment newEnv);
Overrides the environmental rendering configuration for the scene.
newEnv
Environment
The new environment settings.

Properties

atmosphere
Atmosphere
Atmosphere configuration for the scene.

Environment Class

Aggregates configurable environmental effects such as fog and bloom.

Properties

fog
Fog
Fog parameters that softly blend distant geometry with the sky.
volumetricLighting
VolumetricLighting
Controls for volumetric light scattering.
lightBloom
LightBloom
Configures bloom radii and blur passes.
rimLight
RimLight
Rim lighting intensity and tint.
lookupTexture
Texture
Optional 3D lookup texture for color grading.

Fog Structure

Parameters controlling exponential fog accumulation in the scene.
color
Color
default:"Color::white()"
Tint applied to the fog as fragments recede into the distance.
intensity
float
default:"0.0f"
Density of the fog; larger values cause quicker fade-out.

VolumetricLighting Structure

Settings used when simulating volumetric light shafts.
enabled
bool
default:"false"
Whether volumetric lighting is enabled.
density
float
default:"0.3f"
Overall density of the participating medium.
weight
float
default:"0.01"
Strength of each iterative sample along the ray march.
decay
float
default:"0.95"
Damping factor applied per step to soften distant contributions.
exposure
float
default:"0.6f"
Exposure applied after integrating scattered light.

LightBloom Structure

Configuration values for bloom post-processing.
radius
float
default:"0.008f"
Radius of the blur kernel applied to bright fragments.
maxSamples
int
default:"5"
Maximum number of blur passes performed.

RimLight Structure

Settings for rim lighting, accentuating silhouettes opposite the camera.
intensity
float
default:"0.0f"
Strength of the rim contribution.
color
Color
default:"Color::white()"
Color applied to the rim highlight.

Example Usage

Basic Scene Setup

class GameScene : public Scene {
public:
    void initialize(Window &window) override {
        // Set up ambient lighting
        setAmbientIntensity(0.5f);
        
        // Create and add a directional light (sun)
        DirectionalLight sunLight;
        sunLight.direction = {-0.5f, -1.0f, -0.3f};
        sunLight.color = Color::white();
        sunLight.intensity = 1.0f;
        addDirectionalLight(&sunLight);
        
        // Add point lights
        Light pointLight;
        pointLight.position = {0.0f, 5.0f, 0.0f};
        pointLight.color = Color(1.0f, 0.8f, 0.6f);
        pointLight.intensity = 10.0f;
        addLight(&pointLight);
        
        // Set up skybox
        auto skybox = std::make_shared<Skybox>();
        // Configure skybox...
        setSkybox(skybox);
    }
    
    void update(Window &window) override {
        // Update scene logic each frame
        float time = window.getTime();
        // Animate lights, objects, etc.
    }
    
    void onMouseMove(Window &window, Movement2d movement) override {
        // Handle mouse input for camera control
        Camera* camera = window.getCamera();
        if (camera) {
            camera->updateLook(window, movement);
        }
    }
};

Environmental Effects

class AtmosphericScene : public Scene {
public:
    void initialize(Window &window) override {
        // Configure environment
        Environment env;
        
        // Set up fog
        env.fog.color = Color(0.7f, 0.8f, 0.9f);
        env.fog.intensity = 0.02f;
        
        // Enable volumetric lighting
        env.volumetricLighting.enabled = true;
        env.volumetricLighting.density = 0.3f;
        env.volumetricLighting.weight = 0.01f;
        env.volumetricLighting.decay = 0.95f;
        env.volumetricLighting.exposure = 0.6f;
        
        // Configure bloom
        env.lightBloom.radius = 0.008f;
        env.lightBloom.maxSamples = 5;
        
        // Set rim lighting
        env.rimLight.intensity = 0.5f;
        env.rimLight.color = Color(0.8f, 0.9f, 1.0f);
        
        setEnvironment(env);
        
        // Enable automatic ambient from skybox
        setAutomaticAmbient(true);
    }
};

Atmosphere Skybox

class DynamicSkyScene : public Scene {
public:
    void initialize(Window &window) override {
        // Configure atmospheric parameters
        atmosphere.sunDirection = {0.0f, 0.5f, 1.0f};
        atmosphere.rayleighScattering = {5.8e-6f, 13.5e-6f, 33.1e-6f};
        atmosphere.mieScattering = 21e-6f;
        
        // Use atmosphere-generated skybox
        setUseAtmosphereSkybox(true);
    }
    
    void update(Window &window) override {
        // Animate sun direction for day/night cycle
        float time = window.getTime();
        atmosphere.sunDirection.y = sin(time * 0.1f);
    }
};

Build docs developers (and LLMs) love