Page 120 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 120
Lab on Computer Graphics
Notes The Pre-rendering Section
This section is executed before the actual rendering of the scene takes place. It is the most
implementation and programmer dependent of all the sections of the algorithm. Its structure
and content relies entirely on how the programmer has chosen to describe and store his scene
and what variables need to be initialized for the program to run properly. Some parts that are
usually present in some form or the other include generation of efficiency structures, initialization
of the output device, setting up various global variables etc. No standard algorithm exists for
this section.
The Main Rendering Loop
Procedure RenderPicture()
For each pixel on the screen,
Generate a ray R from the viewing position through the point on the view
plane corresponding to this pixel.
Call the procedure RayTrace() with the arguments R and 0
Plot the pixel in the colour value returned by RayTrace()
Next pixel
End Procedure
Procedure RayTrace(ray R, integer Depth) returns colour
Set the numerical variable Dis to a maximum value
Set the object pointer Obj to null
For each object in the scene
Calculate the distance (from the starting point of R) of the nearest
intersection of R with the object in the forward direction
If this distance is less than Dis
Update Dis to this distance
Set Obj to point to this object
End if
Next object
If Obj is not null
Set the position variable Pt to the nearest intersection point of R and Obj
Set the total colour C to black
For each light source in the scene
For each object in the scene
If this object blocks the light coming from the light source to Pt
Attenuate the intensity of the received light by the transmittivity
of the object
End if
Next object
Calculate the perceived colour of Obj at Pt due to this light source
using the value of the attenuated light intensity
Add this colour value to C
Next light source
114 LOVELY PROFESSIONAL UNIVERSITY