Skip to content

Port to Rust, of the Ray Tracer in Atari 8-bit BASIC, with GPU support

License

Notifications You must be signed in to change notification settings

v-espitalier/Raytracer-tch-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raytracer in Rust with GPU

Here is a port to Rust, of the Ray Tracer in Atari 8-bit BASIC by D. Scott Williamson ( https://bunsen.itch.io/raytrace-movie-atari-8bit-by-d-scott-williamson ).

You can find 3 implementations here:

  • 2 CPU implementations (One that follows the Atari code line by line to get close to the the original output, and a fancier implementation in which I have replaced the dithering graphics with the usual color gradient, higher resolution, and multithreading for faster computation.)

  • And a GPU implementation, based on the Rust library tch-rs, which is a wrapper for libtorch.

Example of atari, cpu, gpu images

Beforehand, you need to make sure you got the libtorch installed and ready to use for tch-rs. You can get some information over there:

There is also a CPU-only implementation of the raytracer (without the libtorch dependancy). See v-espitalier/Raytracer-rs .

Once you installed libtorch, you can start playing with tensors, and test this GPU-based raytracer.

Commands to get the raytracer videos:

# Download source code
git clone https://github.com/v-espitalier/Raytracer-tch-rs

# Compilation
cd Raytracer-tch-rs/
cargo build

# Execution of the Raytracer (images generations)
cargo run

# Images merge to get the videos, using ffmpeg:
ffmpeg -framerate 5 -pattern_type glob -i 'generated_imgs/img_atari_*.png' \
  -c:v libx264 -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video_atari.mp4

ffmpeg -framerate 15 -pattern_type glob -i 'generated_imgs/img_cpu_*.png' \
  -c:v libx264 -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video_cpu.mp4

ffmpeg -framerate 30 -pattern_type glob -i 'generated_imgs/img_gpu_*.jpg' \
  -c:v libx264 -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video_gpu.mp4

See also an ASM version created by Nanochess, that fits on a boot sector (https://github.com/nanochess/RayTracer).

Licence

Raytracer-tch-rs is distributed under the terms of the MIT license. See LICENSE for more details.

About

Port to Rust, of the Ray Tracer in Atari 8-bit BASIC, with GPU support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages