ProductPromotion
Logo

Rust

made by https://0x3d.site

GitHub - dps/rust-raytracer: 🔭 A simple ray tracer in Rust 🦀
🔭 A simple ray tracer in Rust 🦀. Contribute to dps/rust-raytracer development by creating an account on GitHub.
Visit Site

GitHub - dps/rust-raytracer: 🔭 A simple ray tracer in Rust 🦀

GitHub - dps/rust-raytracer: 🔭 A simple ray tracer in Rust 🦀

rust-raytracer

An implementation of a very simple raytracer based on Ray Tracing in One Weekend by Peter Shirley in Rust. I used this project to learn 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

https://user-images.githubusercontent.com/237355/147687883-4e9ca4fc-7c3b-4adb-85d7-6b08d1bc69f7.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.png

Rendering out.png
Frame time: 2840ms

$ ./target/release/raytracer data/cover_scene.json cover.png

Rendering cover.png
Frame 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.21s

Rendering anim/frame_000.png
............................................................
Frame time: 21s

Using rayon

Rendering anim/frame_000.png
Frame 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 from https://www.solarsystemscope.com/textures/

Extreme lighting example

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

Progressive max_depth animation

max_depth_anim

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory