Graphics Reference
In-Depth Information
{ Constants }
maxDepth = 10;
{ the maximum number of reflections or refractions we allow }
minShinyness = 0.1;
minTransparency = 0.1;
real refl, refr;
{ Global reflection and refraction coefficients }
real function Shade ( point atPt; shape pointer atObjP; point fromPt, fromN;
shape pointer fromObjP; integer depth )
{ This returns the shade at point atPt on the object to which atObjP points determined by the
light coming from fromPt on object to which fromObjP points. fromN is normal at fromPt. }
begin
boolean rayInObject;
real light; { the intensity }
point viewV, lightV, lightPt, newPt, newN;
ray reflectedRay, refractedRay;
shape pointer newObjP;
if fromObjP = nil then return (background intensity);
viewV := atPt - fromPt;
rayInObject := (atObjP = fromObjP);
{ First we compute the local intensity }
if rayInObject
then light := 0.0
else
begin
light := AmbientLight (atPt);
for all light source location lightPt do
begin
lightV := lightPt - fromPt;
if not (InShadow (fromPt,lightPt) then
light := light + DiffuseLight(viewV,lightV,fromN)
+ SpecularLight(viewV,lightV,fromN);
end
end ;
if depth < maxDepth then
begin
{ Now shoot the reflected ray }
if ShinynessOf (fromObjP) > minShinyness then
begin
reflectedRay := MkReflectedRay (viewV,fromPt,fromN);
FirstIntersection2 (reflectedRay,newPt,newN,newObjP);
if newObjP π nil then
light := light + refl*Shade (fromPt,fromObj,newPt,newN,newObjP);
end ;
Algorithm 10.2.2.
A shade function.
Search WWH ::




Custom Search