12 |
|
#include "rtotypes.h" |
13 |
|
#include "source.h" |
14 |
|
#include "random.h" |
15 |
+ |
#include "pmapsrc.h" |
16 |
+ |
#include "pmapmat.h" |
17 |
|
|
18 |
|
#ifndef MAXSSAMP |
19 |
|
#define MAXSSAMP 16 /* maximum samples per ray */ |
135 |
|
source[ns].sflags |= SSKIP; |
136 |
|
} |
137 |
|
} |
136 |
– |
#if SHADCACHE |
137 |
– |
initobscache(ns); |
138 |
– |
#endif |
138 |
|
foundsource += !(source[ns].sflags & SSKIP); |
139 |
|
} |
140 |
|
if (!foundsource) { |
141 |
|
error(WARNING, "no light sources found"); |
142 |
|
return; |
143 |
|
} |
144 |
< |
markvirtuals(); /* find and add virtual sources */ |
144 |
> |
#if SHADCACHE |
145 |
> |
for (ns = 0; ns < nsources; ns++) /* initialize obstructor cache */ |
146 |
> |
initobscache(ns); |
147 |
> |
#endif |
148 |
> |
/* PMAP: disable virtual sources */ |
149 |
> |
if (!photonMapping) |
150 |
> |
markvirtuals(); /* find and add virtual sources */ |
151 |
> |
|
152 |
|
/* allocate our contribution arrays */ |
153 |
|
maxcntr = nsources + MAXSPART; /* start with this many */ |
154 |
|
srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB)); |
384 |
|
int nhits; |
385 |
|
double prob, ourthresh, hwt; |
386 |
|
RAY sr; |
387 |
+ |
|
388 |
+ |
/* PMAP: Factor in direct photons (primarily for debugging/validation) */ |
389 |
+ |
if (directPhotonMapping) { |
390 |
+ |
(*f)(r -> rcol, p, r -> ron, PI); |
391 |
+ |
multDirectPmap(r); |
392 |
+ |
return; |
393 |
+ |
} |
394 |
+ |
|
395 |
|
/* NOTE: srccnt and cntord global so no recursion */ |
396 |
|
if (nsources <= 0) |
397 |
|
return; /* no sources?! */ |
543 |
|
SRCINDEX si; |
544 |
|
double t, d; |
545 |
|
double re, ge, be; |
546 |
< |
COLOR cvext; |
546 |
> |
COLOR cvext, pmapInscatter; |
547 |
|
int i, j; |
548 |
|
|
549 |
+ |
/* PMAP: do unconditional inscattering for volume photons ? */ |
550 |
+ |
/* if (!volumePhotonMapping) */ |
551 |
|
if (r->slights == NULL || r->slights[0] == 0 |
552 |
|
|| r->gecc >= 1.-FTINY || r->rot >= FHUGE) |
553 |
|
return; |
554 |
+ |
|
555 |
|
if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1) |
556 |
|
nsamps = 1; |
557 |
|
#if MAXSSAMP |
606 |
|
} |
607 |
|
/* other factors */ |
608 |
|
d *= si.dom * r->rot / (4.*PI*nsamps); |
609 |
+ |
scalecolor(sr.rcol, d); |
610 |
+ |
|
611 |
+ |
/* PMAP: Add ambient inscattering from volume photons once only */ |
612 |
+ |
if (volumePhotonMapping && i == 1) { |
613 |
+ |
inscatterVolumePmap(&sr, pmapInscatter); |
614 |
+ |
scalecolor(pmapInscatter, r -> rot / nsamps); |
615 |
+ |
addcolor(sr.rcol, pmapInscatter); |
616 |
+ |
} |
617 |
+ |
|
618 |
|
multcolor(sr.rcol, r->cext); |
619 |
|
multcolor(sr.rcol, r->albedo); |
594 |
– |
scalecolor(sr.rcol, d); |
620 |
|
multcolor(sr.rcol, cvext); |
621 |
|
addcolor(r->rcol, sr.rcol); /* add it in */ |
622 |
|
} |
683 |
|
* The same is true for stray specular samples, since the specular |
684 |
|
* contribution from light sources is calculated separately. |
685 |
|
*/ |
686 |
< |
|
687 |
< |
#define badcomponent(m, r) (r->crtype&(AMBIENT|SPECULAR) && \ |
686 |
> |
/* PMAP: Also avoid counting sources via transferred ambient rays (e.g. |
687 |
> |
* through glass) when photon mapping is enabled, as these indirect |
688 |
> |
* components are already accounted for. |
689 |
> |
*/ |
690 |
> |
#define badcomponent(m, r) (srcRayInPmap(r) || \ |
691 |
> |
(r->crtype&(AMBIENT|SPECULAR) && \ |
692 |
|
!(r->crtype&SHADOW || r->rod < 0.0 || \ |
693 |
< |
/* not 100% correct */ distglow(m, r, r->rot))) |
693 |
> |
/* not 100% correct */ distglow(m, r, r->rot)))) |
694 |
|
|
695 |
|
/* passillum * |
696 |
|
* |