File: SVFancyRaysImpl.mesa
Author: Eric Bier on July 3, 1983 12:33 pm
Last edited by Bier on August 2, 1983 5:12 pm
Contents: Procedures implementing shadows (reflections and transparency to come).
DIRECTORY
CastRays,
CSG,
IO,
Matrix3d,
Shading,
SVFancyRays,
SVVector3d;
SVFancyRaysImpl:
PROGRAM
IMPORTS CastRays, IO, SVVector3d
EXPORTS SVFancyRays =
BEGIN
CSGTree: TYPE = REF CSGTreeObj;
CSGTreeObj: TYPE = CSG.CSGTreeObj;
LightSource: TYPE = Shading.LightSource;
LightSourceList: TYPE = Shading.LightSourceList;
Point3d: TYPE = Matrix3d.Point3d;
Ray: TYPE = CSG.Ray;
VisibleLights:
PUBLIC
PROC [allLights: LightSourceList, surfacePoint: Point3d, tree: CSGTree, makeStream:
BOOL ←
FALSE, f:
IO.
STREAM ←
NIL, indent:
NAT ← 0]
RETURNS [visibleLights: LightSourceList] = {
surfaceToLightRay: Ray;
lightsource: LightSource;
hits: BOOL;
t: REAL;
IF makeStream THEN f.PutF["\nFinding Visible Lights...\n\n"];
surfaceToLightRay ← CastRays.GetRayFromPool[];
surfaceToLightRay.basePt ← surfacePoint;
visibleLights ← NIL;
FOR l: LightSourceList ← allLights, l.rest
UNTIL l =
NIL
DO
lightsource ← l.first;
surfaceToLightRay.direction ← SVVector3d.Difference[lightsource.position, surfacePoint];
[hits, t] ← CastRays.FirstHit[surfaceToLightRay, tree, makeStream, f, indent];
IF hits
THEN {
IF t >=1 THEN visibleLights ← CONS[lightsource, visibleLights]
The first hit occurs past the light source.
}
ELSE visibleLights ← CONS[lightsource, visibleLights];
ENDLOOP;
CastRays.ReturnRayToPool[surfaceToLightRay];
END.
Edited on August 2, 1983 5:12 pm, by Bier
Fixed VisibleLights so that a light is considered visible even if a ray from surface to light hits an object, so long as that object is past the lightsource.
changes to: VisibleLights, DIRECTORY, SVFancyRaysImpl