COL781/COL7681 Assignment 1

Due: Jan 26, 11pm. To be turned in on Moodle New.

Ray Tracing

Implement a recursive ray tracer using C/C++.
  1. Create a Makefile, which builds two executables named "a1_create" and "a1_veiw", respectively, in the directory in which make is run.
  2. a1_create accepts arguments <modelfile> <camerafile> <W> <H> [-o <outdir>]
    It creates images of the data in modelfile from the sequence of camera positions in camerafile. The images are stored in PNG format in the directory <outdir>. If the "-o" argument is not provided, use the default directory named "a1_images". Images are named "1.png", "2.png", etc. Their count and the content is defined by the data in <camerafile> as given below.
  3. a1_view accepts the argument <dir> [-s <speed>]. It reads files named "1.png", "2.png", etc. in dir and displays them on the screen one after another at "speed" frames a second. If "speed" argument is not provided, simply render the images one after another at the GPU rendering rate. (The window size should match the PNG image dimensions, which is uniform across all generated images.)

Model Format

The model format is plain ascii text containing a sequence of geometric components. Each component begins with a line with keyword "MATERIAL" followed by numbers (explained later) describing the material's illumination properties. The next several lines describe the shapes constituting the component.

For each component, there is a shape per line: each such line starts with the keywords "SOLID" or "HOLLOW". A shape is cube, cylinder, or box. For hollow shape only surface interaction of light is to be considered, whereas for a solid shape, volumetric interaction is to be simulated using ray-marching with some rays absorbed and others scattered by the medium. Naturally, "many" rays will be needed to traverse the medium. Each shape has (one of) the following forms following the "SOLID" or "HOLLOW" keywords on a line:

BOX h x1 y1 z1 x2 y2 z2 x3 y3 z3
CYLINDER r x1 y1 z1 x2 y2 z2
SPHERE r x1 y1 z1

The box is a cuboid, and the coordinates of its vertices A, B, and C are listed one after another. ABC forms a plane. The fourth vertex in the same plane needs to be computed to form a parallelogram ABCD. The box is h units high in the direction d = |(B-A)X(C-B)|, i.e., the other four points are A+hd, B+hd, etc.

The cylinder's axis is listed, as well as its radius about that axis.

The sphere's center and radius are listed.

The material properties comprise a sequence of 32 real-valued numbers. The first is the refractive index, the next three are the X Y Z spectral absorption coefficients, and the fifth is the uniform scattering coefficient. The remaining 27 are in triples of X Y Z, each value in the normalized range 0 to 1. The first X Y Z triple represents the (uniformly distributed) irradiance emitted from every point on the surface of the component. The next 12 represent surface BRDF, again normalized in the range 0-1 (with respect to the total reflected light). These are samples at θr = 0, π/6, π/3, and π/2. The full BRDF wrt ≤ θr ≤ π/2 is a linear interpolation of these sample values, and is 0 outside this range. Similarly, the subsequent 12 numbers represent BTDF samples. Here θr is the angle from the ideal direction of reflection for BRDF and from refraction for BTDF. BRDF and BTDF are independent of incoming and outgoing φ.

Camera Format

Each line indicates a camera, and has the following real-valued components:
xc yc zc xf yf zf

Here, xc yc zc represent the position of the camera and xf yf zf the point the camera looks at. The upward orientation is always 0 1 0.

You should trace at least one ray per pixel. However, the goal is to generate anti-aliased images -- you will need to discover how many rays to trace starting at each point. Be particularly careful with grazing incidences. Time taken will not be graded, but try to stay within a few tens of seconds for a model file with, say, 10 solids.

Note: Please start planning and reading up. Example model and camera files are available.

Resources: Use GLFW for creating a window and use OpenGL to push images to the screen. Use stb_image.h to read and write PNG files.


** Revised: Wed, 7 Jan 2025 by Subodh Kumar

-- The URL of this page is: http://www.cse.iitd.ac.in/~subodh/courses/CSL781/a1_ray.html --