[ LiB ] |
The CD materials for this chapter contain an example of this photon mapping application (/ Book Code/Chapter12/Photon Mapping ). The general design of the application is the same as the previous applications in this book. You are still building from where you left off in Chapter 11. The environment of the photon mapping application is exactly the same as the ray tracing applications. Figure 12.11 shows an example of the project setup.
It's time to take a look at the new changes that are implemented in each section of the photon mapping application. The entry point of the photon mapping application is inside main() . This is how you dictate to the application the logic that should be executed for photon mapping. The body and main logic of the program is located in /Chapter12/Photon Mapping/Photon Mapping.cpp . This is the brain of the program, where it calls the different methods of the pho-ton map and scene classes. However, the overall general flow of the application has changed a little bit from the previous ray tracing applications ( Ray Tracer.cpp ). The new code is incorporated for the photon mapping components and functionality. The changes inside main() appear in bold. If the Rendering_Algorithm variable is set to PHOTON_MAPPING , all required photon-mapping logic is executed within the application.
NOTE
NOTE
The overall main logic of the photon- mapping application is almost the same as in the ray tracing applica- tions.The scene loads in a definition file,parses the file,and loads the internal object arrays.The photon mapping logic is then executed and backward ray tracing is called.After the scene is rendered to the image plane,the scene objects are unloaded.
A few variables are created to tally the time it took to build and render the scene using photon mapping. Information is constantly printed to the DOS window to inform the user that the application is running properly. When the program has commenced, it calls the Beep() method that causes the computer speaker to beep. Here is the code:
int main(int argc, char* argv[]) { // for timing unsigned long Start_Time = 0; long Whole_Interval = 0, seconds = 0; int G_Curr_Mins = 0, G_Curr_Secs = 0, Average = 0; // grab begin time Start_Time = GetTickCount(); // RAY TRACER printf("Photon Mapping 1!\n"); // Begin printf("Init Scene!\n"); TheScene.Init_Scene(); // Scene Stats printf("Scene Stats!\n"); printf("Objects: %d Lights: %d\n", TheScene.nObjectCount, TheScene.nLightCount); // Added in Chapter 11 if ( TheScene.Render_Algorithm == PHOTON_MAPPING ) { // Create Photons printf("Creating Photons!\n"); TheScene.CreatePhotons(); } // Trace printf("Tracing Scene!\n"); TheScene.BeginTracing(); // We're all done!! printf("Done Tracing Scene!\n"); TheScene.Kill_Scene(); // actual render time Whole_Interval = 0; Whole_Interval = (GetTickCount() - Start_Time); seconds = (Whole_Interval / 1000); G_Curr_Mins = (int)seconds / 60; G_Curr_Secs = (int)seconds % 60; printf("Render Took %d Minute(s) and %d Second(s)...", G_Curr_Mins, G_Curr_Secs); // halt and beep Beep(1000, 500); return 0; }
NOTE
NOTE
The Init_Scene() method in the scene class should be used to allo cate objects and to set up the ren dering environment.
The folder that includes the required classes for this program is in /Book Code/Chapter 12/Photon Mapping/Common . The files in this folder are:
12/21/2002 05:19p 1,381 cLight.h 12/21/2002 05:19p 5,127 cObject.cpp 12/21/2002 05:19p 4,692 cObject.h 12/21/2002 05:19p 442 Color3.cpp 12/21/2002 05:19p 4,480 Color3.h 12/21/2002 05:20p 2,248 cPhoton.cpp 12/21/2002 05:32p 1,408 cPhoton.h 12/21/2002 05:19p 23 cRay.cpp 12/21/2002 05:19p 2,043 cRay.h 12/21/2002 05:19p 34,852 cScene.cpp 12/21/2002 05:23p 3,781 cScene.h 12/19/2002 05:29p 1,991 cVector3.cpp 12/21/2002 05:19p 5,169 cVector3.h 12/21/2002 05:19p 1,060 MathTools.h 12/21/2002 05:19p 1,108 PPM.cpp 12/21/2002 05:19p 154 PPM.h
You compile this program as described in previous chapters. You can also run the program directly by executing the /Book Code/Chapter 12/Photon Mapping/Photon Mapping.exe file. When the program asks you to "Enter Information:", you enter:
/scenes/photon.txt
The program will also ask how many photons you would like to scatter per object. A good number for spheres is 1000, whereas a good number for triangles is 1000. It will also ask you what the photon contribution is. A good number is 50.
The photon-mapping algorithm will then begin scattering photons. The program starts the ray-tracing process and then again 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:", enter:
/scenes/myoutput.ppm
You can then browse to that path and open up the file in IrfanView. However, I've already created the exported file for you and placed it in the following folder:
/Book Code/Chapter 12/Photon Mapping/Output
The file in this folder is:
10/13/2002 03:30p 3,212,934 photon.ppm
You can now begin compiling the program and executing it using Microsoft Visual C++ 6.0. The application will begin running and you will see the fol-lowing information printed on the screen. The scene definition file for the photon mapping application is located in /Book Code/Chapter 12/Photon Mapping/Scenes . The file you will use when running this program is called photon.txt . The program input is as follows :
Init Scene! 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, you type into the line this statement: Scenes/photon.txt . This procedure loads all data in the scene for rendering.
NOTE
CAUTION
The array method that searches for the closest photons is extremely slow,so be warned that the render will take a very long time.This test was conducted on my laptop that has a PIII 900 MHz Processor,256MB of RAM and 16MB of Video RAM.
The photon mapping input is as follows:
How Many Photons per Object? 10000 How Many Photons for Photon Contribution? 50
This is the new part of the general logic that requests the number of photons to scatter per object and the number of photons to search for when calculating the radiance estimate.
The program statistics are as follows:
Scene Stats! Objects: 2 Lights: 2 Generating Photons!
The objects and light lists are updated and will report this information. The application then begins the photon-tracing process.
The photon mapping statistics are as follows:
Creating Photons! To Object 0: 10000 fired, 65574 hit To Object 1: 10000 fired, 6557 hit To Object 0: 10000 fired, 7305 hit To Object 1: 10000 fired, 7289 hit [STATS] Actual Stored Photons = 29970 Absorbed Hits: 29970 Specular Reflected hits: 0 Diffuse Reflected hits: 2262 Refracted Hits: 0
After the photon tracing process has commenced, the lighting effect statistics are printed. This gives you detailed information about when the photon map was constructed .
Tracing Scene!
Once the photon map has been constructed, the program begins using backward ray tracing to calculate the radiance estimate for the point of intersection. This may take some time depending on the geometry of the scene and the specs of your computer.
The program output is as follows:
Please Enter output Path and Filename: Usage (c:\example.ppm): /Output/photon.ppm
The application completes the rendering process and prompts the users to select the filename and path of the rendered image. The output file must be labeled with a *.PPM extension. After you have entered this information, the application completes.
The program time report is as follows:
Done Tracing Scene! Render Took 30 Minute(s) and 35 Second(s)...
The application reports the time it took to load the scene and render it. As you can see, the time it took to render Scenes/photon.txt was 30 minutes and 35 seconds on my laptop. This is long because traversing through a linear array is a very slow process. You'll learn how to speed up this process in the next chapter.
Figure 12.12 shows an image of the photon.txt render using the photon mapping application with the different lighting effects discussed in this chapter.
[ LiB ] |