Theme Catppuccin
Make yourself at homeCatppuccin

A softer light for long learning sessions.

Appearance

Loading your preference…

Dark palette

Choose a dark palette to try it.

Light uses Latte. Your choices stay in this browser.

Back to your source shelf

Inside the companion

Light Transport

Build a diffuse CPU path renderer and inspect its sampling, geometry, and tests.

Project files 11

Compare an estimate with pi

Run a sampling estimate and query a small scene index from the command line.

21 lines experiment.cpp
#include "lantern.hpp"
#include <exception>
#include <iostream>
#include <numbers>

int main() {
    try {
        const auto integral=lantern::cosine_integral(65536,42);
        if (!integral) { std::cerr << integral.error().message << '\n'; return 1; }
        const std::vector<lantern::Sphere> spheres{{1,{0,0,0},1},{2,{3,0,0},0.5},{3,{-3,0,0},0.5}};
        const auto index=lantern::SceneIndex::build(spheres);
        if (!index) { std::cerr << index.error().message << '\n'; return 1; }
        const auto hit=index->closest({{0,0,4},{0,0,-1}});
        if (!hit || !*hit) { std::cerr << "Expected a central hit.\n"; return 1; }
        std::cout << "Uniform hemisphere estimate: " << *integral << " (analytic pi = " << std::numbers::pi
                  << ")\nBVH nodes: " << index->node_count() << "\nCentral hit id: " << (*hit)->id
                  << ", distance: " << (*hit)->distance << '\n';
        return 0;
    } catch (const std::exception&) { std::cerr << "CPU experiment could not complete.\n"; return 1; }
}

This is the file included with the course. Copy and download give you its complete source.

Taking your work offline? Download all course companions