Program 1: Ray Tracer 1

[ LiB ]

Program 1: Ray Tracer 1

In the path /Book Code/Chapter 09/ on the CD is a folder called Ray Tracer 1 . The application in this folder shades a given point in the scene using the method just defined. That is, it will shade the diffuse interaction (using the cosine method) on the surface and will also apply the specular highlights ( shininess ).

The /Common folder contains all the underlying classes you've been developing throughout the book. These files are used in the ray-tracing application. Open this application in Microsoft Visual C++ 6.0. In order for the scene definition files to work they must be in the relative path with the executable. You must run the application using Microsoft Visual C++ or by pressing Control+F5.

Inside the folder /Ray Tracer 1 is another folder called /Scenes . The files included in this folder are the scene definition files for the program. The basic design of the programs in this book include the /Common folder. This folder contains the basic classes required to set up a 3D rendering environment. The folder that includes the required classes for this program is in /Book Code/Chapter 09/Ray Tracer 1/Common .

The files in this folder are:

 12/21/2002  04:48p               1,381 cLight.h 12/21/2002  04:38p               5,127 cObject.cpp 12/21/2002  04:58p               4,667 cObject.h 12/21/2002  04:39p                 442 Color3.cpp 12/04/2002  12:33p               4,476 Color3.h 12/21/2002  04:39p                  23 ay.cpp 12/21/2002  04:59p               2,043 cRay.h 12/21/2002  04:39p              22,499 cScene.cpp 12/21/2002  04:59p               3,324 cScene.h 12/19/2002  05:29p               1,991 cVector3.cpp 12/21/2002  04:47p               5,171 cVector3.h 12/21/2002  04:59p               1,060 MathTools.h 12/21/2002  04:39p               1,108 PPM.cpp 12/21/2002  04:49p                 154 PPM.h 

To compile this program, follow these steps:

  1. Open the project workspace ( Ray Tracer 1.dsw or Ray Tracer 1.dsp ).

  2. From the File menu, choose Build, Rebuild All.

  3. From the File menu, choose Build, !Execute Ray Tracer 1.exe.

To run the program directly instead, you can execute the following file:

 /Book Code/Chapter 09/Ray Tracer 1/Ray Tracer 1.exe 

The program begins running and will soon prompt you to enter the path of the scene definition file. When the program asks you to "Enter Information:", you enter:

 /scenes/diffuse1.txt 

or

 /scenes/diffuse2.txt 

or

 /scenes/diffuse3.txt 

The program starts the ray-tracing process and then will prompt you to enter the output path for the rendered file stored on the image plane. When it asks "Please Enter output Path and Filename:", you enter:

 /scenes/myoutput1.ppm 

or

 /scenes/myoutput2.ppm 

or

 /scenes/myoutput3.ppm 

You can then browse to that path and open the file in IrfanView. However, I've already created the exported files for you and placed them in the follow-ing folder:

 /Book Code/Chapter 09/Ray Tracer 1/Output 

The files in this folder are:

 12/10/2002  10:38p           3,266,333 diffuse1.ppm 12/10/2002  10:42p           3,301,150 diffuse2.ppm 12/10/2002  10:47p           3,119,627 diffuse3.ppm 

Using the Program

In this section, you begin

compiling the program and executing it using Microsoft Visual C++ 6.0. The application will begin running and you will see the following information on the screen.

NOTE

TIP

Ray tracing renders spheres very quick- ly.It may take a few seconds to render a sphere with mirror reflections.

The application begins in a DOS command prompt window. Both ray tracing and photon mapping can be implemented on any platform, so I've decided to keep things at a minimum and use a simple method to implement the algorithms. The command prompt concepts can run on any platform. Press Control+F5 to begin the program.

The program input is as follows :

 Please Type in Path and File Name Usage (ex. C:\sample.txt) Enter Information: 

This is where you enter the relevant information pertaining to the scene files. For example, if you wanted to render the diffuse1.txt file, you would type it into the line as: Scenes/diffuse1.txt . This procedure is going to load all data in the scene for rendering.

The program statistics are as follows:

 Init Scene! Scene Stats! Objects: 2 Lights: 2 Tracing Scene! 

The objects and light lists are updated and will report this information. The application then begins tracing the scene. After the scene is rendered to the image plane, all the data is copied over to the color buffer. The application then requests for an output path and filename.

The program output is as follows:

 Please Enter output Path and Filename: Usage (c:\example.ppm): 

This is where you enter the output file. This is a file with a *.PPM extension. After you have entered this information, the application is complete.

The program time report is as follows: eDone Tracing Scene! Render Took 0 Minute(s) and 9 Second(s)...

The application reports the time it took to load in the scene and render it. As you can see, it took nine seconds to render Scenes/diffuse1.txt . This is the general format for all future ray-tracing applications, so be sure to commit this procedure to memory.

The Renders

The scene files are rendered using local lighting or direct illumination . The shading is composed of diffuse interaction and specular highlights, as shown in Figures 9.8 through 9.10. Figure 9.8 shows an example of two spheres that are rendered with diffuse interaction and specular highlights.

Figure 9.8. Scenes/diffuse1.txt contains two spheres that are rendered using diffuse interaction and specular highlights.

graphic/09fig08.gif


Figure 9.9 shows an example of a room model that is rendered with diffuse interaction.

Figure 9.9. Scenes/diffuse2.txt contains a room model that is rendered using diffuse interaction.

graphic/09fig09.gif


Figure 9.10 shows an example of a table that is rendered with diffuse interaction.

Figure 9.10. In Scenes/diffuse3.txt contains a table model that is rendered using diffuse interaction.

graphic/09fig10.gif


[ LiB ]


Focus On Photon Mapping
Focus On Photon Mapping (Premier Press Game Development)
ISBN: 1592000088
EAN: 2147483647
Year: 2005
Pages: 128
Authors: Marlon John

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net