moon-ray

    A Monte Carlo path tracing renderer in pure MoonBit — OSC 2026

    ray-tracing
    path-tracing
    graphics
    rendering
    PBR
    Download zip
    Version
    0.3.1
    License
    Apache-2.0
    Last updated
    last month
    Downloads
    32

    #moon-ray

    Pure MoonBit Monte Carlo Path Tracer

    CI License MoonBit mooncakes.io

    2026 MoonBit Open Source Ecosystem Competition

    ─────────────────────

    A physically-based rendering engine written entirely in MoonBit. 8 geometry types, 7 PBR materials, BVH acceleration, procedural textures, volume rendering, post-processing, and an interactive web GUI.

    ─────────────────────

    moon-ray 是一个纯 MoonBit 实现的蒙特卡洛路径追踪渲染器, 2026 MoonBit 国产基础软件开源大赛 参赛项目。

    基于物理渲染(PBR)理论,从零实现了完整的 Monte Carlo 光线追踪管线。 支持 8 种几何体类型、7 种物理材质、BVH 加速结构、程序化纹理生成、 体积渲染(雾/烟)、后处理特效链以及交互式 Web 图形界面。

    内置 13 个演示场景,覆盖经典三球、Cornell Box、材质对比、景深虚化、 大气雾效等效果。项目搭载完整 CI/CD 流水线,32 个单元测试全部通过, 已发布至 mooncakes.io 生态。


    #Features / 功能特性

    #Rendering / 渲染管线

    • Monte Carlo Path Tracing — Full global illumination with recursive ray bounces
    • Russian Roulette Termination — Unbiased early termination for performance
    • Next Event Estimation — Direct light importance sampling with MIS
    • Gamma & sRGB Correction — Physically accurate color output

    • 蒙特卡洛路径追踪 — 递归光线弹射,模拟完整全局光照
    • 俄罗斯轮盘赌终止 — 无偏的早期路径终止,提升渲染效率
    • 次事件估计 (NEE) — 对光源直接采样,配合多重重要性采样 (MIS)
    • Gamma/sRGB 校正 — 物理准确的色彩输出

    #Geometry / 几何体 (8 Types)

    Type / 类型File / 文件Description / 描述
    Sphere / 球体geometry_sphere.mbtRay-sphere intersection
    Plane / 平面geometry_plane.mbtInfinite plane
    Triangle / 三角形geometry_triangle.mbtMöller–Trumbore algorithm
    Box / 盒子geometry_box.mbtAxis-aligned cuboid
    Cylinder / 圆柱geometry_cylinder.mbtY-axis aligned
    Disk / 圆盘geometry_disk.mbtFlat circular disk
    Cone / 圆锥geometry_cone.mbtTapered cone with base cap
    Torus / 圆环geometry_torus.mbtNewton's method solver
    Mesh / 网格geometry_mesh.mbtTriangle mesh with builders

    #Materials / 材质 (7 Types)

    Material / 材质Description / 描述
    LambertianIdeal diffuse (matte) surfaces / 理想漫反射
    MetalSpecular reflection with fuzz / 金属反射(可调粗糙度)
    DielectricGlass/water with Schlick Fresnel / 电介质(玻璃/水/钻石)
    EmissiveLight source (HDR) / 自发光光源
    DiffuseLightTextured area light / 纹理区域光
    IsotropicVolume-like scattering / 各向同性散射
    TexturedDull surface with texture mapping / 纹理映射哑光表面

    #Acceleration / 加速结构

    • BVH (Bounding Volume Hierarchy) — Recursive spatial partitioning

    #Textures / 纹理

    • Solid — Uniform color
    • Checker — Procedural checkerboard with configurable scale
    • Noise — Hash-based procedural noise
    • Image — Bitmap texture sampling

    #Camera / 相机

    • Configurable look-from, look-at, FOV, aperture (depth of field), motion blur
    • Keyframe animation paths with Catmull-Rom interpolation and easing functions

    #Post-Processing / 后处理

    • Tone Mapping — Reinhard, ACES filmic, gamma correction
    • Bloom — Gaussian blur on highlights
    • Vignette — Edge darkening
    • Film Grain — Procedural noise overlay
    • Denoising — Edge-aware bilateral filter (stub)

    #Output / 输出格式

    • PPM — ASCII text (pipe to stdout)
    • BMP — 24-bit uncompressed binary

    #Environment / 环境光

    • Gradient sky, Hosek-Wilkie sky model, black-body radiation, sun direction

    #Volume / 体积渲染

    • Ray marching through constant-density volumes
    • Exponential fog, layered fog, Beer-Lambert absorption


    #Quick Start / 快速开始

    #Prerequisites

    Install the MoonBit toolchain: https://www.moonbitlang.cn/download/

    #Build & Test / 构建与测试

    git clone git@github.com:Kai-Junhan/moon-ray.git cd moon-ray moon check # Syntax check — 0 errors / 语法检查 moon test # Unit tests — 32/32 pass / 单元测试 moon build # Compile / 编译

    #Render / 渲染

    # Default scene: Three Spheres (400×225, 100 spp) # 默认场景:三球 (400×225, 100 spp) moon run cmd/main > output.ppm # Run full test suite / 运行完整测试套件 powershell -File test.ps1

    #Web GUI / 图形界面

    python gui/server.py # Open http://localhost:8088 # Or use the PowerShell launcher / 或使用 PowerShell 启动 powershell -File gui.ps1

    The GUI features: scene selector, parameter sliders, quick presets, live PPM preview.

    图形界面功能:场景选择器、参数滑动条、快速预设级别(低/中/高/超高)、实时 PPM 预览。


    #Demo Scenes / 演示场景 (18 Total)

    #Scene / 场景KeyDescription / 描述
    1three_spheresClassic / 经典Diffuse + Metal + Glass
    2cornell_boxGI Test / 全局光Spherical light box
    3material_showcaseMaterials / 材质4 Lamberts + 4 Metals + 3 Dielectrics
    4random_spheresStress / 压力121 random objects
    5geometricMulti-Geo / 多几何体Boxes, cylinders, disks, checker floor
    6cornell_box_planesPlanar / 平面Plane-based Cornell box
    7texture_demoTextures / 纹理Checker & noise spheres
    8triangle_demoTriangles / 三角Colored triangle banners
    9final_demoShowcase / 展示121 mixed shapes + DOF
    10full_geometryAll Types / 全类型Every geometry type on display
    11studio_lightingLighting / 布光Three-point studio light setup
    12depth_of_fieldDOF / 景深Aperture blur on metal spheres
    13foggy_sceneVolume / 大气Atmospheric fog effect
    14mirror_corridorMirror / 镜面Infinite reflection corridor
    15crystal_gardenCrystal / 水晶Glass prisms with colored lights
    16sunrise_valleyLandscape / 风景Stone monoliths at dawn
    17prism_labIOR Lab / 折射6 dielectric prisms (water→diamond)
    18city_at_nightCity / 城市Skyline with emissive windows


    #Project Structure / 项目结构

    moon-ray/ ├── .github/workflows/ci.yml # GitHub Actions CI ├── .githooks/pre-commit # Git pre-commit hook ├── gui/ # Web GUI (HTML/CSS/JS + Python server) ├── cmd/main/ # CLI entry point / CLI 入口 │ ├── math_*.mbt # Math: Vec3, Ray, RNG, AABB, ONB, Perlin ├── geometry_*.mbt # Geometry: Sphere, Plane, Triangle, Box, │ # Cylinder, Disk, Cone, Torus, Mesh, Hit ├── texture_base.mbt # Texture enum / 纹理枚举 ├── material.mbt # Material enum (7 types) / 材质枚举 ├── camera.mbt # Camera model + defocus blur / 相机+景深 ├── renderer.mbt # Path tracing core / 路径追踪核心 ├── render_sampling.mbt # Advanced sampling / 高级采样 ├── render_config.mbt # Render parameter management / 渲染配置 │ ├── bvh.mbt # BVH acceleration / BVH 加速 ├── animation.mbt # Keyframe camera / 关键帧动画 ├── environment.mbt # Sky & black-body / 天空模型 ├── tone_mapping.mbt # Reinhard/ACES/gamma / 色调映射 ├── volume_render.mbt # Fog & media / 体积渲染 ├── post_process.mbt # Bloom/vignette/denoise / 后处理 ├── scene_loader.mbt # Scene builder API / 场景构建 │ ├── demo_scenes.mbt # Preset scenes × 4 / 预设场景 ├── demo_extra.mbt # Extended scenes × 5 / 扩展场景 ├── demo_extra2.mbt # Extended scenes × 4 / 扩展场景 ├── demo_extra3.mbt # Advanced scenes × 5 / 高级场景 │ ├── output_ppm.mbt # PPM output / PPM 输出 ├── output_bmp.mbt # BMP output / BMP 输出 │ ├── *_test.mbt # Tests × 5 (32 cases) / 测试 ├── moon.mod / moon.pkg # Package config / 包配置 ├── test.ps1 / gui.ps1 # Helper scripts / 辅助脚本 ├── README.md └── LICENSE # Apache 2.0


    #CI/CD / 持续集成

    On every push, GitHub Actions automatically runs / 每次推送自动执行:

    StepStatus
    moon check✅ 0 errors / 零错误
    moon test✅ 32/32 pass / 全部通过
    moon build✅ Build successful / 编译成功
    Render test✅ PPM validation / PPM 格式验证


    #Testing / 测试

    moon test # 32 tests, all passing / 32 个测试全部通过

    Coverage includes: Vec3 operations, ray-point computation, AABB hit/miss, RNG determinism, all 8 geometry types, material emission/scattering, texture evaluation, tone mapping, camera rays, BMP output, scene construction, animation interpolation, and volume fog.

    测试覆盖:Vec3 运算、光线求交、AABB 碰撞、随机数确定性、全部 8 种几何体、 材质发射/散射、纹理采样、色调映射、相机光线、BMP 输出、场景构建、 动画插值和体积雾效。


    #Packages / 包管理

    Published on mooncakes.io — importable as / 可在 mooncakes.io 获取:

    import "Kai-Junhan/moon-ray"


    #References / 参考资料

    • Ray Tracing in One Weekend — Peter Shirley
      • License: CC0 1.0 Universal (Public Domain Dedication)
      • Scope: Core ray-sphere intersection, basic Lambertian/Metal/Dielectric material scattering, pinhole camera model, and recursive path tracing structure. All concepts re-implemented in idiomatic MoonBit and significantly extended.

    • Physically Based Rendering — Matt Pharr, Wenzel Jakob, Greg Humphreys
      • License: MIT License
      • Scope: Conceptual reference for Next Event Estimation (NEE), Multiple Importance Sampling (MIS), BVH spatial partitioning with SAH, and physically-based tone mapping theory.

    All MoonBit source code is an original implementation. The following features are independent additions beyond any reference work: 8 geometry types (Plane, Triangle, Box, Cylinder, Disk, Cone, Torus, Mesh), 4 additional material types (DiffuseLight, Isotropic, Textured, Emissive), BVH acceleration structure, procedural texture system (Checker, Noise, Image), volume rendering (exponential/layered fog, Beer-Lambert), post-processing pipeline (bloom, vignette, film grain, denoising), keyframe animation system with easing functions, scene builder API, and interactive web GUI.


    #License / 许可证

    Apache License 2.0 — See LICENSE for details.


    Built with MoonBit for the 2026 Open Source Ecosystem Competition

    ★ Star on GitHub · Gitlink · mooncakes.io

    AABB

    pub(all) struct AABB {
    min : Vec3
    max : Vec3
    } derive(
    Debug
    )

    Axis-Aligned Bounding Box for ray intersection acceleration.

    AABB::hit

    fn AABB::hit(self : AABB, r : Ray, t_min~ : Double, t_max~ : Double) -> Bool

    AABB::new

    fn AABB::new(min~ : Vec3, max~ : Vec3) -> AABB

    BVHNode

    BVH (Bounding Volume Hierarchy) with recursive traversal. Builds a spatial partition tree and integrates with HitableList.

    BoxShape

    pub(all) struct BoxShape {
    center : Vec3
    size : Vec3
    material : Material
    } derive(
    Debug
    )

    Axis-aligned box geometry (cuboid).

    BoxShape::hit_box

    fn BoxShape::hit_box(self : BoxShape, r : Ray, t_min~ : Double, t_max~ : Double) -> HitRecord?

    BoxShape::new

    fn BoxShape::new(center~ : Vec3, size~ : Vec3, material~ : Material) -> BoxShape

    Camera

    pub(all) struct Camera {
    origin : Vec3
    lower_left_corner : Vec3
    horizontal : Vec3
    vertical : Vec3
    u : Vec3
    v : Vec3
    w : Vec3
    lens_radius : Double
    time0 : Double
    time1 : Double
    } derive(
    Debug
    )

    Camera model with configurable position, look-at, and defocus blur.

    Camera::default

    fn Camera::default(aspect_ratio~ : Double) -> Camera

    Camera::get_ray

    fn Camera::get_ray(self : Camera, s : Double, t : Double) -> Ray

    Camera::new

    fn Camera::new(lookfrom~ : Vec3, lookat~ : Vec3, vup~ : Vec3, vfov~ : Double, aspect_ratio~ : Double, aperture~ : Double, focus_dist~ : Double, time0~ : Double, time1~ : Double) -> Camera

    Cone

    pub(all) struct Cone {
    base_center : Vec3
    base_radius : Double
    apex : Vec3
    height : Double
    material : Material
    } derive(
    Debug
    )

    Cone geometry tapered along the Y-axis. Defined by base center, base radius, apex point (tip), and height.

    Cone::hit_cone

    fn Cone::hit_cone(self : Cone, r : Ray, t_min~ : Double, t_max~ : Double) -> HitRecord?

    Cone::new

    fn Cone::new(base_center~ : Vec3, base_radius~ : Double, height~ : Double, material~ : Material) -> Cone

    Cylinder

    pub(all) struct Cylinder {
    center : Vec3
    radius : Double
    height : Double
    material : Material
    } derive(
    Debug
    )

    Cylinder geometry aligned along the Y-axis.

    Cylinder::hit_cylinder

    fn Cylinder::hit_cylinder(self : Cylinder, r : Ray, t_min~ : Double, t_max~ : Double) -> HitRecord?

    Cylinder::new

    fn Cylinder::new(center~ : Vec3, radius~ : Double, height~ : Double, material~ : Material) -> Cylinder

    Disk

    pub(all) struct Disk {
    center : Vec3
    normal : Vec3
    radius : Double
    material : Material
    } derive(
    Debug
    )

    Disk geometry (flat circular disk).

    Disk::hit_disk

    fn Disk::hit_disk(self : Disk, r : Ray, t_min~ : Double, t_max~ : Double) -> HitRecord?

    Disk::new

    fn Disk::new(center~ : Vec3, normal~ : Vec3, radius~ : Double, material~ : Material) -> Disk

    Environment

    pub(all) enum Environment {
    Gradient(Vec3, Vec3)
    Constant(Vec3)
    HDRISky(Double, Double, Double)
    } derive(
    Debug
    )

    Environment lighting and sky models. Supports gradient sky, Hosek-Wilkie sky model, and constant color environment.

    Environment::constant

    fn Environment::constant(color~ : Vec3) -> Environment

    Environment::default_sky

    fn Environment::default_sky() -> Environment

    Environment::sample

    fn Environment::sample(self : Environment, dir : Vec3) -> Vec3

    Environment::sample_importance

    fn Environment::sample_importance(self : Environment, rng : Rng, normal : Vec3) -> (Vec3, Rng, Double)

    HitRecord

    pub(all) struct HitRecord {
    p : Vec3
    normal : Vec3
    t : Double
    front_face : Bool
    material : Material
    } derive(
    Debug
    )

    HitRecord::set_face_normal

    fn HitRecord::set_face_normal(self : HitRecord, r : Ray, outward_normal : Vec3) -> HitRecord

    Hitable

    pub(all) enum Hitable {
    Sphere(Sphere)
    Plane(Plane)
    Triangle(Triangle)
    BoxShape(BoxShape)
    Cylinder(Cylinder)
    Disk(Disk)
    Cone(Cone)
    Torus(Torus)
    } derive(
    Debug
    )

    Hitable geometry with BVH-accelerated hit testing.

    Hitable::bounding_box

    fn Hitable::bounding_box(self : Hitable) -> AABB

    Hitable::hit

    fn Hitable::hit(self : Hitable, r : Ray, t_min~ : Double, t_max~ : Double) -> HitRecord?
    Per-object hit test.

    Hitable::match_material

    fn Hitable::match_material(self : Hitable, u : Double, v : Double, p : Vec3) -> Vec3

    HitableList

    pub(all) struct HitableList {
    objects : Array[Hitable]
    bvh_ready : Bool
    } derive(
    Debug
    )
    World with optional BVH acceleration.

    HitableList::add

    fn HitableList::add(self : HitableList, object : Hitable) -> HitableList

    HitableList::build_bvh

    fn HitableList::build_bvh(self : HitableList) -> HitableList
    Build BVH acceleration structure. Must be called before rendering for scenes with more than a handful of objects.

    HitableList::hit

    fn HitableList::hit(self : HitableList, r : Ray, t_min~ : Double, t_max~ : Double) -> HitRecord?
    BVH-accelerated hit. When BVH is built, uses hierarchical traversal. Otherwise falls back to linear scan.

    HitableList::new

    Keyframe

    pub(all) struct Keyframe {
    time : Double
    position : Vec3
    lookat : Vec3
    } derive(
    Debug
    )

    Animation support for camera paths and object transforms. Keyframe interpolation using Catmull-Rom and linear splines.

    Keyframe::new

    fn Keyframe::new(time~ : Double, position~ : Vec3, lookat~ : Vec3) -> Keyframe

    Material

    pub(all) enum Material {
    Lambertian(Vec3)
    Metal(Vec3, Double)
    Dielectric(Double)
    Emissive(Vec3)
    DiffuseLight(Texture)
    Isotropic(Vec3)
    Textured(Texture)
    } derive(
    Debug
    )

    Material system for ray tracing using an enum to dispatch on material type.

    Material::albedo_at

    fn Material::albedo_at(self : Material, u : Double, v : Double, p : Vec3) -> Vec3

    Material::emitted

    fn Material::emitted(self : Material, u : Double, v : Double, p : Vec3) -> Vec3
    Get emitted light from a material.

    Material::scatter

    fn Material::scatter(self : Material, r_in : Ray, rec : HitRecord) -> ScatterResult?
    Scatter a ray off a material.

    Mesh

    pub(all) struct Mesh {
    vertices : Array[Vec3]
    indices : Array[(Int, Int, Int)]
    material : Material
    } derive(
    Debug
    )

    Mesh geometry from triangle collections. Supports building from indexed vertex and face arrays.

    Mesh::add_triangle

    fn Mesh::add_triangle(self : Mesh, i0 : Int, i1 : Int, i2 : Int) -> Mesh

    Mesh::add_vertex

    fn Mesh::add_vertex(self : Mesh, v : Vec3) -> Mesh

    Mesh::build_cube

    fn Mesh::build_cube(center~ : Vec3, size~ : Double, material~ : Material) -> Mesh

    Mesh::build_uv_sphere

    fn Mesh::build_uv_sphere(center~ : Vec3, radius~ : Double, segments~ : Int, rings~ : Int, material~ : Material) -> Mesh

    Mesh::new

    fn Mesh::new(material~ : Material) -> Mesh

    ONB

    pub(all) struct ONB {
    u : Vec3
    v : Vec3
    w : Vec3
    } derive(
    Debug
    )

    Orthonormal Basis (ONB) for importance sampling. Used to transform vectors from tangent space to world space.

    ONB::build_from_w

    fn ONB::build_from_w(normal~ : Vec3) -> ONB

    ONB::local_vec

    fn ONB::local_vec(self : ONB, a : Double, b : Double, c : Double) -> Vec3

    ONB::to_world

    fn ONB::to_world(self : ONB, local_vec : Vec3) -> Vec3

    Perlin

    pub(all) struct Perlin {
    randfloat : Array[Double]
    perm_x : Array[Int]
    perm_y : Array[Int]
    perm_z : Array[Int]
    } derive(
    Debug
    )

    Perlin noise generator for procedural texturing.

    Perlin::new

    fn Perlin::new() -> Perlin

    Perlin::turbulence

    fn Perlin::turbulence(self : Perlin, p : Vec3, depth~ : Int) -> Double

    Plane

    pub(all) struct Plane {
    center : Vec3
    normal : Vec3
    material : Material
    } derive(
    Debug
    )

    Plane geometry: infinite plane defined by center point and normal.

    Plane::hit_plane

    fn Plane::hit_plane(self : Plane, r : Ray, t_min~ : Double, t_max~ : Double) -> HitRecord?

    Plane::new

    fn Plane::new(center~ : Vec3, normal~ : Vec3, material~ : Material) -> Plane

    Ray

    pub(all) struct Ray {
    orig : Vec3
    dir : Vec3
    tm : Double
    } derive(
    Debug
    )

    Ray representation: origin + t * direction.

    Ray::at

    fn Ray::at(self : Ray, t : Double) -> Vec3
    Get point along the ray at parameter t.

    Ray::new

    fn Ray::new(orig? : Vec3, dir? : Vec3, tm? : Double) -> Ray

    RenderConfig

    pub(all) struct RenderConfig {
    scene : String
    width : Int
    height : Int
    samples : Int
    max_depth : Int
    output_format : String
    aperture : Double
    fov : Double
    } derive(
    Debug
    )

    Render configuration and parameter management for GUI integration.

    Rng

    type Rng

    Pseudo-random number generation for Monte Carlo rendering.

    Rng::random_cosine_direction

    fn Rng::random_cosine_direction(self : Rng) -> (Vec3, Rng)
    Cosine-weighted hemisphere sampling (Lambertian).

    Rng::random_double

    fn Rng::random_double(self : Rng) -> (Double, Rng)
    Generate a random Double in [0, 1).

    Rng::random_double_range

    fn Rng::random_double_range(self : Rng, min~ : Double, max~ : Double) -> (Double, Rng)
    Generate a random Double in [min, max).

    Rng::random_in_unit_disk

    fn Rng::random_in_unit_disk(self : Rng) -> (Vec3, Rng)
    Generate a random point inside the unit disk (for defocus blur).

    Rng::random_in_unit_sphere

    fn Rng::random_in_unit_sphere(self : Rng) -> (Vec3, Rng)
    Generate a random point inside the unit sphere (recursive rejection sampling).

    Rng::random_int

    fn Rng::random_int(self : Rng, n : Int) -> (Int, Rng)
    Generate a random integer in [0, n).

    Rng::random_on_hemisphere

    fn Rng::random_on_hemisphere(self : Rng, normal : Vec3) -> (Vec3, Rng)
    Generate a random point on the hemisphere oriented by the given normal.

    Rng::random_unit_vector

    fn Rng::random_unit_vector(self : Rng) -> (Vec3, Rng)
    Generate a random unit vector (on the unit sphere surface, uniform).

    ScatterResult

    pub(all) struct ScatterResult {
    attenuation : Vec3
    scattered : Ray
    } derive(
    Debug
    )
    Result of a ray scattering off a material.

    SceneObject

    pub(all) struct SceneObject {
    shape : String
    center : Vec3
    params : (Double, Double, Double)
    material_name : String
    material_params : (Double, Double, Double)
    } derive(
    Debug
    )

    Scene description system for loading scenes from structured data. Includes a simple scene builder and JSON-like scene representation.

    Sphere

    pub(all) struct Sphere {
    center : Vec3
    radius : Double
    material : Material
    } derive(
    Debug
    )

    Sphere geometry.

    Sphere::new

    fn Sphere::new(center~ : Vec3, radius~ : Double, material~ : Material) -> Sphere

    Texture

    pub(all) enum Texture {
    Solid(Vec3)
    Checker(Texture, Texture, Double)
    Noise(Double)
    Image(Array[Vec3], Int, Int)
    } derive(
    Debug
    )

    Texture system using enum dispatch. Textures map surface coordinates (u, v) and hit points to colors.

    Texture::checker

    fn Texture::checker(even~ : Texture, odd~ : Texture, scale~ : Double) -> Texture

    Texture::noise

    fn Texture::noise(scale~ : Double) -> Texture

    Texture::solid

    fn Texture::solid(color~ : Vec3) -> Texture

    Texture::value

    fn Texture::value(self : Texture, u : Double, v : Double, p : Vec3) -> Vec3

    Torus

    pub(all) struct Torus {
    center : Vec3
    major_radius : Double
    minor_radius : Double
    material : Material
    } derive(
    Debug
    )

    Torus geometry (donut shape) in the XZ plane.

    Torus::hit_torus

    fn Torus::hit_torus(self : Torus, r : Ray, t_min~ : Double, t_max~ : Double) -> HitRecord?

    Torus::new

    fn Torus::new(center~ : Vec3, major_radius~ : Double, minor_radius~ : Double, material~ : Material) -> Torus

    Triangle

    pub(all) struct Triangle {
    v0 : Vec3
    v1 : Vec3
    v2 : Vec3
    material : Material
    } derive(
    Debug
    )

    Triangle geometry using Moller-Trumbore intersection.

    Triangle::hit_triangle

    fn Triangle::hit_triangle(self : Triangle, r : Ray, t_min~ : Double, t_max~ : Double) -> HitRecord?

    Triangle::new

    fn Triangle::new(v0~ : Vec3, v1~ : Vec3, v2~ : Vec3, material~ : Material) -> Triangle

    Vec3

    pub(all) struct Vec3 {
    x : Double
    y : Double
    z : Double
    } derive(
    Debug
    )

    3D vector math operations for ray tracing.
    impl Add for Vec3
    impl Mul for Vec3
    impl Neg for Vec3
    impl Sub for Vec3

    Vec3::cross

    fn Vec3::cross(self : Vec3, other : Vec3) -> Vec3

    Vec3::div_scalar

    fn Vec3::div_scalar(self : Vec3, t : Double) -> Vec3

    Vec3::dot

    fn Vec3::dot(self : Vec3, other : Vec3) -> Double

    Vector operations

    Vec3::length

    fn Vec3::length(self : Vec3) -> Double

    Vec3::length_squared

    fn Vec3::length_squared(self : Vec3) -> Double

    Vec3::lerp

    fn Vec3::lerp(self : Vec3, other : Vec3, t : Double) -> Vec3
    Linear interpolation

    Vec3::max

    fn Vec3::max(self : Vec3, other : Vec3) -> Vec3
    Component-wise maximum

    Vec3::min

    fn Vec3::min(self : Vec3, other : Vec3) -> Vec3
    Component-wise minimum

    Vec3::mul_scalar

    fn Vec3::mul_scalar(self : Vec3, t : Double) -> Vec3

    Scalar operations

    Vec3::near_zero

    fn Vec3::near_zero(self : Vec3) -> Bool

    Vec3::new

    fn Vec3::new(x~ : Double, y~ : Double, z~ : Double) -> Vec3

    Vec3::normalize

    fn Vec3::normalize(self : Vec3) -> Vec3

    VolumeBox

    pub(all) struct VolumeBox {
    min_point : Vec3
    max_point : Vec3
    density : Double
    albedo : Vec3
    } derive(
    Debug
    )

    Participating media (volume rendering) support. Simulates fog, smoke, and volumetric scattering through ray marching.

    VolumeBox::new

    fn VolumeBox::new(min_point~ : Vec3, max_point~ : Vec3, density~ : Double, albedo~ : Vec3) -> VolumeBox

    aces_tone_map

    fn aces_tone_map(color : Vec3) -> Vec3

    apply_bloom

    fn apply_bloom(pixels : Array[Vec3], width : Int, height : Int, threshold~ : Double, intensity~ : Double) -> Array[Vec3]

    apply_color_grading

    fn apply_color_grading(pixels : Array[Vec3], width : Int, height : Int, contrast~ : Double, saturation~ : Double, brightness~ : Double, temperature~ : Double) -> Array[Vec3]

    apply_film_grain

    fn apply_film_grain(pixels : Array[Vec3], width : Int, height : Int, intensity~ : Double) -> Array[Vec3]

    apply_vignette

    fn apply_vignette(pixels : Array[Vec3], width : Int, height : Int, strength~ : Double) -> Array[Vec3]

    Post-processing effects: bloom, vignette, color grading, denoising stubs.

    balanced_heuristic

    fn balanced_heuristic(n_f : Double, pdf_f : Double, n_g : Double, pdf_g : Double) -> Double

    beer_lambert_absorption

    fn beer_lambert_absorption(color : Vec3, dist : Double, density : Vec3) -> Vec3

    black_body_radiation

    fn black_body_radiation(temperature : Double) -> Vec3

    bvh_build_from

    fn bvh_build_from(objects : Array[Hitable]) -> BVHNode?
    Build BVH from an array of objects. Returns the root node. Mutates the objects array by sorting for spatial locality.

    bvh_hit

    fn bvh_hit(node : BVHNode, objects : Array[Hitable], r : Ray, t_min~ : Double, t_max~ : Double) -> HitRecord?
    Recursive BVH hit traversal.

    camera_along_path

    fn camera_along_path(keyframes : Array[Keyframe], t : Double) -> (Vec3, Vec3)

    catmull_rom

    fn catmull_rom(v0 : Vec3, v1 : Vec3, v2 : Vec3, v3 : Vec3, t : Double) -> Vec3

    city_at_night_scene

    fn city_at_night_scene() -> (HitableList, Camera)

    cornel_box_scene

    fn cornel_box_scene() -> (HitableList, Camera)

    cornell_box_scene

    fn cornell_box_scene() -> (HitableList, Camera)
    Cornell Box scene - classic test scene for global illumination

    create_orbiting_camera_path

    fn create_orbiting_camera_path(center~ : Vec3, radius~ : Double, height~ : Double, num_frames~ : Int, duration~ : Double) -> Array[Keyframe]

    crystal_garden_scene

    fn crystal_garden_scene() -> (HitableList, Camera)

    default_render_config

    fn default_render_config() -> RenderConfig

    default_rng

    fn default_rng() -> Rng
    Create a new RNG with a default seed.

    depth_of_field_demo

    fn depth_of_field_demo() -> (HitableList, Camera)

    ease_in_out_cubic

    fn ease_in_out_cubic(t : Double) -> Double

    ease_in_out_quad

    fn ease_in_out_quad(t : Double) -> Double

    edge_aware_denoise_stub

    fn edge_aware_denoise_stub(pixels : Array[Vec3], width : Int, height : Int) -> Array[Vec3]

    empty_aabb

    fn empty_aabb() -> AABB

    exponential_fog

    fn exponential_fog(color : Vec3, dist : Double, fog_density : Double, fog_color : Vec3) -> Vec3

    exposure_adjust

    fn exposure_adjust(color : Vec3, exposure : Double) -> Vec3

    final_demo_scene

    fn final_demo_scene() -> (HitableList, Camera)

    foggy_scene_demo

    fn foggy_scene_demo() -> (HitableList, Camera)

    full_geometry_demo

    fn full_geometry_demo() -> (HitableList, Camera)

    Extended demo scenes with all geometry types and advanced effects.

    gamma_correct

    fn gamma_correct(color : Vec3, gamma : Double) -> Vec3

    gaussian_filter

    fn gaussian_filter(x : Double, sigma : Double) -> Double

    geometric_scene

    fn geometric_scene() -> (HitableList, Camera)

    Extended demo scenes using new geometry types and materials.

    interpolate_keyframe

    fn interpolate_keyframe(k1 : Keyframe, k2 : Keyframe, t : Double) -> Keyframe

    layered_fog

    fn layered_fog(color : Vec3, pos_y : Double, fog_base : Double, fog_top : Double, fog_density : Double, fog_color : Vec3) -> Vec3

    list_scenes

    fn list_scenes() -> Array[String]

    make_scene_from_objects

    fn make_scene_from_objects(objects~ : Array[SceneObject], cam_origin~ : Vec3, cam_lookat~ : Vec3, cam_fov~ : Double, cam_aspect~ : Double) -> (HitableList, Camera)

    material_showcase_scene

    fn material_showcase_scene() -> (HitableList, Camera)
    Material showcase scene - demonstrates all material types

    mesh_to_hitable_list

    fn mesh_to_hitable_list(mesh : Mesh) -> HitableList

    mirror_corridor_scene

    fn mirror_corridor_scene() -> (HitableList, Camera)

    Advanced demo scenes for moon-ray. Visually impressive scenes demonstrating the renderer's capabilities.

    motion_blur_sample

    fn motion_blur_sample(time0 : Double, time1 : Double) -> (Double, Double)

    new_rng

    fn new_rng(seed : UInt64) -> Rng
    Create a new RNG with the given seed.

    power_heuristic

    fn power_heuristic(n_f : Double, pdf_f : Double, n_g : Double, pdf_g : Double, beta~ : Double) -> Double

    prism_lab_scene

    fn prism_lab_scene() -> (HitableList, Camera)

    random_spheres_scene

    fn random_spheres_scene() -> (HitableList, Camera)
    Random spheres scene - similar to "Ray Tracing in One Weekend"

    ray_march_volume

    fn ray_march_volume(vol : VolumeBox, r : Ray, t_min : Double, t_max : Double) -> (Vec3, Double)

    reflect

    fn reflect(v : Vec3, n : Vec3) -> Vec3
    Reflect vector v around normal n.

    refract

    fn refract(uv : Vec3, n : Vec3, etai_over_etat : Double) -> Vec3?
    Refract vector uv through surface with normal n and etai_over_etat ratio.

    reinhard_tone_map

    fn reinhard_tone_map(color : Vec3) -> Vec3

    Tone mapping and color space utilities. Implements Reinhard, ACES, and filmic tone mapping operators.

    render_scene

    fn render_scene(width~ : Int, height~ : Int, samples_per_pixel~ : Int, max_depth~ : Int, world~ : HitableList, cam~ : Camera, fog_density~ : Double) -> Array[Vec3]
    Render with BVH acceleration, NEE, Russian roulette, and optional volume fog.

    render_scene_full

    fn render_scene_full(width~ : Int, height~ : Int, samples_per_pixel~ : Int, max_depth~ : Int, world~ : HitableList, cam~ : Camera, fog_density~ : Double) -> Array[Vec3]
    Full pipeline: render + ACES tone mapping + vignette + gamma correction.

    render_with_config

    fn render_with_config(config : RenderConfig) -> (Array[Vec3], Int, Int)

    scene_add_box

    fn scene_add_box(objects : Array[SceneObject], center~ : Vec3, size~ : Vec3, material~ : String, r~ : Double, g~ : Double, b~ : Double) -> Array[SceneObject]

    scene_add_cylinder

    fn scene_add_cylinder(objects : Array[SceneObject], center~ : Vec3, radius~ : Double, height~ : Double, material~ : String, r~ : Double, g~ : Double, b~ : Double) -> Array[SceneObject]

    scene_add_plane

    fn scene_add_plane(objects : Array[SceneObject], center~ : Vec3, normal~ : Vec3, material~ : String, r~ : Double, g~ : Double, b~ : Double) -> Array[SceneObject]

    scene_add_sphere

    fn scene_add_sphere(objects : Array[SceneObject], center~ : Vec3, radius~ : Double, material~ : String, param1~ : Double, param2~ : Double, param3~ : Double) -> Array[SceneObject]

    scene_empty

    fn scene_empty() -> Array[SceneObject]

    sky_luminance

    fn sky_luminance(color : Vec3) -> Double

    smoothstep_edge0

    fn smoothstep_edge0(edge0 : Double, edge1 : Double, x : Double) -> Double

    sobol_sample

    fn sobol_sample(_index : Int, _dimension : Int) -> Double

    Advanced sampling strategies for Monte Carlo integration. Includes stratified sampling, MIS heuristics, and pixel filters.

    srgb_gamma_correct

    fn srgb_gamma_correct(color : Vec3) -> Vec3

    stratified_2d

    fn stratified_2d(s : Int, t : Int, nx : Int, ny : Int) -> (Double, Double)

    studio_lighting_demo

    fn studio_lighting_demo() -> (HitableList, Camera)

    sun_direction

    fn sun_direction(time_of_day : Double) -> Vec3

    sunrise_valley_scene

    fn sunrise_valley_scene() -> (HitableList, Camera)

    surrounding_box

    fn surrounding_box(box0 : AABB, box1 : AABB) -> AABB

    tent_filter

    fn tent_filter(x : Double) -> Double

    texture_demo_scene

    fn texture_demo_scene() -> (HitableList, Camera)

    three_spheres_scene

    fn three_spheres_scene() -> (HitableList, Camera)
    Simple scene with three spheres on a ground plane.

    triangle_demo_scene

    fn triangle_demo_scene() -> (HitableList, Camera)

    uniform_cone_pdf

    fn uniform_cone_pdf(cos_theta_max : Double) -> Double

    uniform_cone_sample_with_base

    fn uniform_cone_sample_with_base(rng : Rng, w : Vec3, cos_theta_max : Double) -> (Vec3, Rng)

    uniform_sample_cone

    fn uniform_sample_cone(rng : Rng, cos_theta_max : Double) -> (Vec3, Rng)

    uniform_sample_hemisphere

    fn uniform_sample_hemisphere(rng : Rng, normal : Vec3) -> (Vec3, Rng, Double)

    uniform_sample_sphere

    fn uniform_sample_sphere(rng : Rng) -> (Vec3, Rng)

    write_bmp_bytes

    fn write_bmp_bytes(width~ : Int, height~ : Int, pixels~ : Array[Vec3], samples_per_pixel~ : Int) -> Array[Byte]

    write_ppm_stdout

    fn write_ppm_stdout(width~ : Int, height~ : Int, pixels~ : Array[Vec3], samples_per_pixel~ : Int) -> Unit
    Output PPM from raw accumulated pixels (applies gamma correction internally).

    write_ppm_tonemapped

    fn write_ppm_tonemapped(width~ : Int, height~ : Int, pixels~ : Array[Vec3]) -> Unit
    Output PPM from already-gamma-corrected pixels (no further correction).