Ray Tracing, Version 4.0
| Goal: Ray trace a scene where
|
Ray Tracing Tools:
Add these new classes and test each:
The code for readPPMfile is found in our files directory.
Make these changes:
bool isTextured;
//default is false, set in the constructor
TextureInfo texture;
Scene Class:
After calculating phong,
Assign diffuse and ambient to be the object's material diffuse and ambient. If the object is not textured, these will not change.
If the object is textured,
{
if the object is a square or a plane
{
set the generic hit point, GH
if GH is within the texture frame
{
set local variable j to be which texture;
set local variables for numColors, nCols and nRows //these locals are set merely for convenience;
calculate which row (tex_row) and which column (tex_col) of the image map the pixel is in;
calculate and assign whichpix to be the correct entry for this pixel (tex_col, tex_row) of the image array, which is one-dimensional;
assign local variable diffuse to be the red, green, blue components in this array entry, divided by the number of colors;
assign local variable ambient to be the diffuse values * 0.3 (or some other appropriate fraction)
}
}
}Then continue on with lighting calculations as before.
Test Files:
Tese test files for textures are located in /classes/cs3114/RayTracing/files/texture directory, along with the appropriate PPM files:
- tex1.scn
- tex2.scn
- tex3.scn
- tex4.scn
- ts.scn
- wood.ppm
- sunrise.ppm
- dog.ppm
- shingle.ppm
Working Directory:
Make a subdirectory v4.0 in your Working Directory. When you have version 4,0 working correctly, copy all files pertaining to it, including the makefile, to that directory and don't touch it!