A Monte Carlo path tracing renderer in pure MoonBit — OSC 2026
| Type / 类型 | File / 文件 | Description / 描述 |
|---|---|---|
| Sphere / 球体 | geometry_sphere.mbt | Ray-sphere intersection |
| Plane / 平面 | geometry_plane.mbt | Infinite plane |
| Triangle / 三角形 | geometry_triangle.mbt | Möller–Trumbore algorithm |
| Box / 盒子 | geometry_box.mbt | Axis-aligned cuboid |
| Cylinder / 圆柱 | geometry_cylinder.mbt | Y-axis aligned |
| Disk / 圆盘 | geometry_disk.mbt | Flat circular disk |
| Cone / 圆锥 | geometry_cone.mbt | Tapered cone with base cap |
| Torus / 圆环 | geometry_torus.mbt | Newton's method solver |
| Mesh / 网格 | geometry_mesh.mbt | Triangle mesh with builders |
| Material / 材质 | Description / 描述 |
|---|---|
| Lambertian | Ideal diffuse (matte) surfaces / 理想漫反射 |
| Metal | Specular reflection with fuzz / 金属反射(可调粗糙度) |
| Dielectric | Glass/water with Schlick Fresnel / 电介质(玻璃/水/钻石) |
| Emissive | Light source (HDR) / 自发光光源 |
| DiffuseLight | Textured area light / 纹理区域光 |
| Isotropic | Volume-like scattering / 各向同性散射 |
| Textured | Dull surface with texture mapping / 纹理映射哑光表面 |
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 / 编译# 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.ps1python gui/server.py
# Open http://localhost:8088
# Or use the PowerShell launcher / 或使用 PowerShell 启动
powershell -File gui.ps1| # | Scene / 场景 | Key | Description / 描述 |
|---|---|---|---|
| 1 | three_spheres | Classic / 经典 | Diffuse + Metal + Glass |
| 2 | cornell_box | GI Test / 全局光 | Spherical light box |
| 3 | material_showcase | Materials / 材质 | 4 Lamberts + 4 Metals + 3 Dielectrics |
| 4 | random_spheres | Stress / 压力 | 121 random objects |
| 5 | geometric | Multi-Geo / 多几何体 | Boxes, cylinders, disks, checker floor |
| 6 | cornell_box_planes | Planar / 平面 | Plane-based Cornell box |
| 7 | texture_demo | Textures / 纹理 | Checker & noise spheres |
| 8 | triangle_demo | Triangles / 三角 | Colored triangle banners |
| 9 | final_demo | Showcase / 展示 | 121 mixed shapes + DOF |
| 10 | full_geometry | All Types / 全类型 | Every geometry type on display |
| 11 | studio_lighting | Lighting / 布光 | Three-point studio light setup |
| 12 | depth_of_field | DOF / 景深 | Aperture blur on metal spheres |
| 13 | foggy_scene | Volume / 大气 | Atmospheric fog effect |
| 14 | mirror_corridor | Mirror / 镜面 | Infinite reflection corridor |
| 15 | crystal_garden | Crystal / 水晶 | Glass prisms with colored lights |
| 16 | sunrise_valley | Landscape / 风景 | Stone monoliths at dawn |
| 17 | prism_lab | IOR Lab / 折射 | 6 dielectric prisms (water→diamond) |
| 18 | city_at_night | City / 城市 | Skyline with emissive windows |
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| Step | Status |
|---|---|
| moon check | ✅ 0 errors / 零错误 |
| moon test | ✅ 32/32 pass / 全部通过 |
| moon build | ✅ Build successful / 编译成功 |
| Render test | ✅ PPM validation / PPM 格式验证 |
moon test # 32 tests, all passing / 32 个测试全部通过import "Kai-Junhan/moon-ray"fn Environment::sample_importance(self : Environment, rng : Rng, normal : Vec3) -> (Vec3, Rng, Double)pub(all) struct RenderConfig {
scene : String
width : Int
height : Int
samples : Int
max_depth : Int
output_format : String
aperture : Double
fov : Double
} derive(Debug)type Rngfn balanced_heuristic(n_f : Double, pdf_f : Double, n_g : Double, pdf_g : Double) -> Doublefn make_scene_from_objects(objects~ : Array[SceneObject], cam_origin~ : Vec3, cam_lookat~ : Vec3, cam_fov~ : Double, cam_aspect~ : Double) -> (HitableList, Camera)fn power_heuristic(n_f : Double, pdf_f : Double, n_g : Double, pdf_g : Double, beta~ : Double) -> Doublefn render_scene(width~ : Int, height~ : Int, samples_per_pixel~ : Int, max_depth~ : Int, world~ : HitableList, cam~ : Camera, fog_density~ : Double) -> Array[Vec3]fn render_scene_full(width~ : Int, height~ : Int, samples_per_pixel~ : Int, max_depth~ : Int, world~ : HitableList, cam~ : Camera, fog_density~ : Double) -> Array[Vec3]fn scene_add_box(objects : Array[SceneObject], center~ : Vec3, size~ : Vec3, material~ : String, r~ : Double, g~ : Double, b~ : Double) -> Array[SceneObject]fn scene_add_cylinder(objects : Array[SceneObject], center~ : Vec3, radius~ : Double, height~ : Double, material~ : String, r~ : Double, g~ : Double, b~ : Double) -> Array[SceneObject]fn scene_add_plane(objects : Array[SceneObject], center~ : Vec3, normal~ : Vec3, material~ : String, r~ : Double, g~ : Double, b~ : Double) -> Array[SceneObject]fn scene_add_sphere(objects : Array[SceneObject], center~ : Vec3, radius~ : Double, material~ : String, param1~ : Double, param2~ : Double, param3~ : Double) -> Array[SceneObject]fn sobol_sample(_index : Int, _dimension : Int) -> DoubleA Monte Carlo path tracing renderer in pure MoonBit — OSC 2026