Skip to main content

Overview

Atlas provides a comprehensive lighting system with support for ambient, directional, point, spot, and area lights. All light types support shadow mapping and are optimized for GPU rendering with aligned buffer structures.

Light Types

AmbientLight

Ambient light provides uniform illumination across the entire scene.
color
Color
The color of the ambient light reflected into all objects.
intensity
float
The intensity with which the ambient light is applied.

DirectionalLight

Directional lights simulate distant light sources like the sun, with parallel rays.

Constructor

DirectionalLight
constructor
Creates a new directional light.Parameters:
  • dir - Direction vector (will be normalized) (default: {0.0f, -1.0f, 0.0f})
  • color - Light color (default: Color::white())
  • shineColor - Specular highlight color (default: Color::white())
  • intensity - Light intensity (default: 1.0f)

Properties

direction
Magnitude3d
Direction in which the light is pointing (normalized vector).
color
Color
default:"Color::white()"
The color of the light.
shineColor
Color
default:"Color::white()"
The color used for specular highlights.
intensity
float
default:"1.0f"
The light intensity multiplier.
shadowRenderTarget
RenderTarget*
Render target that holds the shadow map (when shadows are enabled).

Methods

setColor
void
Sets the light color.Parameters:
  • color - New color for the light
castShadows
void
Enables shadow casting for this light.Parameters:
  • window - The window in which to cast shadows
  • resolution - Shadow map resolution (default: 4096)

Light (Point Light)

Point lights emit light in all directions from a single point, with distance-based attenuation.

Constructor

Light
constructor
Creates a new point light.Parameters:
  • pos - Position in 3D space (default: {0.0f, 0.0f, 0.0f})
  • color - Light color (default: Color::white())
  • distance - Distance the light reaches (default: 50.0f)
  • shineColor - Specular highlight color (default: Color::white())
  • intensity - Light intensity (default: 1.0f)

Properties

position
Position3d
default:"{0.0f, 0.0f, 0.0f}"
Position of the light in 3D space.
color
Color
default:"Color::white()"
The color of the light.
shineColor
Color
default:"Color::white()"
The color used for specular highlights.
intensity
float
default:"1.0f"
Light intensity multiplier.
distance
float
default:"50.0f"
Distance to which the light reaches.
shadowRenderTarget
RenderTarget*
Render target that holds the shadow cubemap.
debugObject
shared_ptr<CoreObject>
Debug object for visualizing the light in the scene.

Methods

setColor
void
Sets the light color.Parameters:
  • newColor - New color for the light
calculateConstants
PointLightConstants
Calculates attenuation constants for the point light.Returns: Structure containing distance, constant, linear, quadratic, and radius values
castShadows
void
Enables shadow casting for this light.Parameters:
  • window - The window in which to cast shadows
  • resolution - Shadow map resolution (default: 2048)
createDebugObject
void
Creates a debug object to visualize the light in the scene.
addDebugObject
void
Adds the debug object to the window.Parameters:
  • window - The window to add the debug object to

Spotlight

Spotlights emit light in a cone from a specific position and direction.

Constructor

Spotlight
constructor
Creates a new spotlight.Parameters:
  • pos - Position in 3D space (default: {0.0f, 0.0f, 0.0f})
  • dir - Direction vector (default: {0.0f, -1.0f, 0.0f})
  • color - Light color (default: Color::white())
  • angle - Inner cone angle in degrees (default: 35.0f)
  • outerAngle - Outer cone angle in degrees (default: 40.0f)
  • shineColor - Specular highlight color (default: Color::white())
  • intensity - Light intensity (default: 1.0f)
  • range - Light range (default: 50.0f)

Properties

position
Position3d
default:"{0.0f, 0.0f, 0.0f}"
Position of the spotlight in 3D space.
direction
Magnitude3d
default:"{0.0f, -1.0f, 0.0f}"
Direction in which the spotlight is pointing.
color
Color
default:"Color::white()"
The color of the spotlight.
shineColor
Color
default:"Color::white()"
The color used for specular highlights.
intensity
float
default:"1.0f"
Light intensity multiplier.
range
float
default:"50.0f"
Maximum range of the spotlight.
cutOff
float
Inner cone angle of the spotlight (cosine of angle in radians).
outerCutoff
float
Outer cone angle of the spotlight (cosine of angle in radians).
shadowRenderTarget
RenderTarget*
Render target for shadow mapping.
debugObject
shared_ptr<CoreObject>
Debug object for visualizing the spotlight.

Methods

setColor
void
Sets the spotlight color.Parameters:
  • newColor - New color for the spotlight
