This is a C++ framework for a raytracer. It is created for the Computer Science course "Introduction to Computer Graphics" taught at the University of Groningen.
This framework is inspired by and uses (some) code of the raytracer framework of Bert Freudenberg which unfortunately is no longer available.
We provided a CMakeLists.txt file to be used with cmake
.
This can be used in the following way (on the command line/shell):
# cd into the main directory of the framework
mkdir build # create a new build directory
cd build # cd into the directory
cmake .. # creates a Makefile
# Comipiling the code can then be done with:
make
# or
make -j4 # replacing 4 with the number of cores of your pc
Note! After adding new .cpp
files (when adding new shapes)
cmake ..
needs to be called again or you might get linker errors.
After compilation you should have the ray
executable.
This can be used like this:
./ray <path to .json file> [output .png file]
# when in the build directory:
./ray ../Scenes/scene01.json
Specifying an output is optional and by default an image will be created in
the same directory as the source scene file with the .json
extension replaced
by .png
.
-
Scenes/*.json
: Scene files are structured in JSON. If you have never worked with json, please see here or here.Take a look at the provided example scenes for the general structure. You are free (and encouraged) to define your own scene files later on.
-
main.cpp
: Contains main(), starting point. Responsible for parsing command-line arguments. -
raytracer.cpp/.h
: Raytracer class. Responsible for reading the scene description, starting the raytracer and writing the result to an image file. -
scene.cpp/.h
: Scene class. Contains code for the actual raytracing. -
image.cpp/.h
: Image class, includes code for reading from and writing to PNG files. -
light.h
: Light class. Plain Old Data (POD) class. Colored light at a position in the scene. -
ray.h
: Ray class. POD class. Ray from an origin point in a direction. -
hit.h
: Hit class. POD class. Intersection between anRay
and anObject
. -
object.h
: virtualObject
class. Represents an object in the scene. All your shapes should derive from this class. See -
shapes (directory/folder)
: Folder containing all your shapes. -
sphere.cpp/.h (inside shapes)
: Sphere class, which is a subclass of theObject
class. Represents a sphere in the scene. -
example.cpp/.h (inside shapes)
: Example shape class. Copy these two files and replace/rename every instance ofExample
example.h
orEXAMPLE
with your new shape name. -
triple.cpp/.h
: Triple class. Represents a 3-dimensional vector which is used for colors, points and vectors. Includes a number of useful functions and operators, see the comments intriple.h
. Classes ofColor
,Vector
,Point
are all aliases ofTriple
. -
objloader.cpp/.h
: Is a similar class to Model used in the OpenGL exercises to load .obj model files. It produces a std::vector of Vertex structs. Seevertex.h
on how you can retrieve the coordinates and other data defined at vertices.
lode/*
: Code for reading from and writing to PNG files, used by theImage
class. lodepng is created by Lode Vandevenne and can be found on github.json/*
: Code for parsing JSON documents. Created by Niels Lohmann and available under the MIT license on github. Recommended: Especially take a look at their README for more info on how to work with json files.