File: SVFancyRaysImpl.mesa
Created July 3, 1983 12:33 pm
Copyright © 1984 by Xerox Corporation. All rights reserved.
Last edited by Bier on August 5, 1984 1:07:19 pm PDT
Contents: Procedures implementing shadows (reflections and transparency to come).
DIRECTORY
CastRays,
CSG,
IO,
SV3d,
SVFancyRays,
SVModelTypes,
SVRayTypes;
SVFancyRaysImpl: PROGRAM
IMPORTS CastRays, CSG, IO
EXPORTS SVFancyRays =
BEGIN
CSGTree: TYPE = SVRayTypes.CSGTree;
LightSource: TYPE = SVModelTypes.LightSource;
LightSourceList: TYPE = SVModelTypes.LightSourceList;
Point3d: TYPE = SV3d.Point3d;
Ray: TYPE = SVRayTypes.Ray;
Vector: TYPE = SV3d.Vector;
VisibleLights: PUBLIC PROC [allLights: LightSourceList, surfacePoint: Point3d, tree: CSGTree, useBoundSpheres: BOOL, makeStream: BOOLFALSE, f: IO.STREAMNIL, indent: NAT ← 0] RETURNS [visibleLights: LightSourceList] = {
surfaceToLightRay: Ray;
lightsource: LightSource;
ambient: LightSource;
hits: BOOL;
t: REAL;
IF makeStream THEN f.PutF["\nFinding Visible Lights...\n\n"];
surfaceToLightRay ← CSG.GetRayFromPool[];
visibleLights ← NIL;
IF allLights.first.type # ambient THEN ERROR;
ambient ← allLights.first; -- CONS on last, so it will be first.
FOR l: LightSourceList ← allLights.rest, l.rest UNTIL l = NIL DO
lightsource ← l.first;
CSG.StuffWorldRayFromPoints[surfaceToLightRay, surfacePoint, lightsource.position];
[hits, t] ← CastRays.FirstHit[surfaceToLightRay, tree, useBoundSpheres, 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;
CSG.ReturnRayToPool[surfaceToLightRay];
visibleLights ← CONS[ambient, visibleLights];
The ambient light is never blocked.
};

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.