| 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?! */ |
| 454 |
|
/* compute number to check */ |
| 455 |
|
nshadcheck = pow((double)ncnts, shadcert) + .5; |
| 456 |
|
/* modify threshold */ |
| 457 |
< |
ourthresh = shadthresh / r->rweight; |
| 457 |
> |
if (ncnts > MINSHADCNT) |
| 458 |
> |
ourthresh = shadthresh / r->rweight; |
| 459 |
> |
else |
| 460 |
> |
ourthresh = 0; |
| 461 |
|
/* test for shadows */ |
| 462 |
|
for (nhits = 0, hwt = 0.0, sn = 0; sn < ncnts; |
| 463 |
|
hwt += (double)source[scp->sno].nhits / |
| 546 |
|
COLOR cvext; |
| 547 |
|
int i, j; |
| 548 |
|
|
| 549 |
< |
if (r->slights == NULL || r->slights[0] == 0 |
| 550 |
< |
|| r->gecc >= 1.-FTINY || r->rot >= FHUGE) |
| 549 |
> |
if (r->rot >= FHUGE || r->gecc >= 1.-FTINY) |
| 550 |
> |
return; /* this can never work */ |
| 551 |
> |
/* PMAP: do unconditional inscattering for volume photons */ |
| 552 |
> |
if (!volumePhotonMapping && (r->slights == NULL || r->slights[0] == 0)) |
| 553 |
|
return; |
| 554 |
+ |
|
| 555 |
|
if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1) |
| 556 |
|
nsamps = 1; |
| 557 |
|
#if MAXSSAMP |
| 560 |
|
#endif |
| 561 |
|
oldsampndx = samplendx; |
| 562 |
|
samplendx = random()&0x7fff; /* randomize */ |
| 563 |
< |
for (i = r->slights[0]; i > 0; i--) { /* for each source */ |
| 563 |
> |
for (i = volumePhotonMapping ? 1 : r->slights[0]; i > 0; i--) { |
| 564 |
> |
/* for each source OR once if volume photon map enabled */ |
| 565 |
|
for (j = 0; j < nsamps; j++) { /* for each sample position */ |
| 566 |
|
samplendx++; |
| 567 |
|
t = r->rot * (j+frandom())/nsamps; |
| 577 |
|
sr.rorg[0] = r->rorg[0] + r->rdir[0]*t; |
| 578 |
|
sr.rorg[1] = r->rorg[1] + r->rdir[1]*t; |
| 579 |
|
sr.rorg[2] = r->rorg[2] + r->rdir[2]*t; |
| 580 |
< |
initsrcindex(&si); /* sample ray to this source */ |
| 581 |
< |
si.sn = r->slights[i]; |
| 582 |
< |
nopart(&si, &sr); |
| 583 |
< |
if (!srcray(&sr, NULL, &si) || |
| 584 |
< |
sr.rsrc != r->slights[i]) |
| 585 |
< |
continue; /* no path */ |
| 580 |
> |
|
| 581 |
> |
if (!volumePhotonMapping) { |
| 582 |
> |
initsrcindex(&si); /* sample ray to this source */ |
| 583 |
> |
si.sn = r->slights[i]; |
| 584 |
> |
nopart(&si, &sr); |
| 585 |
> |
if (!srcray(&sr, NULL, &si) || |
| 586 |
> |
sr.rsrc != r->slights[i]) |
| 587 |
> |
continue; /* no path */ |
| 588 |
|
#if SHADCACHE |
| 589 |
< |
if (srcblocked(&sr)) /* check shadow cache */ |
| 590 |
< |
continue; |
| 589 |
> |
if (srcblocked(&sr)) /* check shadow cache */ |
| 590 |
> |
continue; |
| 591 |
|
#endif |
| 592 |
< |
copycolor(sr.cext, r->cext); |
| 593 |
< |
copycolor(sr.albedo, r->albedo); |
| 594 |
< |
sr.gecc = r->gecc; |
| 595 |
< |
sr.slights = r->slights; |
| 596 |
< |
rayvalue(&sr); /* eval. source ray */ |
| 597 |
< |
if (bright(sr.rcol) <= FTINY) { |
| 592 |
> |
copycolor(sr.cext, r->cext); |
| 593 |
> |
copycolor(sr.albedo, r->albedo); |
| 594 |
> |
sr.gecc = r->gecc; |
| 595 |
> |
sr.slights = r->slights; |
| 596 |
> |
rayvalue(&sr); /* eval. source ray */ |
| 597 |
> |
if (bright(sr.rcol) <= FTINY) { |
| 598 |
|
#if SHADCACHE |
| 599 |
< |
srcblocker(&sr); /* add blocker to cache */ |
| 599 |
> |
srcblocker(&sr); /* add blocker to cache */ |
| 600 |
|
#endif |
| 601 |
< |
continue; |
| 602 |
< |
} |
| 603 |
< |
if (r->gecc <= FTINY) /* compute P(theta) */ |
| 604 |
< |
d = 1.; |
| 605 |
< |
else { |
| 606 |
< |
d = DOT(r->rdir, sr.rdir); |
| 607 |
< |
d = 1. + r->gecc*r->gecc - 2.*r->gecc*d; |
| 608 |
< |
d = (1. - r->gecc*r->gecc) / (d*sqrt(d)); |
| 609 |
< |
} |
| 601 |
> |
continue; |
| 602 |
> |
} |
| 603 |
> |
if (r->gecc <= FTINY) /* compute P(theta) */ |
| 604 |
> |
d = 1.; |
| 605 |
> |
else { |
| 606 |
> |
d = DOT(r->rdir, sr.rdir); |
| 607 |
> |
d = 1. + r->gecc*r->gecc - 2.*r->gecc*d; |
| 608 |
> |
d = (1. - r->gecc*r->gecc) / (d*sqrt(d)); |
| 609 |
> |
} |
| 610 |
|
/* other factors */ |
| 611 |
< |
d *= si.dom * r->rot / (4.*PI*nsamps); |
| 611 |
> |
d *= si.dom * r->rot / (4.*PI*nsamps); |
| 612 |
> |
scalecolor(sr.rcol, d); |
| 613 |
> |
} else { |
| 614 |
> |
/* PMAP: Add ambient inscattering from |
| 615 |
> |
* volume photons; note we reverse the |
| 616 |
> |
* incident ray direction since we're |
| 617 |
> |
* now in *backward* raytracing mode! */ |
| 618 |
> |
sr.rdir [0] = -r -> rdir [0]; |
| 619 |
> |
sr.rdir [1] = -r -> rdir [1]; |
| 620 |
> |
sr.rdir [2] = -r -> rdir [2]; |
| 621 |
> |
sr.gecc = r -> gecc; |
| 622 |
> |
inscatterVolumePmap(&sr, sr.rcol); |
| 623 |
> |
scalecolor(sr.rcol, r -> rot / nsamps); |
| 624 |
> |
} |
| 625 |
|
multcolor(sr.rcol, r->cext); |
| 626 |
|
multcolor(sr.rcol, r->albedo); |
| 591 |
– |
scalecolor(sr.rcol, d); |
| 627 |
|
multcolor(sr.rcol, cvext); |
| 628 |
|
addcolor(r->rcol, sr.rcol); /* add it in */ |
| 629 |
|
} |
| 690 |
|
* The same is true for stray specular samples, since the specular |
| 691 |
|
* contribution from light sources is calculated separately. |
| 692 |
|
*/ |
| 693 |
< |
|
| 694 |
< |
#define badcomponent(m, r) (r->crtype&(AMBIENT|SPECULAR) && \ |
| 693 |
> |
/* PMAP: Also avoid counting sources via transferred ambient rays (e.g. |
| 694 |
> |
* through glass) when photon mapping is enabled, as these indirect |
| 695 |
> |
* components are already accounted for. |
| 696 |
> |
*/ |
| 697 |
> |
#define badcomponent(m, r) (srcRayInPmap(r) || \ |
| 698 |
> |
(r->crtype&(AMBIENT|SPECULAR) && \ |
| 699 |
|
!(r->crtype&SHADOW || r->rod < 0.0 || \ |
| 700 |
< |
/* not 100% correct */ distglow(m, r, r->rot))) |
| 700 |
> |
/* not 100% correct */ distglow(m, r, r->rot)))) |
| 701 |
|
|
| 702 |
|
/* passillum * |
| 703 |
|
* |