Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# CLAUDE.md - Rays.rust Project Guide

## Project Overview
Rays.rust is a raytracer written in Rust with the following features:
- Whitted tracing and path tracing with Monte-Carlo global illumination
- Material models: Lambertian, Specular, Dielectric
- Objects: Sphere, Plane, Mesh, OBJ file import
- Skysphere with Rayleigh and Mie Scattering
- Procedural objects including Ocean (Tessendorf's algorithm with Phillips spectrum)
- Multithreaded rendering with progressive output

## Build Commands
- Build and run: `cargo run --release -- -p demo/demo.json`
- Run tests: `cargo test`
- Run specific test: `cargo test <test_name>`
- Lint code: `cargo clippy`
- Format code: `cargo fmt`
- View sample scenes: `cargo run --release -- -p demo/scenes/<scene_file>.json`

## Command-line Options
- `-p, --scene <FILE>`: Set scene file (required)
- `--progressive-render`: Update output file when a chunk is completed
- `--width <NUM>`: Override scene file width
- `--height <NUM>`: Override scene file height

## Code Style
- Traits used for major abstractions (Camera, Geometry, Medium, MaterialModel)
- Box<dyn Trait> for polymorphism
- Error handling via Option<T>/Result<T,E> with unwrap()
- Full paths with crate:: prefix for imports
- 4-space indentation
- snake_case for variables and functions
- Structs using PascalCase
- Extensive use of Vector3<f64> from nalgebra
- Multithreaded rendering with Rayon

## Project Structure
- Modules organized by functionality (material, shapes, procedural)
- Scene definitions stored in JSON files (in demo/ and demo/scenes/)
- Rendering progress tracking via indicatif
- Sample scenes available in demo/scenes/ with corresponding .png outputs
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ rustfft="2.1"
termcolor="1.0.5"
indicatif = "0.17.11"
console = "0.15.11"
approx = "0.5.1"
Binary file modified demo/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/scenes/ocean-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions demo/scenes/sky-custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"width": 1200,
"height": 500,

"supersamples": 50,
"chunk_size": 64,
"samples_per_chunk": 1,

"background": [0.1, 0.1, 0.1],
"shadow_bias": 0.0001,
"max_depth": 3,

"materials": {
"WHITE_MARBLE": {
"type": "lambertian",
"albedo": [0.9, 0.9, 0.9]
},
"BLACK_MARBLE": {
"type": "lambertian",
"albedo": [0.1, 0.1, 0.1]
},
"GOLD": {
"type": "metal",
"reflective": [1, 0.85, 0.57],
"roughness": 0.1
}
},
"media": {
"CHECKERED_MARBLE": {
"type": "checkered-y-plane",
"m1": "WHITE_MARBLE",
"m2": "BLACK_MARBLE"
}
},

"camera": {
"location": [0, 10, -50],
"lookat" : [0, 10, 0],
"up" : [0, 1, 0],
"angle": 0.5,
"aperture": 0.01
},

"lights" : [],
"variables" : {},

"objects": [
{
"type": "sphere",
"radius": 5,
"location": [0, 10, 0],
"material" : "GOLD"
},
{
"type": "checkeredplane",
"y": 0,
"medium": "CHECKERED_MARBLE"
},
{
"type": "skysphere",
"rayleigh_r": 5.0e-6,
"rayleigh_g": 10.0e-6,
"rayleigh_b": 30.0e-6,
"mie_coefficient": 15.0e-6,
"mie_anisotropy": 0.85,
"sun_direction": [0.3, 0.2, 1],
"brightness": 15
}
]
}
Binary file added demo/scenes/sky-custom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions demo/scenes/sky-presets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"width": 1200,
"height": 500,

"supersamples": 50,
"chunk_size": 64,
"samples_per_chunk": 1,

"background": [0.1, 0.1, 0.1],
"shadow_bias": 0.0001,
"max_depth": 3,

