| 12 |
|
#include "rtotypes.h" |
| 13 |
|
#include "source.h" |
| 14 |
|
#include "random.h" |
| 15 |
+ |
#include "pmap.h" |
| 16 |
+ |
#include "pmapsrc.h" |
| 17 |
|
|
| 16 |
– |
extern double ssampdist; /* scatter sampling distance */ |
| 17 |
– |
|
| 18 |
|
#ifndef MAXSSAMP |
| 19 |
|
#define MAXSSAMP 16 /* maximum samples per ray */ |
| 20 |
|
#endif |
| 42 |
|
static int cntcmp(const void *p1, const void *p2); |
| 43 |
|
|
| 44 |
|
|
| 45 |
< |
extern OBJREC * /* find an object's actual material */ |
| 46 |
< |
findmaterial(register OBJREC *o) |
| 45 |
> |
OBJREC * /* find an object's actual material */ |
| 46 |
> |
findmaterial(OBJREC *o) |
| 47 |
|
{ |
| 48 |
|
while (!ismaterial(o->otype)) { |
| 49 |
|
if (o->otype == MOD_ALIAS && o->oargs.nsargs) { |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
|
| 71 |
< |
extern void |
| 71 |
> |
void |
| 72 |
|
marksources(void) /* find and mark source objects */ |
| 73 |
|
{ |
| 74 |
|
int foundsource = 0; |
| 75 |
|
int i; |
| 76 |
< |
register OBJREC *o, *m; |
| 77 |
< |
register int ns; |
| 76 |
> |
OBJREC *o, *m; |
| 77 |
> |
int ns; |
| 78 |
|
/* initialize dispatch table */ |
| 79 |
|
initstypes(); |
| 80 |
|
/* find direct sources */ |
| 135 |
|
source[ns].sflags |= SSKIP; |
| 136 |
|
} |
| 137 |
|
} |
| 138 |
– |
#if SHADCACHE |
| 139 |
– |
initobscache(ns); |
| 140 |
– |
#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 |
> |
initobscache(ns); |
| 146 |
> |
#endif |
| 147 |
> |
/* PMAP: disable virtual sources */ |
| 148 |
> |
if (!photonMapping) |
| 149 |
> |
markvirtuals(); /* find and add virtual sources */ |
| 150 |
> |
|
| 151 |
|
/* allocate our contribution arrays */ |
| 152 |
|
maxcntr = nsources + MAXSPART; /* start with this many */ |
| 153 |
|
srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB)); |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
|
| 163 |
< |
extern void |
| 163 |
> |
void |
| 164 |
|
freesources(void) /* free all source structures */ |
| 165 |
|
{ |
| 166 |
|
if (nsources > 0) { |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
|
| 186 |
< |
extern int |
| 186 |
> |
int |
| 187 |
|
srcray( /* send a ray to a source, return domega */ |
| 188 |
< |
register RAY *sr, /* returned source ray */ |
| 188 |
> |
RAY *sr, /* returned source ray */ |
| 189 |
|
RAY *r, /* ray which hit object */ |
| 190 |
|
SRCINDEX *si /* source sample index */ |
| 191 |
|
) |
| 192 |
|
{ |
| 193 |
|
double d; /* distance to source */ |
| 194 |
< |
register SRCREC *srcp; |
| 194 |
> |
SRCREC *srcp; |
| 195 |
|
|
| 196 |
|
rayorigin(sr, SHADOW, r, NULL); /* ignore limits */ |
| 197 |
|
|
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
|
| 228 |
< |
extern void |
| 228 |
> |
void |
| 229 |
|
srcvalue( /* punch ray to source and compute value */ |
| 230 |
< |
register RAY *r |
| 230 |
> |
RAY *r |
| 231 |
|
) |
| 232 |
|
{ |
| 233 |
< |
register SRCREC *sp; |
| 233 |
> |
SRCREC *sp; |
| 234 |
|
|
| 235 |
|
sp = &source[r->rsrc]; |
| 236 |
|
if (sp->sflags & SVIRTUAL) { /* virtual source */ |
| 282 |
|
} |
| 283 |
|
|
| 284 |
|
|
| 285 |
< |
extern int |
| 285 |
> |
int |
| 286 |
|
sourcehit( /* check to see if ray hit distant source */ |
| 287 |
< |
register RAY *r |
| 287 |
> |
RAY *r |
| 288 |
|
) |
| 289 |
|
{ |
| 290 |
|
int glowsrc = -1; |
| 291 |
|
int transrc = -1; |
| 292 |
|
int first, last; |
| 293 |
< |
register int i; |
| 293 |
> |
int i; |
| 294 |
|
|
| 295 |
|
if (r->rsrc >= 0) { /* check only one if aimed */ |
| 296 |
|
first = last = r->rsrc; |
| 358 |
|
const void *p2 |
| 359 |
|
) |
| 360 |
|
{ |
| 361 |
< |
register const CNTPTR *sc1 = (const CNTPTR *)p1; |
| 362 |
< |
register const CNTPTR *sc2 = (const CNTPTR *)p2; |
| 361 |
> |
const CNTPTR *sc1 = (const CNTPTR *)p1; |
| 362 |
> |
const CNTPTR *sc2 = (const CNTPTR *)p2; |
| 363 |
|
|
| 364 |
|
if (sc1->brt > sc2->brt) |
| 365 |
|
return(-1); |
| 369 |
|
} |
| 370 |
|
|
| 371 |
|
|
| 372 |
< |
extern void |
| 372 |
> |
void |
| 373 |
|
direct( /* add direct component */ |
| 374 |
|
RAY *r, /* ray that hit surface */ |
| 375 |
|
srcdirf_t *f, /* direct component coefficient function */ |
| 376 |
|
void *p /* data for f */ |
| 377 |
|
) |
| 378 |
|
{ |
| 379 |
< |
register int sn; |
| 380 |
< |
register CONTRIB *scp; |
| 379 |
> |
int sn; |
| 380 |
> |
CONTRIB *scp; |
| 381 |
|
SRCINDEX si; |
| 382 |
|
int nshadcheck, ncnts; |
| 383 |
|
int nhits; |
| 384 |
|
double prob, ourthresh, hwt; |
| 385 |
|
RAY sr; |
| 386 |
+ |
|
| 387 |
+ |
/* PMAP: Factor in direct photons (primarily for debugging/validation) */ |
| 388 |
+ |
if (directPhotonMapping) { |
| 389 |
+ |
(*f)(r -> rcol, p, r -> ron, PI); |
| 390 |
+ |
multDirectPmap(r); |
| 391 |
+ |
return; |
| 392 |
+ |
} |
| 393 |
+ |
|
| 394 |
|
/* NOTE: srccnt and cntord global so no recursion */ |
| 395 |
|
if (nsources <= 0) |
| 396 |
|
return; /* no sources?! */ |
| 433 |
|
/* sort contributions */ |
| 434 |
|
qsort(cntord, sn, sizeof(CNTPTR), cntcmp); |
| 435 |
|
{ /* find last */ |
| 436 |
< |
register int l, m; |
| 436 |
> |
int l, m; |
| 437 |
|
|
| 438 |
|
ncnts = l = sn; |
| 439 |
|
sn = 0; |
| 453 |
|
/* compute number to check */ |
| 454 |
|
nshadcheck = pow((double)ncnts, shadcert) + .5; |
| 455 |
|
/* modify threshold */ |
| 456 |
< |
ourthresh = shadthresh / r->rweight; |
| 456 |
> |
if (ncnts > MINSHADCNT) |
| 457 |
> |
ourthresh = shadthresh / r->rweight; |
| 458 |
> |
else |
| 459 |
> |
ourthresh = 0; |
| 460 |
|
/* test for shadows */ |
| 461 |
|
for (nhits = 0, hwt = 0.0, sn = 0; sn < ncnts; |
| 462 |
|
hwt += (double)source[scp->sno].nhits / |
| 531 |
|
} |
| 532 |
|
|
| 533 |
|
|
| 534 |
< |
extern void |
| 534 |
> |
void |
| 535 |
|
srcscatter( /* compute source scattering into ray */ |
| 536 |
< |
register RAY *r |
| 536 |
> |
RAY *r |
| 537 |
|
) |
| 538 |
|
{ |
| 539 |
|
int oldsampndx; |
| 542 |
|
SRCINDEX si; |
| 543 |
|
double t, d; |
| 544 |
|
double re, ge, be; |
| 545 |
< |
COLOR cvext; |
| 545 |
> |
COLOR cvext, pmapInscatter; |
| 546 |
|
int i, j; |
| 547 |
|
|
| 548 |
+ |
/* PMAP: do unconditional inscattering for volume photons ? */ |
| 549 |
+ |
/* if (!volumePhotonMapping) */ |
| 550 |
|
if (r->slights == NULL || r->slights[0] == 0 |
| 551 |
|
|| r->gecc >= 1.-FTINY || r->rot >= FHUGE) |
| 552 |
|
return; |
| 553 |
+ |
|
| 554 |
|
if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1) |
| 555 |
|
nsamps = 1; |
| 556 |
|
#if MAXSSAMP |
| 605 |
|
} |
| 606 |
|
/* other factors */ |
| 607 |
|
d *= si.dom * r->rot / (4.*PI*nsamps); |
| 608 |
+ |
scalecolor(sr.rcol, d); |
| 609 |
+ |
|
| 610 |
+ |
/* PMAP: Add ambient inscattering from volume photons once only */ |
| 611 |
+ |
if (volumePhotonMapping && i == 1) { |
| 612 |
+ |
inscatterVolumePmap(&sr, pmapInscatter); |
| 613 |
+ |
scalecolor(pmapInscatter, r -> rot / nsamps); |
| 614 |
+ |
addcolor(sr.rcol, pmapInscatter); |
| 615 |
+ |
} |
| 616 |
+ |
|
| 617 |
|
multcolor(sr.rcol, r->cext); |
| 618 |
|
multcolor(sr.rcol, r->albedo); |
| 593 |
– |
scalecolor(sr.rcol, d); |
| 619 |
|
multcolor(sr.rcol, cvext); |
| 620 |
|
addcolor(r->rcol, sr.rcol); /* add it in */ |
| 621 |
|
} |
| 707 |
|
distglow(m, r, raydist(r,PRIMARY))) |
| 708 |
|
|
| 709 |
|
|
| 710 |
< |
extern int |
| 710 |
> |
int |
| 711 |
|
m_light( /* ray hit a light source */ |
| 712 |
< |
register OBJREC *m, |
| 713 |
< |
register RAY *r |
| 712 |
> |
OBJREC *m, |
| 713 |
> |
RAY *r |
| 714 |
|
) |
| 715 |
|
{ |
| 716 |
|
/* check for over-counting */ |