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: BOOL _ FALSE, 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] } 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]; }; CountLights: PROC [lights: LightSourceList] RETURNS [count: NAT] = { count _ 0; FOR list: LightSourceList _ lights, list.rest UNTIL list = NIL DO count _ count + 1; ENDLOOP; }; END.  File: SVFancyRaysImpl.mesa Created July 3, 1983 12:33 pm Copyright c 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). The first hit occurs past the light source. The ambient light is never blocked. 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. Κl˜Ihead™J™Jšœ Οmœ1™J™+J˜—Jšžœžœ˜6—Jšžœ˜šžœ žœ˜Jšœ-˜-Jšœ[˜[J˜—Jšžœ$˜)šœžœ˜-J™#—J˜J˜—šŸ œžœžœ žœ˜DJšœ ˜ šžœ+žœžœž˜AJšœ˜Jšžœ˜—J˜Jšœ˜—Jšžœ˜™)Jšœ™J™—J™J™J™—…—”