Rainbow — Architecture

Parent: Rainbow

Purpose

CPU renderer of sunlight scattered by individual spherical water droplets in waterfall spray. A bounded homogeneous cloud is the baseline. Particle scattering generates the rainbow; no screen-space colour bands are painted onto the cloud.

Components

C++20 numerical core, OpenMP for shared-memory work, CMake and Ninja build. Components: configuration and validation; optical properties and scattering solver; versioned scattering-table cache; particle generation; camera projection and radiometry; tile renderer; linear image merge and output; independent-job runner.

Optical contract

The solver returns differential scattering cross-section S(a,lambda,theta)=d sigma/d Omega in m^2/sr, plus scattering and extinction cross-sections in m^2. Radius is explicitly distinguished from diameter. Incoming and outgoing propagation vectors define theta=acos(dot(k_in,k_out)); forward is zero and the primary rainbow is near 138 degrees. Relative complex refractive index and the surrounding-medium wavelength use explicit consistent conventions.

Lorenz-Mie scattering is the spherical-droplet reference. Geometric optics checks rainbow angles and explains ray paths. The solver uses stable recurrences and convergence control; direct reference evaluations remain available alongside interpolation. Scalar unpolarized intensity is the initial observable; polarization-resolved transport and nonspherical droplets require explicit extensions.

Sun and colour

Point and finite-disc Sun models are selectable, with source spectrum, intensity and angular radius specified independently. Solar-disc integration is performed on linear scattering intensities. Spectral reference rendering integrates wavelength-resolved light against XYZ colour-matching functions. For fixed illumination, response and wavelength-independent path factors, a derived radius-angle XYZ table accelerates rendering. Spectral attenuation disables this shortcut unless equivalence is demonstrated.

Particles and radiometry

Each particle has stable ID, position, radius and weight, with velocity when motion is enabled. Physical mode represents one droplet per particle and derives the population from density and cloud volume under a declared fixed-count or Poisson population rule. Weighted mode uses M computational samples with weight N*V/M, where N is number density. It preserves mean radiance, not physical fluctuation variance. Intensity adds between independent droplets; internal droplet interference remains in the optical model.

Unresolved-droplet camera power is proportional to source-integrated differential cross-section times projected entrance-pupil solid angle A*cos(gamma)/R^2 and particle weight. The far-field and unresolved-droplet assumptions are checked against the selected geometry. Normalized point-spread functions conserve collected energy. Film response integrates over pixel area and exposure. Motion integration reevaluates angle, colour and brightness along trajectories, rather than drawing uniformly coloured endpoint streaks.

Transport and limits

Baseline transport is optically thin single scattering. A separate homogeneous-attenuation mode uses wavelength-dependent Beer-Lambert factors on incoming and outgoing cloud segments, with extinction derived from the same radius distribution and cross-sections. It models mean extinction, not individual neighbour shadows. Multiple scattering is outside the initial implementation; configurations outside the validity of the selected approximation receive quantified optical-depth diagnostics. No generic haze is added that double-counts the droplet contribution.

Outputs

Store linear HDR XYZ or linear RGB image data, exposure-controlled preview, diagnostics, and run manifest. Record output chromaticities and conversion matrices. Merge linear accumulators before tone mapping. Background radiance is added exactly once and attenuated consistently when applicable.

Related design

Configuration and tunable parameters

CPU and multi-machine execution

References

Physically-Based Simulation of Rainbows

Camera measurement and spectral colour

version 1  ·  created 2026-10-16  ·  updated 2026-10-16