Ray Tracing

Previous    Next


For ray tracing, we represent the window on the projection plane as a rectangular area of pseudo-pixels (PP). Each pseudo-pixel is then a small rectangle and is identified with the location of its center. Ray tracing will determine the correct color to display for each pseudo-pixel using the algorithm:

For each PP in window { Find RAY from COP to center of PP Dnearest = INFINITY; /* Distance from COP to nearest intersection */ Onearest = NULL; /* OBJECT on which Dnearest is achieved */ For each OBJECT in SCENE { if (OBJECT intersects RAY) { P = closest intersection of RAY with OBJECT D = dist(COP,P) if (D < Dnearest) { Pnearest = P Dnearest = D Onearest = OBJECT } } } WRITE_PSEUDO_PIXEL(color(Onearest,Pnearest), PP) }

If the pseudo pixels map directly to pixels on the screen, then WRITE_PSEUDO_PIXEL just becomes write_pixel(). However more generally, WRITE_PSEUDO_PIXEL draws the rectangle PP with color color(Onearest,Pearest))


Previous   Next