"materials": {
"WHITE_MARBLE": {
"type": "lambertian",
"albedo": [0.9, 0.9, 0.9]
},
"BLACK_MARBLE": {
"type": "lambertian",
"albedo": [0.1, 0.1, 0.1]
},
"GOLD": {
"type": "metal",
"reflective": [1, 0.85, 0.57],
"roughness": 0.1
}
},
"media": {
"CHECKERED_MARBLE": {
"type": "checkered-y-plane",
"m1": "WHITE_MARBLE",
"m2": "BLACK_MARBLE"
}
},

"camera": {
"location": [0, 10, -50],
"lookat" : [0, 10, 0],
"up" : [0, 1, 0],
"angle": 0.5,
"aperture": 0.01
},

"lights" : [],
"variables" : {},

"objects": [
{
"type": "sphere",
"radius": 5,
"location": [0, 10, 0],
"material" : "GOLD"
},
{
"type": "checkeredplane",
"y": 0,
"medium": "CHECKERED_MARBLE"
},
{
"type": "skysphere",
"preset": "earth",
"sun_direction": [0.5, 0.3, 1],
"brightness": 15
}
]
}
66 changes: 66 additions & 0 deletions demo/scenes/sky-sunset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"width": 1200,
"height": 500,

"supersamples": 50,
"chunk_size": 64,
"samples_per_chunk": 1,

"background": [0.1, 0.1, 0.1],
"shadow_bias": 0.0001,
"max_depth": 3,

"materials": {
"WHITE_MARBLE": {
"type": "lambertian",
"albedo": [0.9, 0.9, 0.9]
},
"BLACK_MARBLE": {
"type": "lambertian",
"albedo": [0.1, 0.1, 0.1]
},
"GOLD": {
"type": "metal",
"reflective": [1, 0.85, 0.57],
"roughness": 0.1
}
},
"media": {
"CHECKERED_MARBLE": {
"type": "checkered-y-plane",
"m1": "WHITE_MARBLE",
"m2": "BLACK_MARBLE"
}
},

"camera": {
"location": [0, 10, -50],
"lookat" : [0, 10, 0],
"up" : [0, 1, 0],
"angle": 0.5,
"aperture": 0.01
},

"lights" : [],
"variables" : {},

"objects": [
{
"type": "sphere",
"radius": 5,
"location": [0, 10, 0],
"material" : "GOLD"
},
{
"type": "checkeredplane",
"y": 0,
"medium": "CHECKERED_MARBLE"
},
{
"type": "skysphere",
"preset": "sunset",
"sun_direction": [0.0, 0.1, 1],
"brightness": 15
}
]
}
Binary file added demo/scenes/sky-sunset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/scenes/spheres.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ use rand::thread_rng;
use rand::seq::SliceRandom;

use indicatif::ProgressBar;
use indicatif::ProgressStyle;
use console::style;


Expand Down Expand Up @@ -131,7 +132,8 @@ fn main() {
println!("{}",
style("# 2. - Rendering ").bold().cyan()
);
let pb = ProgressBar::new_spinner();
let pb = ProgressBar::new(100);
pb.set_style(ProgressStyle::with_template("{spinner:.green} {prefix}{msg} [{bar:.cyan/blue}]").unwrap().progress_chars("#>-"));

chunks
.into_par_iter()
Expand All @@ -145,6 +147,7 @@ fn main() {
if rc.progressive_render {
paint::to_png(&rc);
}
pb.set_position(rc.progress_percentage(&s) as u64);
pb.set_message(rc.progress(&s));
pb.tick();
});
Expand Down
6 changes: 5 additions & 1 deletion src/rendercontext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ impl RenderContext {
format_f64(self.rays_cast as f64),
format_f64(self.rays_cast as f64 / elapsed.as_secs_f64()),
format_f64(self.rays_cast as f64 / self.pixels_rendered as f64),
format_f64((self.pixels_rendered as f64 / (self.width * self.height * s.render.supersamples as usize) as f64) * 100.),
format_f64(self.progress_percentage(s)),
rayon::current_num_threads());
}

pub fn progress_percentage(&self, s: &Scene) -> f64 {
(self.pixels_rendered as f64 / (self.width * self.height * s.render.supersamples as usize) as f64) * 100.
}

pub fn iter(&self, s: &Scene) -> impl Iterator<Item=RenderableChunk> + '_ {
let width = self.width;
let height = self.height;
Expand Down
Loading