• Stars
    star
    180
  • Rank 213,097 (Top 5 %)
  • Language
    Rust
  • License
    BSD 2-Clause "Sim...
  • Created almost 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ”ญ 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

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.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 Repositories

1

piui

Add a UI to your standalone Raspberry Pi project using your Android phone
JavaScript
416
star
2

nnrccar

nnrccar
C++
234
star
3

remarkable-keywriter

QML
183
star
4

remarkable-wikipedia

QML
142
star
5

go-xml-parse

Streaming XML parser example in go
Go
126
star
6

rpi-timelapse

Timelapse Camera Controller for Raspberry Pi
Python
104
star
7

montesheet

JavaScript
13
star
8

piui-sdcards

sdcard images for piui
8
star
9

unhumanize

a simple python library to convert humanized time intervals (e.g. 'an hour ago') into timedeltas
7
star
10

northbelt

A belt that buzzes north
Arduino
6
star
11

SwiftUI-Recipes

๐Ÿฝ A SwiftUI demo app showing how to fetch data from the server to populate list views, navigate to detailed results and wire in a search field.
Swift
6
star
12

piui-timelapse

PiUi version of rpi-timelapse
Python
4
star
13

spreadsheet

JavaScript
4
star
14

shortest-sudoku

A collection of tiny Sudoku solvers
Java
4
star
15

android-vector-climacons

Android vector drawable resources for @adamwhitcroft 's Climacons
3
star
16

aoc

Python
3
star
17

recipes

recipes
Python
2
star
18

wear-exchangerates

Exchange Rates complication data provider for Android Wear 2.0
Java
2
star
19

laserUp

๐Ÿ” Create 3D relief map slices for Glowforge. ๐ŸŒŽGenerate input files at
Python
2
star
20

go-zim

Pure Go reader for the ZIM file format
Go
2
star
21

wixel

Wixel Apps
C
2
star
22

lasercut

A collection of laser cutter designs. Most made for my kids.
Python
1
star
23

wordgrid

1
star
24

multihttp

A multiplexing http notifier in golang
Go
1
star
25

webalert

Python
1
star
26

remarkable-ambient-launcher

A launcher for reMarkable
QMake
1
star
27

gcal-cruncher

Crunches .ics files exported from Google calendar to show you where your time has been spent
Ruby
1
star
28

dial.fyi.complications

dial.fyi complications
Java
1
star
29

hotdog

HTML
1
star
30

sundial

A sundial laser-cutter template generator
Python
1
star
31

dial.fyi

Java
1
star
32

simplescheduler

A simple task scheduler using redis for python
Python
1
star