220.127.116.11 Initializing the raytracer
#declare MaxDist = 1e5;
#declare ObjAmnt = dimension_size(Coord, 1);
#declare LightAmnt = dimension_size(LVect, 1);
#declare Ind = 0;
#while(Ind < LightAmnt)
#declare LVect[Ind] = vnormalize(LVect[Ind]);
#declare Ind = Ind+1;
Before being able to start the raytracing, we have to intialize a couple of things.
MaxDist defines the maximum distance a surface can be from the starting point of a ray. This means
that if a surface is farther away from the starting point of the ray than this value, it will not be seen. Strictly
speaking this value is unnecessary and we can make the raytracer so that there is no such a limitation, but we save
one extra step when we do it this way, and for scenes sized like ours it does not really matter. (If you really,
really want to get rid of the limitation, I am sure you will figure out yourself how to do it after this tutorial.)
LightAmnt identifiers are declared just to make it easier for us to see
how many objects and lights are there (we need this info to loop through all the objects and lights). Calling the
function is a really nice way of getting the number of items in an array.
All right, now we are getting to a bit more advanced stuff: What does the while-loop do there?
#while-loop uses the
Ind identifier as an index value going from
Ind gets the value
LightAmnt the loop is ended right away). We
also see that we are indexing the
LVect array; thus, it is clear we are going through all the light
sources (specifically through their direction vectors, as we only use the
 part) and we assign
something to them.
What we are doing is to assign a normalized version of each light source direction onto themselves, that is, just
Normalize is a synonym for "convert to unit vector", that is, convert to a vector with the same direction
as the original but with length 1.
Why? We will later see that for illumination calculations we will be needing unit vectors. It is more efficient to
convert the light source directions to unit vectors once at the beginning than every time for each pixel later.