File: SVFancyRaysImpl.mesa
Created July 3, 1983 12:33 pm
Copyright © 1984 by Xerox Corporation. All rights reserved.
Last edited by Bier on March 1, 1987 7:09:50 pm PST
Contents: Procedures implementing shadows (reflections and transparency to come).
DIRECTORY
AtomButtonsTypes, SVCastRays, SVRay, Feedback, SV3d, SVFancyRays, SVModelTypes, SVRayTypes;
SVFancyRaysImpl: CEDAR PROGRAM
IMPORTS SVCastRays, SVRay, Feedback
EXPORTS SVFancyRays =
BEGIN
CSGTree: TYPE = SVRayTypes.CSGTree;
FeedbackData: TYPE = AtomButtonsTypes.FeedbackData;
LightSource: TYPE = SVModelTypes.LightSource;
LightSourceList: TYPE = SVModelTypes.LightSourceList;
Point3d: TYPE = SV3d.Point3d;
Ray: TYPE = SVRayTypes.Ray;
Vector3d: TYPE = SV3d.Vector3d;
VisibleLights: PUBLIC PROC [allLights: LightSourceList, surfacePoint: Point3d, tree: CSGTree, useBoundSpheres: BOOL, feedback: FeedbackData, makeStream: BOOLFALSE, indent: NAT ← 0] RETURNS [visibleLights: LightSourceList] = {
surfaceToLightRay: Ray;
lightsource: LightSource;
ambient: LightSource;
hits: BOOL;
t: REAL;
IF makeStream THEN Feedback.PutFTypescript[feedback, oneLiner, "\nFinding Visible Lights...\n\n"];
surfaceToLightRay ← SVRay.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;
SVRay.StuffWorldRayFromPoints[surfaceToLightRay, surfacePoint, lightsource.position];
[hits, t] ← SVCastRays.FirstHit[surfaceToLightRay, tree, useBoundSpheres, feedback, makeStream, 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;
IF makeStream THEN {
lightCount: NAT ← CountLights[visibleLights];
Feedback.PutF[feedback, oneLiner, "\n%g Visible Lights found.\n\n", [integer[lightCount]]];
};
SVRay.ReturnRayToPool[surfaceToLightRay];
visibleLights ← CONS[ambient, visibleLights];
The ambient light is never blocked.
};
CountLights: PROC [lights: LightSourceList] RETURNS [count: NAT] = {
count ← 0;
FOR list: LightSourceList ← lights, list.rest UNTIL list = NIL DO
count ← count + 1;
ENDLOOP;
};

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.