Docsity

Ray Tracing - Computer Graphics I - Assignment | CS 4620, Assignments of Computer Graphics

Toggle sidebar
bg1
CS 4620 Program 1: Ray I
out: Tuesday 2 September 2008
due: Tuesday 16 September 2008
1 Overview
Ray tracing is a simple and powerful algorithm for rendering images. Within the accuracy of the
scene and shading models and with enough computing time, the images produced by a ray tracer
can be physically accurate and can appear indistinguishable from real images1. Your ray tracer will
not be able to produce physically accurate images, but later in the semester you will extend it to
produce nice looking images with many interesting effects. If you really catch the ray tracing bug,
you can go on to take CS 665, where you will learn how to build a modern, physically accurate ray
tracer.
In this assignment, your ray tracer will have support for:
•Spheres and axis-aligned boxes
•Lambertian and Phong shading
•Point lights with shadows
•Arbitrary perspective cameras
Some framework code is provided to save you the time to implement I/0 and vector operations.
However, the framework does not contain any code that does any actual ray tracing—you will
develop that code yourself.
When you write the ray tracing code, you have the freedom to determine the design you believe is
best. You may want to add some classes to the program, and there are many choices about where to
put the various parts of the computation. Any solution that correctly meets the requirements below
and is clearly written will recieve full credit. The textbook, the lectures, and the course staff are all
sources of information about good approaches to coding up a ray tracer.
This is not to say that you need to write a lot of new code. For reference, the framework contains 19
classes with about 2000 lines of code (1500 of which are in the parser and the vector math classes),
and our solution contains three small additional classes and about 600 additional lines of code.
1See http://www.graphics.cornell.edu/online/box/compare.html for a famous example
1
pf3
pf4
pf5

Partial preview of the text

Download Ray Tracing - Computer Graphics I - Assignment | CS 4620 and more Assignments Computer Graphics in PDF only on Docsity!

CS 4620 Program 1: Ray I

out: Tuesday 2 September 2008 due: Tuesday 16 September 2008

1 Overview

Ray tracing is a simple and powerful algorithm for rendering images. Within the accuracy of the scene and shading models and with enough computing time, the images produced by a ray tracer can be physically accurate and can appear indistinguishable from real images^1. Your ray tracer will not be able to produce physically accurate images, but later in the semester you will extend it to produce nice looking images with many interesting effects. If you really catch the ray tracing bug, you can go on to take CS 665, where you will learn how to build a modern, physically accurate ray tracer.

In this assignment, your ray tracer will have support for:

  • Spheres and axis-aligned boxes
  • Lambertian and Phong shading
  • Point lights with shadows
  • Arbitrary perspective cameras

Some framework code is provided to save you the time to implement I/0 and vector operations. However, the framework does not contain any code that does any actual ray tracing—you will develop that code yourself.

When you write the ray tracing code, you have the freedom to determine the design you believe is best. You may want to add some classes to the program, and there are many choices about where to put the various parts of the computation. Any solution that correctly meets the requirements below and is clearly written will recieve full credit. The textbook, the lectures, and the course staff are all sources of information about good approaches to coding up a ray tracer.

This is not to say that you need to write a lot of new code. For reference, the framework contains 19 classes with about 2000 lines of code (1500 of which are in the parser and the vector math classes), and our solution contains three small additional classes and about 600 additional lines of code. (^1) See http://www.graphics.cornell.edu/online/box/compare.html for a famous example

2 Requirements

  1. Use a ray tracing algorithm.
  2. Support arbitrary perspective projections as described in the file format section below.
  3. Support spheres and axis-aligned boxes.
  4. Support the Lambertian and Blinn-Phong shading models, as defined in Shirley 9.1–9.2 and in the lecture notes.
  5. Support point lights that provide illumination that does not fall off with distance.

You do not need to worry about malformed input, either syntactically or semantically. For instance, you will not be given a sphere with a negative radius or a scene without a camera.

3 File format

The input file for your ray tracer is in XML. An XML file contains sequences of nested elements that are delimited by HTML-like angle-bracket tags. For instance, the XML code:

1.0 2.0 3.0

contains four elements. One is a scene element that contains two others, called camera and surface. The surface element has an attribute named type that has the value Sphere. It also contains a center element that contains the text “1.0 2.0 3.0”, which in this context would be interpreted as the 3D point (1, 2 , 3).

An input file for the ray tracer always contains one scene element, which is allowed to contains tags of the following types:

  • surface: This element describes a geometric object. It must have an attribute type with value Sphere or Box. It can contain a shader element to set the shader, and also geometric parameters depending on its type: - for sphere: center, containing a 3D point, and radius, containing a real number. - for box: minPt and maxPt, each containing a 3D point. If the two points are (xmin, ymin, zmin) and (xmax, ymax, zmax) then the box is [xmin, xmax] × [ymin, ymax] × [zmin, zmax].
  • camera: This element describes the camera. It is described by the following elements: - viewPoint, a 3D point that specifies the center of projection.

4 Framework

The framework for this assignment includes a simple main program, some utility classes for vector math, a parser for the input file format, and stubs for the classes that are required by the parser.

4.1 Parser

The Parser class contains a simple and, we like to think, elegant parser based on Java’s built-in XML parsing. The parser simply reads a XML document and instantiates an object for each XML entity, adding it to its containing element by calling set... or add... methods on the containing object.

For instance, the input

0 0 1

1 2 3
4

results in the following construction sequence:

  1. Create the scene.
  2. Create an object of class Sphere and add it to the scene by calling Scene.addSurface. This is OK because Sphere extends the Surface class.
  3. Create an object of class Lambertian and add it to the sphere using Sphere.setShader. This is OK because Lambertian implements the Shader interface.
  4. Call setDiffuseColor(new Color(0, 0, 1)) on the shader.
  5. Call setCenter(new Point3D(1, 2, 3)) on the sphere.
  6. Call setRadius(4) on the sphere.

Which elements are allowed where in the file is determined by which classes contain appropriate methods, and the types of those methods’ parameters determine how the tag’s contents are parsed (as a number, a vector, etc.). There is more detail for the curious in the header comment of the Parser class.

The practical result of all this is that your ray tracer is handed a scene that contains objects that are in one-to-one correspondence with the elements in the input file. You shouldn’t need to change the parser in any way.

4.2 RayTracer

This class holds the entry point for the program. The main method is provided, so that your program will have an command-line interface compatible with ours. It treats each command line argument as the name of an input file, which it parses, renders an image, and writes the image to a PNG file. The method RayTracer.renderImage, which you need to write, is called to do the actual rendering.

4.3 Image

This class contains an array of floats and the requisite code to get and set pixels and to output the image to a PNG file.

4.4 The ray.math package

This package contains classes to represent 2D and 3D points and vectors, as well as RGB colors. They support all the standard vector arithmetic operations you’re likely to need, including dot and cross products for vectors and gamma correction for colors.

4.5 Other classes

The other classes in the framework all exist because they are required in order for the parser to de- code files in the input format described above. Since the XML entities in the file correspond directly to Java objects constructed by the parser, there is a class for every type of XML tag that can appear in the file, including Scene, Image, Camera, Light; Surface and its subtypes Sphere and Box; and Shader and its subtypes Lambertian and Phong. These classes generally contain only the fields and set/add methods required to implement the file format.

5 Submission and FAQ

Submission will be through CMS. A FAQ page will be kept on the course website detailing any new questions and their answers brought to the attention of the course staff.