lookAt
void
Makes the spotlight look at a target position.Parameters:
  • target - Position to look at
castShadows
void
Enables shadow casting.Parameters:
  • window - The window in which to cast shadows
  • resolution - Shadow map resolution (default: 2048)
createDebugObject
void
Creates a debug object to visualize the spotlight.
addDebugObject
void
Adds the debug object to the window.Parameters:
  • window - The window to add the debug object to
updateDebugObjectRotation
void
Updates the rotation of the debug object to match the spotlight direction.

AreaLight

Area lights are rectangular light sources with controllable emission angle and two-sided emission.

Properties

position
Position3d
default:"{0.0, 0.0, 0.0}"
Center position of the rectangular light.
right
Magnitude3d
default:"{1.0, 0.0, 0.0}"
Oriented axis for width direction (normalized).
up
Magnitude3d
default:"{0.0, 1.0, 0.0}"
Oriented axis for height direction (normalized).
size
Size2d
default:"{1.0, 1.0}"
Width and height of the rectangle.
color
Color
default:"Color::white()"
Diffuse/emissive color of the light.
shineColor
Color
default:"Color::white()"
Specular highlight color.
intensity
float
default:"1.0f"
Light intensity multiplier.
range
float
default:"50.0f"
Maximum range of the light.
angle
float
default:"90.0f"
Emission cone half-angle in degrees around the plane normal (90 = hemisphere).
castsBothSides
bool
default:"false"
If true, the light emits on both sides of the rectangle plane.
rotation
Rotation3d
default:"{0.0, 0.0, 0.0}"
Rotation tracking for the area light in degrees.
debugObject
shared_ptr<CoreObject>
Optional debug object for visualizing the area light.
shadowRenderTarget
RenderTarget*
Render target for shadow mapping.

Methods

getNormal
Magnitude3d
Computes the plane normal (normalize(cross(right, up))).Returns: Normalized normal vector
setColor
void
Sets the diffuse color.Parameters:
  • c - New color
setRotation
void
Sets absolute rotation and updates right/up axes accordingly.Parameters:
  • r - Rotation in degrees (roll Z, pitch X, yaw Y)
rotate
void
Applies a delta rotation and updates right/up axes.Parameters:
  • delta - Delta rotation in degrees
createDebugObject
void
Creates a debug object to visualize the area light rectangle.
addDebugObject
void
Adds the debug object to the window.Parameters:
  • window - The window to add the debug object to
castShadows
void
Enables shadow casting.Parameters:
  • window - The window in which to cast shadows
  • resolution - Shadow map resolution (default: 2048)

GPU Buffer Structures

Atlas provides GPU-aligned structures for efficient light data transfer:
  • GPUDirectionalLight - Matches GLSL DirectionalLight struct
  • GPUPointLight - Matches GLSL PointLight struct
  • GPUSpotLight - Matches GLSL SpotLight struct
  • GPUAreaLight - Matches GLSL AreaLight struct
  • GPUShadowParams - Matches GLSL ShadowParameters struct
These structures use alignas(16) to ensure proper GPU memory alignment.

Example Usage

// Create a directional light (sun)
DirectionalLight dirLight({0.0f, -1.0f, 0.0f}, Color::white());
dirLight.setColor(Color(1.0f, 0.95f, 0.8f));
dirLight.castShadows(window);
scene.addDirectionalLight(&dirLight);

// Create a point light
Light pointLight({10.0f, 10.0f, 10.0f}, Color::white(), 50.0f);
pointLight.setColor(Color(1.0f, 0.9f, 0.7f));
pointLight.castShadows(window);
pointLight.createDebugObject();
pointLight.addDebugObject(window);
scene.addPointLight(&pointLight);

// Create a spotlight
Spotlight spotLight({0.0f, 10.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, Color::white(), 30.0f, 35.0f);
spotLight.setColor(Color(0.7f, 0.8f, 1.0f));
spotLight.castShadows(window);
spotLight.lookAt({0.0f, 0.0f, 0.0f});
spotLight.createDebugObject();
spotLight.addDebugObject(window);
scene.addSpotlight(&spotLight);

// Create an area light
AreaLight areaLight;
areaLight.position = {0.0, 5.0, 0.0};
areaLight.size = {2.0, 2.0};
areaLight.setRotation({0.0, 45.0, 0.0});
areaLight.color = Color::white();
areaLight.intensity = 2.0f;
areaLight.castsBothSides = true;
areaLight.createDebugObject();
areaLight.addDebugObject(window);

Build docs developers (and LLMs) love