| 8 |
|
*/ |
| 9 |
|
|
| 10 |
|
#include "ray.h" |
| 11 |
– |
|
| 11 |
|
#include "otypes.h" |
| 12 |
< |
|
| 12 |
> |
#include "rtotypes.h" |
| 13 |
|
#include "source.h" |
| 15 |
– |
|
| 14 |
|
#include "random.h" |
| 15 |
|
|
| 16 |
|
extern double ssampdist; /* scatter sampling distance */ |
| 39 |
|
static CNTPTR *cntord; /* source ordering in direct() */ |
| 40 |
|
static int maxcntr = 0; /* size of contribution arrays */ |
| 41 |
|
|
| 42 |
+ |
static int cntcmp(const void *p1, const void *p2); |
| 43 |
|
|
| 44 |
< |
OBJREC * /* find an object's actual material */ |
| 44 |
> |
|
| 45 |
> |
extern OBJREC * /* find an object's actual material */ |
| 46 |
|
findmaterial(register OBJREC *o) |
| 47 |
|
{ |
| 48 |
|
while (!ismaterial(o->otype)) { |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
< |
void |
| 70 |
< |
marksources() /* find and mark source objects */ |
| 69 |
> |
extern void |
| 70 |
> |
marksources(void) /* find and mark source objects */ |
| 71 |
|
{ |
| 72 |
|
int foundsource = 0; |
| 73 |
|
int i; |
| 83 |
|
if (!issurface(o->otype) || o->omod == OVOID) |
| 84 |
|
continue; |
| 85 |
|
/* find material */ |
| 86 |
< |
m = findmaterial(o); |
| 86 |
> |
m = findmaterial(objptr(o->omod)); |
| 87 |
|
if (m == NULL || !islight(m->otype)) |
| 88 |
|
continue; /* not source modifier */ |
| 89 |
|
|
| 125 |
|
} |
| 126 |
|
} |
| 127 |
|
#if SHADCACHE |
| 128 |
< |
source[ns].obscache = NULL; |
| 128 |
> |
initobscache(ns); |
| 129 |
|
#endif |
| 130 |
|
if (!(source[ns].sflags & SSKIP)) |
| 131 |
|
foundsource++; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
< |
void |
| 151 |
< |
freesources() /* free all source structures */ |
| 150 |
> |
extern void |
| 151 |
> |
freesources(void) /* free all source structures */ |
| 152 |
|
{ |
| 153 |
|
if (nsources > 0) { |
| 154 |
|
#if SHADCACHE |
| 169 |
|
} |
| 170 |
|
|
| 171 |
|
|
| 172 |
< |
int |
| 172 |
> |
extern int |
| 173 |
|
srcray( /* send a ray to a source, return domega */ |
| 174 |
< |
register RAY *sr, /* returned source ray */ |
| 175 |
< |
RAY *r, /* ray which hit object */ |
| 176 |
< |
SRCINDEX *si /* source sample index */ |
| 174 |
> |
register RAY *sr, /* returned source ray */ |
| 175 |
> |
RAY *r, /* ray which hit object */ |
| 176 |
> |
SRCINDEX *si /* source sample index */ |
| 177 |
|
) |
| 178 |
|
{ |
| 179 |
|
double d; /* distance to source */ |
| 208 |
|
} |
| 209 |
|
|
| 210 |
|
|
| 211 |
< |
void |
| 211 |
> |
extern void |
| 212 |
|
srcvalue( /* punch ray to source and compute value */ |
| 213 |
< |
register RAY *r |
| 213 |
> |
register RAY *r |
| 214 |
|
) |
| 215 |
|
{ |
| 216 |
|
register SRCREC *sp; |
| 250 |
|
} |
| 251 |
|
|
| 252 |
|
|
| 253 |
< |
int |
| 253 |
> |
extern int |
| 254 |
|
sourcehit( /* check to see if ray hit distant source */ |
| 255 |
< |
register RAY *r |
| 255 |
> |
register RAY *r |
| 256 |
|
) |
| 257 |
|
{ |
| 258 |
|
int first, last; |
| 292 |
|
|
| 293 |
|
static int |
| 294 |
|
cntcmp( /* contribution compare (descending) */ |
| 295 |
< |
const void *p1, |
| 296 |
< |
const void *p2 |
| 295 |
> |
const void *p1, |
| 296 |
> |
const void *p2 |
| 297 |
|
) |
| 298 |
|
{ |
| 299 |
|
register const CNTPTR *sc1 = (const CNTPTR *)p1; |
| 307 |
|
} |
| 308 |
|
|
| 309 |
|
|
| 310 |
< |
void |
| 310 |
> |
extern void |
| 311 |
|
direct( /* add direct component */ |
| 312 |
< |
RAY *r, /* ray that hit surface */ |
| 313 |
< |
void (*f)(), /* direct component coefficient function */ |
| 314 |
< |
char *p /* data for f */ |
| 312 |
> |
RAY *r, /* ray that hit surface */ |
| 313 |
> |
srcdirf_t *f, /* direct component coefficient function */ |
| 314 |
> |
void *p /* data for f */ |
| 315 |
|
) |
| 316 |
|
{ |
| 317 |
– |
extern void (*trace)(); |
| 317 |
|
register int sn; |
| 318 |
|
register CONTRIB *scp; |
| 319 |
|
SRCINDEX si; |
| 451 |
|
} |
| 452 |
|
|
| 453 |
|
|
| 454 |
< |
void |
| 454 |
> |
extern void |
| 455 |
|
srcscatter( /* compute source scattering into ray */ |
| 456 |
< |
register RAY *r |
| 456 |
> |
register RAY *r |
| 457 |
|
) |
| 458 |
|
{ |
| 459 |
|
int oldsampndx; |
| 499 |
|
if (!srcray(&sr, NULL, &si) || |
| 500 |
|
sr.rsrc != r->slights[i]) |
| 501 |
|
continue; /* no path */ |
| 502 |
+ |
#if SHADCACHE |
| 503 |
+ |
if (srcblocked(&sr)) /* check shadow cache */ |
| 504 |
+ |
continue; |
| 505 |
+ |
#endif |
| 506 |
|
copycolor(sr.cext, r->cext); |
| 507 |
|
copycolor(sr.albedo, r->albedo); |
| 508 |
|
sr.gecc = r->gecc; |
| 509 |
|
sr.slights = r->slights; |
| 510 |
|
rayvalue(&sr); /* eval. source ray */ |
| 511 |
< |
if (bright(sr.rcol) <= FTINY) |
| 511 |
> |
if (bright(sr.rcol) <= FTINY) { |
| 512 |
> |
#if SHADCACHE |
| 513 |
> |
srcblocker(&sr); /* add blocker to cache */ |
| 514 |
> |
#endif |
| 515 |
|
continue; |
| 516 |
+ |
} |
| 517 |
|
if (r->gecc <= FTINY) /* compute P(theta) */ |
| 518 |
|
d = 1.; |
| 519 |
|
else { |
| 551 |
|
*/ |
| 552 |
|
|
| 553 |
|
static int |
| 554 |
< |
weaksrcmat(int obj) /* identify material */ |
| 554 |
> |
weaksrcmat(OBJECT obj) /* identify material */ |
| 555 |
|
{ |
| 556 |
< |
register OBJREC *o = objptr(obj); |
| 556 |
> |
OBJREC *o = findmaterial(objptr(obj)); |
| 557 |
|
|
| 558 |
< |
while (!ismaterial(o->otype)) /* find material */ |
| 552 |
< |
o = objptr(o->omod); |
| 558 |
> |
if (o == NULL) return 0; |
| 559 |
|
return((o->otype==MAT_ILLUM)|(o->otype==MAT_GLOW)); |
| 560 |
|
} |
| 561 |
|
|
| 617 |
|
distglow(m, r, raydist(r,PRIMARY))) |
| 618 |
|
|
| 619 |
|
|
| 620 |
< |
int |
| 620 |
> |
extern int |
| 621 |
|
m_light( /* ray hit a light source */ |
| 622 |
< |
register OBJREC *m, |
| 623 |
< |
register RAY *r |
| 622 |
> |
register OBJREC *m, |
| 623 |
> |
register RAY *r |
| 624 |
|
) |
| 625 |
|
{ |
| 626 |
|
/* check for over-counting */ |