3D Graphics - Ray Tracer


Scene Description Format

Each scene file can have the following keywords:

#COMMENTS

#global parameters
GLOBAL_AMBIENT_COLOR r g b
BACKGROUND_COLOR r g b
DEFAULT_REFRACTIVE_INDEX <double>
MAX_RECURSION_DEPTH <int>
FOV <double>

#scene objects
POSITIONAL_LIGHT r g b x y z
SPHERE x y z radius
TRIANGLE x1 y1 z1 x2 y2 z2 x3 y3 z3

#material properties
DIFFUSE_COLOR r g b
AMBIENT_COLOR r g b
SPECULAR_COLOR r g b
REFLECTANCE r g b
TRANSMITTANCE r g b
REFRACTIVE_INDEX <double>
SHININESS <double>

Sample scenes

Notes:

PPM file format

PPM files are very easy to write. They are plain text ASCII files. You should be able to open them in Photoshop, GIMP, or use the unix convert command(convert a.ppm a.png) to convert it to another format.

A typical file looks like:

P3 <width> <height> <max color value>
r g b r g b r g b r g b ... (max 70 columns per line)

All values are integers in ASCII format. Each value is seperated by one or more white spaces(<newlines> or <space> or <tabs>). <max color value> should be 255 if you want a 24 bits/pixel RGB image. Here is an example 2x2 24bit color PPM file

P3 2 2 256
0 0 0 255 255 255 255 255 255 0 0 0

This should make a image which looks something like:

.#
#.

Here is some sample C++ code which write to a PPM file. The buffer it takes is the same as what you would give to glDrawPixels().


- Yogi