Ray Tracing, Version 4.0
Day #9
|
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:
Set up local Color3 variables for diffuse and ambient.
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 G>H 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:
All files are located in /classes/cs3114/Advanced_Graphics/files/texture directory. The ones I used in class today for demo are there, along with the appropriate PPM files:
- tex1.scn
- tex2.scn
- tex3.scn
- tex4.scn
- ts.scn
- wood.ppm
- sunrise.ppm
- dog.ppm
- shingle.ppm