Skip to content

Fyy10/ray-tracer

Repository files navigation

ray-tracer

A vanilla ray tracer implemented in C/C++.

Reference: Ray Tracing in One Weekend

Output an Image

The PPM Image Format

From wikipedia:

P3
# "P3" means this is a RGB color image in ASCII
# "3 2" is the width and height of the image in pixels
# "255" is the maximum value for each color
# This, up through the "255" line below are the header.
# Everything after that is the image data: RGB triplets.
# In order: red, green, blue, yellow, white, and black.
3 2
255
255   0   0
  0 255   0
  0   0 255
255 255   0
255 255 255
  0   0   0

Generate a Sample Image

g++ ppm_example.cpp -o ppm_example
./ppm_example > sample.ppm

The generated image (converted to PNG):

ppm_example

Convert to Other Formats

Use ffmpeg:

ffmpeg -i input.ppm output.png

Or, use ImageMagick:

convert input.ppm output.png

Draw a Background

g++ background.cpp -o bg_gen -std=c++11
./bg_gen > background.ppm
convert background.ppm background.png

The generated background:

background

Usage

Build

git clone https://github.com/Fyy10/ray-tracer.git
cd ray-tracer/
make

Run

./main > pic.ppm
convert pic.ppm pic.png

The rendered image:

pic

The code runs extremely slow (takes around 18 hours to produce a single 1200x800 image on my linux server with an Intel Core i3-530 CPU). GPU acceleration is important (not implemented yet).

Remove the Executable

make clean

Progress

  • 3D Vectors, 3D Points, Color
  • Rays, Basic Camera, and Background
  • Sphere Objects
    • Surface Normal
    • Hit Table and Multiple Objects
  • Antialiasing
  • Materials
    • Diffuse Material
    • Metal
    • Dielectrics
  • Positionable Camera
  • Defocus Blur
  • Random Scene
  • Parallel Acceleration for Rendering

About

A vanilla ray tracer implemented in C/C++.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors