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.
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.
The window in which the scene is being rendered.
onMouseMove
virtual void onMouseMove(Window &window, Movement2d movement);
Function that handles mouse movement events.
The window in which the scene is being rendered.
virtual void onMouseScroll(Window &window, Movement2d offset);
Function that handles mouse scroll events.
The window in which the scene is being rendered.
Ambient Lighting
setAmbientIntensity
void setAmbientIntensity(float intensity);
Sets the intensity of the ambient light in the scene.
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.
Whether to enable automatic ambient sampling.
isAutomaticAmbientEnabled
bool isAutomaticAmbientEnabled() const;
Returns whether automatic ambient sampling is enabled.
True if automatic ambient is enabled.
getAutomaticAmbientColor
Color getAutomaticAmbientColor() const;
Gets the ambient color computed from the skybox when automatic ambient is active.
The automatic ambient color.
getAutomaticAmbientIntensity
float getAutomaticAmbientIntensity() const;
Gets the intensity derived from the skybox when automatic ambient is active.
The automatic ambient intensity.
getAmbientColor
Color getAmbientColor() const;
Returns the manually configured ambient light color.
getAmbientIntensity
float getAmbientIntensity() const;
Returns the manually configured ambient intensity.
Light Management
addDirectionalLight
void addDirectionalLight(DirectionalLight *light);
Function that adds a directional light to the scene.
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.
The light object must be valid during the entire scene lifetime.
addSpotlight
void addSpotlight(Spotlight *light);
Function that adds a spotlight to the scene.
The light object must be valid during the entire scene lifetime.
addAreaLight
void addAreaLight(AreaLight *light);
Adds an area light to the scene.
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.
getSkybox
std::shared_ptr<Skybox> getSkybox() const;
Gets 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().
Whether to use the atmosphere-generated skybox.
isUsingAtmosphereSkybox
bool isUsingAtmosphereSkybox() const;
Returns whether the atmosphere-generated skybox is currently used.
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.
The atmosphere-generated skybox.
getAtmosphereSkybox
std::shared_ptr<Skybox> getAtmosphereSkybox() const;
Returns the internally stored atmosphere-generated skybox.
The atmosphere-generated skybox.
Environment Configuration
setEnvironment
void setEnvironment(Environment newEnv);
Overrides the environmental rendering configuration for the scene.
The new environment settings.
Properties
Atmosphere configuration for the scene.
Environment Class
Aggregates configurable environmental effects such as fog and bloom.
Properties
Fog parameters that softly blend distant geometry with the sky.
Controls for volumetric light scattering.
Configures bloom radii and blur passes.
Rim lighting intensity and tint.
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.
Density of the fog; larger values cause quicker fade-out.
VolumetricLighting Structure
Settings used when simulating volumetric light shafts.
Whether volumetric lighting is enabled.
Overall density of the participating medium.
Strength of each iterative sample along the ray march.
Damping factor applied per step to soften distant contributions.
Exposure applied after integrating scattered light.
LightBloom Structure
Configuration values for bloom post-processing.
Radius of the blur kernel applied to bright fragments.
Maximum number of blur passes performed.
RimLight Structure
Settings for rim lighting, accentuating silhouettes opposite the camera.
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);
}
};