Scene Management
Scene configuration and preset scenes.
Scene
Scene container managing geometry on GPU.
cpp
class Scene {
public:
Scene();
~Scene();
// Add primitives
void add_sphere(const Sphere& sphere);
void add_plane(const Plane& plane);
void add_material(const Material& material);
void add_light(const PointLight& light);
// Build acceleration structure
void build_bvh();
// GPU intersection
__device__ bool intersect(const ray& r, HitRecord& rec) const;
__device__ bool intersect_any(const ray& r, float t_max) const; // Shadow ray
// Clear scene
void clear();
private:
Sphere* d_spheres_;
Plane* d_planes_;
Material* d_materials_;
PointLight* d_lights_;
BVHNode* d_bvh_nodes_;
int num_spheres_, num_planes_, num_materials_, num_lights_;
};SceneBuilder
Helper class for constructing scenes.
cpp
class SceneBuilder {
public:
SceneBuilder& with_sphere(const vec3& center, float radius, int material_id);
SceneBuilder& with_plane(const vec3& point, const vec3& normal, int material_id);
SceneBuilder& with_material(const Material& material);
SceneBuilder& with_light(const vec3& position, const vec3& color);
Scene build();
};Preset Scenes
cpp
// Demo scene: 8 spheres + ground plane, multiple materials, 3 lights
Scene create_demo_scene();
// Cornell box: 6 walls as planes, 2 spheres, 1 light
Scene create_cornell_box();
// Random spheres: procedurally generated ~100 spheres
Scene create_random_scene(int num_spheres = 100);PointLight
Light source definition.
cpp
struct PointLight {
vec3 position;
vec3 color;
float intensity;
};Usage Example
cpp
// Using preset
Scene scene = create_demo_scene();
scene.build_bvh();
// Custom scene
SceneBuilder builder;
builder
.with_material(Material::matte(vec3(0.8f, 0.2f, 0.2f)))
.with_sphere(vec3(0, 0, 0), 1.0f, 0)
.with_light(vec3(5, 5, 5), vec3(1, 1, 1));
Scene custom_scene = builder.build();
// Render
Renderer renderer(800, 600);
renderer.set_scene(scene);
renderer.set_mode(RenderMode::Phong);
renderer.render();
renderer.save_ppm("output.ppm");Scene File Format (Planned)
json
{
"spheres": [
{"center": [0, 0, 0], "radius": 1.0, "material": 0}
],
"materials": [
{"type": "matte", "albedo": [0.8, 0.2, 0.2]}
],
"lights": [
{"position": [5, 5, 5], "color": [1, 1, 1]}
]
}