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

Comparing ray/src/rt/pmap.c (file contents):
Revision 2.13 by rschregle, Mon Aug 14 21:12:10 2017 UTC vs.
Revision 2.17 by rschregle, Tue Dec 18 22:14:04 2018 UTC

# Line 50 | Line 50 | static int photonParticipate (RAY *ray)
50     or 0 if absorbed and $*%&ed. Analogon to rayparticipate(). */
51   {
52     int i;
53 <   RREAL cosTheta, cosPhi, du, dv;
53 >   RREAL xi1, cosTheta, phi, du, dv;
54     const float cext = colorAvg(ray -> cext),
55 <               albedo = colorAvg(ray -> albedo);
55 >               albedo = colorAvg(ray -> albedo),
56 >               gecc = ray -> gecc, gecc2 = sqr(gecc);
57     FVECT u, v;
58     COLOR cvext;
59  
# Line 60 | Line 61 | static int photonParticipate (RAY *ray)
61     ray -> rmax = -log(pmapRandom(mediumState)) / cext;
62    
63     while (!localhit(ray, &thescene)) {
64 +      if (!incube(&thescene, ray -> rop)) {
65 +         /* Terminate photon if it has leaked from the scene */
66 + #ifdef DEBUG_PMAP
67 +         fprintf(stderr,
68 +                 "Volume photon leaked from scene at [%.3f %.3f %.3f]\n",
69 +                 ray -> rop [0], ray -> rop [1], ray -> rop [2]);
70 + #endif                
71 +         return 0;
72 +      }
73 +        
74        setcolor(cvext, exp(-ray -> rmax * ray -> cext [0]),
75                        exp(-ray -> rmax * ray -> cext [1]),
76                        exp(-ray -> rmax * ray -> cext [2]));
# Line 69 | Line 80 | static int photonParticipate (RAY *ray)
80        colorNorm(ray -> rcol);
81        VCOPY(ray -> rorg, ray -> rop);
82        
83 + #if 0
84        if (albedo > FTINY && ray -> rlvl > 0)
85 + #else
86 +      /* Store volume photons unconditionally in mist to also account for
87 +         direct inscattering from sources */
88 +      if (albedo > FTINY)
89 + #endif
90           /* Add to volume photon map */
91           newPhoton(volumePmap, ray);
92          
# Line 82 | Line 99 | static int photonParticipate (RAY *ray)
99        scalecolor(ray -> rcol, 1 / albedo);    
100        
101        /* Scatter photon */
102 <      cosTheta = ray -> gecc <= FTINY ? 2 * pmapRandom(scatterState) - 1
103 <                                      : 1 / (2 * ray -> gecc) *
104 <                                            (1 + ray -> gecc * ray -> gecc -
105 <                                               (1 - ray -> gecc * ray -> gecc) /
106 <                                               (1 - ray -> gecc + 2 * ray -> gecc *
107 <                                                  pmapRandom(scatterState)));
108 <                                                  
109 <      cosPhi = cos(2 * PI * pmapRandom(scatterState));
110 <      du = dv = sqrt(1 - cosTheta * cosTheta);   /* sin(theta) */
111 <      du *= cosPhi;
112 <      dv *= sqrt(1 - cosPhi * cosPhi);           /* sin(phi) */
102 >      xi1 = pmapRandom(scatterState);
103 >      cosTheta = ray -> gecc <= FTINY
104 >                    ? 2 * xi1 - 1
105 >                    : 0.5 / gecc *
106 >                      (1 + gecc2 - sqr((1 - gecc2) /
107 >                                       (1 + gecc * (2 * xi1 - 1))));
108 >
109 >      phi = 2 * PI * pmapRandom(scatterState);
110 >      du = dv = sqrt(1 - sqr(cosTheta));     /* sin(theta) */
111 >      du *= cos(phi);
112 >      dv *= sin(phi);
113        
114        /* Get axes u & v perpendicular to photon direction */
115        i = 0;
# Line 106 | Line 123 | static int photonParticipate (RAY *ray)
123        for (i = 0; i < 3; i++)
124           ray -> rdir [i] = du * u [i] + dv * v [i] +
125                             cosTheta * ray -> rdir [i];
126 +
127        ray -> rlvl++;
128        ray -> rmax = -log(pmapRandom(mediumState)) / cext;
129     }  
130 <    
130 >  
131 >   /* Passed through medium until intersecting local object */  
132     setcolor(cvext, exp(-ray -> rot * ray -> cext [0]),
133                     exp(-ray -> rot * ray -> cext [1]),
134                     exp(-ray -> rot * ray -> cext [2]));
135                    
136     /* Modify ray color and normalise */
137     multcolor(ray -> rcol, cvext);
138 <   colorNorm(ray -> rcol);
139 <  
121 <   /* Passed through medium */  
138 >   colorNorm(ray -> rcol);  
139 >
140     return 1;
141   }
142  
# Line 333 | Line 351 | void distribPhotons (PhotonMap **pmaps, unsigned numPr
351     initPhotonEmissionFuncs();
352     initPhotonScatterFuncs();
353    
354 <   /* Get photon ports if specified */
355 <   if (ambincl == 1)
338 <      getPhotonPorts();
354 >   /* Get photon ports from modifier list */
355 >   getPhotonPorts(photonPortList);
356  
357     /* Get photon sensor modifiers */
358     getPhotonSensors(photonSensorList);
# Line 445 | Line 462 | void distribPhotons (PhotonMap **pmaps, unsigned numPr
462           pmapSeed(randSeed + (proc + 3) % numProc, mediumState);
463           pmapSeed(randSeed + (proc + 4) % numProc, scatterState);
464           pmapSeed(randSeed + (proc + 5) % numProc, rouletteState);
465 <                  
465 >              
466 > #ifdef DEBUG_PMAP          
467 >         /* Output child process PID after random delay to prevent corrupted
468 >          * console output due to race condition */
469 >         usleep(1e6 * pmapRandom(rouletteState));
470 >         fprintf(stderr, "Proc %d: PID = %d "
471 >                 "(waiting 10 sec to attach debugger...)\n",
472 >                 proc, getpid());
473 >         /* Allow time for debugger to attach to child process */
474 >         sleep(10);
475 > #endif            
476 >
477           for (t = 0; t < NUM_PMAP_TYPES; t++)
478              lastNumPhotons [t] = 0;
479              

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines