ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/pmapsrc.c
(Generate patch)

Comparing ray/src/rt/pmapsrc.c (file contents):
Revision 2.2 by greg, Tue Apr 21 19:16:51 2015 UTC vs.
Revision 2.16 by rschregle, Sat Apr 7 20:25:10 2018 UTC

# Line 1 | Line 1
1 + #ifndef lint
2 + static const char RCSid[] = "$Id$";
3 + #endif
4   /*
5     ==================================================================
6     Photon map support routines for emission from light sources
7  
8     Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
9     (c) Fraunhofer Institute for Solar Energy Systems,
10 <       Lucerne University of Applied Sciences & Arts  
10 >   (c) Lucerne University of Applied Sciences and Arts,
11 >   supported by the Swiss National Science Foundation (SNSF, #147053)
12     ==================================================================
13 <  
10 <   $Id$
13 >
14   */
15  
16  
# Line 17 | Line 20
20   #include "pmaprand.h"
21   #include "otypes.h"
22  
23 <
24 <
25 < SRCREC *photonPorts = NULL;             /* Photon port list */
23 > /* List of photon port modifier names */
24 > char *photonPortList [MAXSET + 1] = {NULL};
25 > /* Photon port objects (with modifiers in photonPortMods) */
26 > SRCREC *photonPorts = NULL;
27   unsigned numPhotonPorts = 0;
28  
29   void (*photonPartition [NUMOTYPE]) (EmissionMap*);
30   void (*photonOrigin [NUMOTYPE]) (EmissionMap*);
31  
28 extern OBJECT ambset [];
29
32    
33  
34   static int flatPhotonPartition2 (EmissionMap* emap, unsigned long mp,
# Line 518 | Line 520 | static void cylPhotonOrigin (EmissionMap* emap)
520  
521  
522  
523 < void getPhotonPorts ()
524 < /* Find geometry declared as photon ports */
523 > void getPhotonPorts (char **portList)
524 > /* Find geometry declared as photon ports from modifiers in portList */
525   {
526     OBJECT i;
527 <   OBJREC* obj;
527 >   OBJREC *obj, *mat;
528 >   char **lp;  
529    
530 <   /* Check for missing port modifiers */
531 <   if (!ambset [0])
529 <      error(USER, "no photon ports found");
530 >   /* Init photon port objects */
531 >   photonPorts = NULL;
532    
533 +   if (!portList [0])
534 +      return;
535 +  
536     for (i = 0; i < nobjects; i++) {
537        obj = objptr(i);
538 +      mat = findmaterial(obj);
539        
540 <      if (inset(ambset, obj -> omod)) {
541 <         /* Add photon port */
542 <         photonPorts = (SRCREC*)realloc(photonPorts,
543 <                                        (numPhotonPorts + 1) *
544 <                                        sizeof(SRCREC));
539 <         if (!photonPorts)
540 <            error(USER, "can't allocate photon ports");
541 <            
542 <         photonPorts [numPhotonPorts].so = obj;
543 <         photonPorts [numPhotonPorts].sflags = 0;
540 >      /* Check if object is a surface and NOT a light source (duh) and
541 >       * resolve its material via any aliases, then check for inclusion in
542 >       * modifier list */
543 >      if (issurface(obj -> otype) && mat && !islight(mat -> otype)) {
544 >         for (lp = portList; *lp && strcmp(mat -> oname, *lp); lp++);
545          
546 <         if (!sfun [obj -> otype].of || !sfun[obj -> otype].of -> setsrc)
547 <            objerror(obj, USER, "illegal photon port");
546 >         if (*lp) {
547 >            /* Add photon port */
548 >            photonPorts = (SRCREC*)realloc(photonPorts,
549 >                                           (numPhotonPorts + 1) *
550 >                                           sizeof(SRCREC));
551 >            if (!photonPorts)
552 >               error(USER, "can't allocate photon ports");
553              
554 <         setsource(photonPorts + numPhotonPorts, obj);
555 <         numPhotonPorts++;
554 >            photonPorts [numPhotonPorts].so = obj;
555 >            photonPorts [numPhotonPorts].sflags = 0;
556 >        
557 >            if (!sfun [obj -> otype].of || !sfun[obj -> otype].of -> setsrc)
558 >               objerror(obj, USER, "illegal photon port");
559 >        
560 >            setsource(photonPorts + numPhotonPorts, obj);
561 >            numPhotonPorts++;
562 >         }
563        }
564     }
565 +  
566 +   if (!numPhotonPorts)
567 +      error(USER, "no valid photon ports found");
568   }
569  
570  
# Line 591 | Line 607 | void initPhotonEmission (EmissionMap *emap, float numP
607     unsigned i, t, p;
608     double phi, cosTheta, sinTheta, du, dv, dOmega, thetaScale;
609     EmissionSample* sample;
610 <   const OBJREC* mod =  objptr(emap -> src -> so -> omod);
610 >   const OBJREC* mod =  findmaterial(emap -> src -> so);
611     static RAY r;
612   #if 0  
613     static double lastCosNorm = FHUGE;
614     static SRCREC *lastSrc = NULL, *lastPort = NULL;
615   #endif  
616  
617 +   setcolor(emap -> partFlux, 0, 0, 0);
618 +
619     photonOrigin [emap -> src -> so -> otype] (emap);
620     cosTheta = DOT(emap -> ws, emap -> wh);
621  
# Line 620 | Line 638 | void initPhotonEmission (EmissionMap *emap, float numP
638   #endif
639          
640     /* Need to recompute flux & PDF */
623   setcolor(emap -> partFlux, 0, 0, 0);
641     emap -> cdf = 0;
642     emap -> numSamples = 0;
643    
# Line 669 | Line 686 | void initPhotonEmission (EmissionMap *emap, float numP
686          
687        VCOPY(r.rorg, emap -> photonOrg);
688        VCOPY(r.rop, emap -> photonOrg);
689 <      r.rmax = FHUGE;
689 >      r.rmax = 0;
690        
691        for (t = 0; t < emap -> numTheta; t++) {
692           for (p = 0; p < emap -> numPhi; p++) {
# Line 739 | Line 756 | void emitPhoton (const EmissionMap* emap, RAY* ray)
756     unsigned long i, lo, hi;
757     const EmissionSample* sample = emap -> samples;
758     RREAL du, dv, cosTheta, cosThetaSqr, sinTheta, phi;  
759 <   const OBJREC* mod = objptr(emap -> src -> so -> omod);
759 >   const OBJREC* mod = findmaterial(emap -> src -> so);
760    
761     /* Choose a new origin within current partition for every
762        emitted photon to break up clustering artifacts */
763     photonOrigin [emap -> src -> so -> otype] ((EmissionMap*)emap);
764 +   /* If we have a local glow source with a maximum radius, then
765 +      restrict our photon to the specified distance, otherwise we set
766 +      the limit imposed by photonMaxDist (or no limit if 0) */
767 +   if (mod -> otype == MAT_GLOW && !(emap -> src -> sflags & SDISTANT)
768 +                && mod -> oargs.farg[3] > FTINY)
769 +      ray -> rmax = mod -> oargs.farg[3];
770 +   else
771 +      ray -> rmax = photonMaxDist;
772     rayorigin(ray, PRIMARY, NULL, NULL);
748   ray -> rmax = FHUGE;
773    
774     if (!emap -> numSamples) {
775        /* Source is unmodified and has no port, and either local with

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines