I wrote a Ray Tracer along reading the books Ray Tracing in One Weekend book series.
I chose to write it in Rust.
I added the possibiliy to load some scene configuration files and to convert some STL file into those scene.
Sources are available on GitHub.
Pictures
Features
Materials
- Glass
- Lambertian
- Metal
- Light
Textures
- Solid color
- Checker
- Image
- Procedural noise
- Marble
Shapes
- Sphere,
- Quad
- Triangle
Transformations
- Scale
- Rotation
- Translation
Misc
- Load scene configuration
- Create scene configuration
- Convert STL files into scene configuration
Setup
git clone https://codeberg.org/null_dev/ray-tracer.git
cd ray-tracer
cargo install --path ./packages/ray-tracer
Usage
Get help
nd-ray-tracer help
Create a scene
You can obtain the list of available creation subcommands.
nd-ray-tracer create help
Let's create a scene with two boxes standing in a Cornell box.
- First, we need a cornell box model
nd-ray-tracer create cornell-box --output cornell-box-model.json - then, we need a cube model
nd-ray-tracer create cube --output cornell-box-model.toml - now we can a scene using these two models
{ "camera": { "background_color": [0, 0, 0], "look_at": [0.5, 0.5, 0.5], "look_from": [0.5, 0.5, -1.625], "field_of_view": 35, "samples_per_pixel": 200, "ray_max_bounces": 50 }, "textures": [[ "cube1", { "SolidColor": { "color": [0.9803921569, 0.7019607843, 0.5294117647] }} ], [ "cube2", { "SolidColor": { "color": [0.537254902, 0.7058823529, 0.9803921569] }} ]], "materials": [[ "cube1", { "Lambertian": { "texture": "cube1" }} ], [ "cube2", { "Metal": { "fuzz": 0.025, "texture": "cube2" }} ]], "instances": [[ "cornell-box", { "Scene": { "path": "cornell-box-model.json" }} ], [ "cube1", { "Scene": { "path": "cube-model.toml", "material": "cube1" }} ], [ "cube2", { "Scene": { "path": "cube-model.toml", "material": "cube2" }} ]], "scene": [{ "Ref": { "id": "cornell-box" } }, { "Translate": { "offset": [0.25, 0, 0.25], "object": { "RotateY": { "angle": 0.7853981634, "object": { "ScaleU": { "factor": 0.25, "object": { "Translate": { "offset": [-0.5, 0, -0.5], "object": { "Ref": { "id": "cube1" } }} }} }} }} }, { "Translate": { "offset": [0.750, 0, 0.625], "object": { "RotateY": { "angle": -1.0471975512, "object": { "ScaleV": { "scale": [0.25, 0.75, 0.25], "object": { "Translate": { "offset": [-0.5, 0, -0.5], "object": { "Ref": { "id": "cube2" } }} }} }} }} }] }cornell-box-scene.json
Render a scene
nd-ray-tracer render \
-fv \
--width 800 \
--aspect-ratio 1 \
--samples-per-pixel 500 \
--ray-max-bounces 50 \
--output cornell-box-scene.png \
cornell-box-scene.json
Credits
All textures and 3D STL models are licensed under Creative Commons 4.0 (CC BY 4.0).





