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.15 by rschregle, Thu Jun 7 19:26:04 2018 UTC vs.
Revision 2.16 by rschregle, Wed Nov 21 19:33:30 2018 UTC

# Line 52 | Line 52 | static int photonParticipate (RAY *ray)
52     int i;
53     RREAL cosTheta, cosPhi, du, dv;
54     const float cext = colorAvg(ray -> cext),
55 <               albedo = colorAvg(ray -> albedo);
55 >               albedo = colorAvg(ray -> albedo),
56 >               gecc2 = ray -> gecc * ray -> 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 75 | Line 86 | static int photonParticipate (RAY *ray)
86        /* Store volume photons unconditionally in mist to also account for
87           direct inscattering from sources */
88        if (albedo > FTINY)
89 < #endif
89 > #endif      
90           /* Add to volume photon map */
91           newPhoton(volumePmap, ray);
92          
# Line 88 | 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 *
96 <                                                  pmapRandom(scatterState)));
102 >      cosTheta = ray -> gecc <= FTINY
103 >                    ? 2 * pmapRandom(scatterState) - 1
104 >                    : 0.5 * (1 + gecc2 -
105 >                         (1 - gecc2) / (1 - ray -> gecc + 2 * ray -> gecc *
106 >                         pmapRandom(scatterState))) / ray -> gecc;
107                                                    
108        cosPhi = cos(2 * PI * pmapRandom(scatterState));
109        du = dv = sqrt(1 - cosTheta * cosTheta);   /* sin(theta) */
# Line 115 | Line 125 | static int photonParticipate (RAY *ray)
125        ray -> rlvl++;
126        ray -> rmax = -log(pmapRandom(mediumState)) / cext;
127     }  
128 <    
128 >  
129 >   /* Passed through medium until intersecting local object */  
130     setcolor(cvext, exp(-ray -> rot * ray -> cext [0]),
131                     exp(-ray -> rot * ray -> cext [1]),
132                     exp(-ray -> rot * ray -> cext [2]));
133                    
134     /* Modify ray color and normalise */
135     multcolor(ray -> rcol, cvext);
136 <   colorNorm(ray -> rcol);
137 <  
127 <   /* Passed through medium */  
136 >   colorNorm(ray -> rcol);  
137 >
138     return 1;
139   }
140  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines