Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🔭 A simple ray tracer in Rust 🦀

License

NotificationsYou must be signed in to change notification settings

dps/rust-raytracer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An implementation of a very simple raytracer based onRay Tracing in One Weekendby Peter Shirley in Rust. I used this project tolearn Rust from scratch - the code may not be perfectly idiomatic, or even good, but it does make pretty pictures.

Additional features beyond Shirley's course:

  • Texture mapping (e.g. earth and moon textures below)
  • Lighting
  • Parallel rendering - will use all CPU cores for best performance
  • Read scene data from JSON file
  • Render a sky texture

Example output

Latest output

anim.mp4

Example usage

$ cargo build --release   Compiling raytracer v0.1.0 (/Users/dps/proj/rust-raytracer/raytracer)    Finished release [optimized] target(s) in 2.57s$ ./target/release/raytracer data/test_scene.json out.pngRendering out.pngFrame time: 2840ms$ ./target/release/raytracer data/cover_scene.json cover.pngRendering cover.pngFrame time: 27146ms

Texture mapping

cover_alt

Lighting

lighting-recast-final

Parallel rendering - will use all CPU cores for best performance

Original

🚀 ./target/release/raytracer anim/frame   Compiling raytracer v0.1.0 (/Users/dps/proj/rust-raytracer/raytracer)    Finished release [optimized] target(s) in 2.21sRendering anim/frame_000.png............................................................Frame time: 21s

Using rayon

Rendering anim/frame_000.pngFrame time: 2573ms

Render a sky texture

sky_textures

Read scene data from JSON file

Example

{  "width": 800,  "height": 600,  "samples_per_pixel": 128,  "max_depth": 50,  "sky": {    "texture":"data/beach.jpg"  },  "camera": {    "look_from": { "x": -2.0, "y": 0.5, "z": 1.0 },    "look_at": { "x": 0.0, "y": 0.0, "z": -1.0 },    "vup": { "x": 0.0, "y": 1.0, "z": 0.0 },    "vfov": 50.0,    "aspect": 1.3333333333333333  },  "objects": [    {      "center": { "x": 0.0, "y": 0.0, "z": -1.0 },      "radius": 0.5,      "material": {        "Texture": {          "albedo": [            1.0,            1.0,            1.0          ],          "pixels": "data/earth.jpg",          "width": 2048,          "height": 1024,          "h_offset": 0.75        }      }    }  ]}

Make animation

🚀 ffmpeg -f image2 -framerate 15 -i anim/frame_%03d.png -loop -0 anim.gif

Credits

Earth and moon textures fromhttps://www.solarsystemscope.com/textures/

Extreme lighting example

147705264-c6f439df-f61b-4bcf-b5e6-c2c755b35b1c

Progressive max_depth animation

max_depth_anim

About

🔭 A simple ray tracer in Rust 🦀

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp