|
#declare MaxDist = 1e5; #declare ObjAmnt = dimension_size(Coord, 1); #declare LightAmnt = dimension_size(LVect, 1); #declare Ind = 0; #while(Ind < LightAmnt) #declare LVect[Ind][0] = vnormalize(LVect[Ind][0]); #declare Ind = Ind+1; #end
Before being able to start the raytracing, we have to intialize a couple of things.
The 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's no such a limitation, but we save one extra
step when we do it this way, and for scenes sized like ours it doesn't
really matter. (If you really, really want to get rid of the limitation,
I'm sure you'll figure out yourself how to do it after this tutorial.)
The ObjAmnt
and 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 dimension_size()
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?
The #while
-loop uses the Ind
identifier as
an index value going from 0
to LightAmnt-1
(yes, -1
; when Ind
gets the value
LightAmnt
the loop is ended right away). We also see that
we are indexing the LVect
array; thus, it's clear we are
going through all the light sources (specifically through their direction
vectors, as we only use the [0]
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 normalizing them.
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's more efficient to convert the light source directions to unit vectors once at the beginning than every time for each pixel later.
|