19 |
|
#include "otypes.h" |
20 |
|
#include "source.h" |
21 |
|
#include "rcontrib.h" |
22 |
+ |
#include "random.h" |
23 |
|
|
24 |
|
|
25 |
|
|
67 |
|
const PhotonPrimary* addPhotonPrimary (PhotonMap *pmap, const RAY *ray) |
68 |
|
{ |
69 |
|
PhotonPrimary *prim = NULL; |
70 |
+ |
FVECT dvec; |
71 |
|
|
72 |
|
if (!pmap || !ray) |
73 |
|
return NULL; |
100 |
|
prim -> srcIdx = -1; |
101 |
|
|
102 |
|
/* Reverse incident direction to point to light source */ |
103 |
< |
prim -> dir [0] = -ray -> rdir [0]; |
104 |
< |
prim -> dir [1] = -ray -> rdir [1]; |
105 |
< |
prim -> dir [2] = -ray -> rdir [2]; |
103 |
> |
dvec [0] = -ray -> rdir [0]; |
104 |
> |
dvec [1] = -ray -> rdir [1]; |
105 |
> |
dvec [2] = -ray -> rdir [2]; |
106 |
> |
prim -> dir = encodedir(dvec); |
107 |
|
|
108 |
|
VCOPY(prim -> pos, ray -> rop); |
109 |
|
|
230 |
|
} |
231 |
|
|
232 |
|
/* Reject photon if normal faces away (ignored for volume photons) */ |
233 |
< |
if (norm && DOT(norm, p -> norm) <= 0) |
233 |
> |
if (norm && DOT(norm, p -> norm) <= 0.5 * frandom()) |
234 |
|
return; |
235 |
|
|
236 |
|
if (isContribPmap(pmap) && pmap -> srcContrib) { |
241 |
|
if (srcIdx < 0 || srcIdx >= nsources) |
242 |
|
error(INTERNAL, "invalid light source index in photon map"); |
243 |
|
|
244 |
< |
srcMod = objptr(source [srcIdx].so -> omod); |
244 |
> |
srcMod = findmaterial(source [srcIdx].so); |
245 |
|
|
246 |
|
/* Reject photon if contributions from light source which emitted it |
247 |
|
* are not sought */ |
456 |
|
dv [2] = pos [2] - p -> pos [2]; |
457 |
|
d2 = DOT(dv, dv); |
458 |
|
|
459 |
< |
if (d2 < pmap -> maxDist && DOT(norm, p -> norm) > 0) { |
459 |
> |
if (d2 < pmap -> maxDist && DOT(norm, p -> norm) > 0.5 * frandom()) { |
460 |
|
/* Closest photon so far with similar normal */ |
461 |
|
pmap -> maxDist = d2; |
462 |
|
*photon = p; |