Inside the companion
First Light
Make your first CPU image, rasterize triangles, and trace an allocation budget.
Project files 15
Name the scene values
Vectors, camera, lights, shapes, limits, and scene-validation interfaces.
#pragma once
#include <cstddef>
#include <cstdint>
#include <expected>
#include <string>
#include <vector>
namespace prism {
// World-space coordinates. Colors are linear-light RGB, each component in [0, 1].
struct Vec3 { double x{}, y{}, z{}; };
struct Color { double r{}, g{}, b{}; };
struct Camera { Vec3 position; Vec3 look_at; double vertical_fov_degrees{}; };
struct Sphere { Vec3 center; double radius{}; Color color; };
// These values own their strings and containers. References to a Scene borrow it.
struct Scene {
std::uint32_t version{};
std::string title;
std::uint32_t width{}, height{};
Camera camera;
Color background;
Vec3 light_direction; // Direction FROM a surface TOWARD the light.
double ground_y{};
Color ground_color;
std::vector<Sphere> spheres;
};
enum class ErrorCode { invalid_scene, allocation, io };
struct Error {
ErrorCode code;
std::string message; // Fixed diagnostics: never echo arbitrary input or file contents.
};
inline constexpr std::uint32_t max_dimension = 2048;
inline constexpr std::size_t max_pixels = 2'097'152;
inline constexpr std::size_t max_spheres = 32;
inline constexpr std::size_t max_intersection_work = 33'554'432;
[[nodiscard]] Scene demo_scene();
[[nodiscard]] std::expected<void, Error> validate_scene(const Scene& scene);
} // namespace prism
This is the file included with the course. Copy and download give you its complete source.
Taking your work offline? Download all course companions
