Rust-raytracer - 🔭 A simple ray tracer in Rust 🦀

Overview

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

You might also like...
Rustcraft is a simple Minecraft engine written in rust using wgpu.
Rustcraft is a simple Minecraft engine written in rust using wgpu.

Rustcraft is a simple Minecraft engine written in rust using wgpu.

Endless Trial is a simple 2D bullet-hell-like game made in Rust with Tetra.

Endless Trial Endless Trial is a simple 2D bullet-hell-like game made in Rust with Tetra. To-do Sound Credits This project uses several free sprites:

Simple RUST game with the Bevy Engine

Simple RUST Game using the Bevy Engine YouTube videos for this code base: Episode 1 - Rust Game Development tutorial from Scratch with Bevy Engine Epi

minesweeper-rs is a simple minesweeper game using Rust and windows-rs.
minesweeper-rs is a simple minesweeper game using Rust and windows-rs.

minesweeper-rs minesweeper-rs is a simple minesweeper game using Rust and windows-rs. Key Features TBA Quick Start TBA How To Contribute Contributions

A simple Rust and WebAssembly example implementing the Game of Life
A simple Rust and WebAssembly example implementing the Game of Life

rust-wasm-game-of-life rust-wasm-game-of-life is a simple Rust and WebAssembly example implementing the Game of Life based on Rust and WebAssembly boo

A Simple Rust Game Engine For 2D

VeeBee VeeBee Is A Nice And Simple Game Engine For 2D. Features Sprites & Images! Btw There Is A Built In 2D Pack (But The Textures Are REALY BAD, Sor

🎮 A simple 2D game framework written in Rust

Tetra Tetra is a simple 2D game framework written in Rust. It uses SDL2 for event handling and OpenGL 3.2+ for rendering. Website Tutorial API Docs FA

A simple Minecraft written in Rust with the Piston game engine
A simple Minecraft written in Rust with the Piston game engine

hematite A simple Minecraft written in Rust with the Piston game engine How To Open a World This method is only for personal use. Never distribute cop

A simple, very minimal Minecraft server implementation in Rust.
A simple, very minimal Minecraft server implementation in Rust.

A simple, very minimal Minecraft server implementation in Rust. For a simple Minecraft server that isn't supposed to do much (for example, a limbo ser

Owner
David Singleton
David Singleton
Ray Tracer written in Rust

Erena A Ray Tracer written in Rust. Erena is based on the Esena project, which is written in Scala. Here is the current rendered image: See The Ray Tr

Melvic Ybanez 11 Dec 7, 2021
A cpu-based raytracer written in rust.

mini-raytracer A cpu-based raytracer written in rust. This project was written by me to learn about computer graphics, specifically rayracing. Feature

null 5 May 16, 2022
The study of a simple path tracer implementation (image raytracing in shorts)

The study of a simple path tracer implementation (generate a raytraced image, in shorts).

Leonardo Vieira 1 Apr 2, 2022
Implementation of the great book Ray Tracing in One Weekend in Rust.

Ray Tracing in One Weekend (Rust) Implementation of the great book Ray Tracing in One Weekend in Rust. Fun easy way to pick up and learn Rust (was rou

Stanley Su 6 Dec 29, 2021
Non-Linear Ray Casting

linon Non-Linear Ray Casting References E. Gröller, “Nonlinear Ray Tracing: Visualizing Strange Worlds,” The Visual Computer, vol. 11, no. 5, pp. 263–

Niklas Korz 13 Dec 1, 2022
First-person 3D pong ray-traced on CPU in real time.

ray ten Run in browser ray-ten.mp4 Reimagining of a 1986 ZX Spectrum game room ten made with ray tracing. Completely ignoring GPUs when rendering 3D g

Egor 2 Aug 20, 2022
💫 create beautiful code snippets on ray.so

Rayso✨ [ Generate beautiful screenshot snippets from terminal using ray.so ] Installation ?? Source ?? $ git clone --depth=1 https://github.com/pwnwri

Nabeen Tiwaree 25 Jul 12, 2023
Simple retro game made using Rust bracket-lib by following "Herbert Wolverson's Hands on Rust" book.

Flappy Dragon Code from This program is a result of a tutorial i followed from Herbert Wolverson's Hands-on Rust Effective Learning through 2D Game De

Praneeth Chinthaka Ranasinghe 1 Feb 7, 2022
A refreshingly simple data-driven game engine built in Rust

What is Bevy? Bevy is a refreshingly simple data-driven game engine built in Rust. It is free and open-source forever! WARNING Bevy is still in the ve

Bevy Engine 21.1k Jan 4, 2023
Victorem - easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust.

Victorem Easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust. Example Cargo.toml [dependencies] vict

Victor Winbringer 27 Jan 7, 2023