13 |
|
#include "source.h" |
14 |
|
#include "random.h" |
15 |
|
|
16 |
– |
extern double ssampdist; /* scatter sampling distance */ |
17 |
– |
|
16 |
|
#ifndef MAXSSAMP |
17 |
|
#define MAXSSAMP 16 /* maximum samples per ray */ |
18 |
|
#endif |
40 |
|
static int cntcmp(const void *p1, const void *p2); |
41 |
|
|
42 |
|
|
43 |
< |
extern OBJREC * /* find an object's actual material */ |
44 |
< |
findmaterial(register OBJREC *o) |
43 |
> |
OBJREC * /* find an object's actual material */ |
44 |
> |
findmaterial(OBJREC *o) |
45 |
|
{ |
46 |
|
while (!ismaterial(o->otype)) { |
47 |
|
if (o->otype == MOD_ALIAS && o->oargs.nsargs) { |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
< |
extern void |
69 |
> |
void |
70 |
|
marksources(void) /* find and mark source objects */ |
71 |
|
{ |
72 |
|
int foundsource = 0; |
73 |
|
int i; |
74 |
< |
register OBJREC *o, *m; |
75 |
< |
register int ns; |
74 |
> |
OBJREC *o, *m; |
75 |
> |
int ns; |
76 |
|
/* initialize dispatch table */ |
77 |
|
initstypes(); |
78 |
|
/* find direct sources */ |
97 |
|
m->otype == MAT_SPOT ? 7 : 3)) |
98 |
|
objerror(m, USER, "bad # arguments"); |
99 |
|
|
102 |
– |
if (m->otype == MAT_GLOW && |
103 |
– |
o->otype != OBJ_SOURCE && |
104 |
– |
m->oargs.farg[3] <= FTINY) |
105 |
– |
continue; /* don't bother */ |
100 |
|
if (m->oargs.farg[0] <= FTINY && m->oargs.farg[1] <= FTINY && |
101 |
|
m->oargs.farg[2] <= FTINY) |
102 |
|
continue; /* don't bother */ |
103 |
< |
|
103 |
> |
if (m->otype == MAT_GLOW && |
104 |
> |
o->otype != OBJ_SOURCE && |
105 |
> |
m->oargs.farg[3] <= FTINY) { |
106 |
> |
foundsource += (ambounce > 0); |
107 |
> |
continue; /* don't track these */ |
108 |
> |
} |
109 |
|
if (sfun[o->otype].of == NULL || |
110 |
|
sfun[o->otype].of->setsrc == NULL) |
111 |
|
objerror(o, USER, "illegal material"); |
118 |
|
if (m->otype == MAT_GLOW) { |
119 |
|
source[ns].sflags |= SPROX; |
120 |
|
source[ns].sl.prox = m->oargs.farg[3]; |
121 |
< |
if (source[ns].sflags & SDISTANT) |
121 |
> |
if (source[ns].sflags & SDISTANT) { |
122 |
|
source[ns].sflags |= SSKIP; |
123 |
+ |
foundsource += (ambounce > 0); |
124 |
+ |
} |
125 |
|
} else if (m->otype == MAT_SPOT) { |
126 |
|
source[ns].sflags |= SSPOT; |
127 |
|
if ((source[ns].sl.s = makespot(m)) == NULL) |
136 |
|
#if SHADCACHE |
137 |
|
initobscache(ns); |
138 |
|
#endif |
139 |
< |
if (!(source[ns].sflags & SSKIP)) |
139 |
< |
foundsource++; |
139 |
> |
foundsource += !(source[ns].sflags & SSKIP); |
140 |
|
} |
141 |
|
if (!foundsource) { |
142 |
|
error(WARNING, "no light sources found"); |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
< |
extern void |
158 |
> |
void |
159 |
|
freesources(void) /* free all source structures */ |
160 |
|
{ |
161 |
|
if (nsources > 0) { |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
< |
extern int |
181 |
> |
int |
182 |
|
srcray( /* send a ray to a source, return domega */ |
183 |
< |
register RAY *sr, /* returned source ray */ |
183 |
> |
RAY *sr, /* returned source ray */ |
184 |
|
RAY *r, /* ray which hit object */ |
185 |
|
SRCINDEX *si /* source sample index */ |
186 |
|
) |
187 |
|
{ |
188 |
|
double d; /* distance to source */ |
189 |
< |
register SRCREC *srcp; |
189 |
> |
SRCREC *srcp; |
190 |
|
|
191 |
|
rayorigin(sr, SHADOW, r, NULL); /* ignore limits */ |
192 |
|
|
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
< |
extern void |
223 |
> |
void |
224 |
|
srcvalue( /* punch ray to source and compute value */ |
225 |
< |
register RAY *r |
225 |
> |
RAY *r |
226 |
|
) |
227 |
|
{ |
228 |
< |
register SRCREC *sp; |
228 |
> |
SRCREC *sp; |
229 |
|
|
230 |
|
sp = &source[r->rsrc]; |
231 |
|
if (sp->sflags & SVIRTUAL) { /* virtual source */ |
277 |
|
} |
278 |
|
|
279 |
|
|
280 |
< |
extern int |
280 |
> |
int |
281 |
|
sourcehit( /* check to see if ray hit distant source */ |
282 |
< |
register RAY *r |
282 |
> |
RAY *r |
283 |
|
) |
284 |
|
{ |
285 |
|
int glowsrc = -1; |
286 |
|
int transrc = -1; |
287 |
|
int first, last; |
288 |
< |
register int i; |
288 |
> |
int i; |
289 |
|
|
290 |
|
if (r->rsrc >= 0) { /* check only one if aimed */ |
291 |
|
first = last = r->rsrc; |
353 |
|
const void *p2 |
354 |
|
) |
355 |
|
{ |
356 |
< |
register const CNTPTR *sc1 = (const CNTPTR *)p1; |
357 |
< |
register const CNTPTR *sc2 = (const CNTPTR *)p2; |
356 |
> |
const CNTPTR *sc1 = (const CNTPTR *)p1; |
357 |
> |
const CNTPTR *sc2 = (const CNTPTR *)p2; |
358 |
|
|
359 |
|
if (sc1->brt > sc2->brt) |
360 |
|
return(-1); |
364 |
|
} |
365 |
|
|
366 |
|
|
367 |
< |
extern void |
367 |
> |
void |
368 |
|
direct( /* add direct component */ |
369 |
|
RAY *r, /* ray that hit surface */ |
370 |
|
srcdirf_t *f, /* direct component coefficient function */ |
371 |
|
void *p /* data for f */ |
372 |
|
) |
373 |
|
{ |
374 |
< |
register int sn; |
375 |
< |
register CONTRIB *scp; |
374 |
> |
int sn; |
375 |
> |
CONTRIB *scp; |
376 |
|
SRCINDEX si; |
377 |
|
int nshadcheck, ncnts; |
378 |
|
int nhits; |
420 |
|
/* sort contributions */ |
421 |
|
qsort(cntord, sn, sizeof(CNTPTR), cntcmp); |
422 |
|
{ /* find last */ |
423 |
< |
register int l, m; |
423 |
> |
int l, m; |
424 |
|
|
425 |
|
ncnts = l = sn; |
426 |
|
sn = 0; |
440 |
|
/* compute number to check */ |
441 |
|
nshadcheck = pow((double)ncnts, shadcert) + .5; |
442 |
|
/* modify threshold */ |
443 |
< |
ourthresh = shadthresh / r->rweight; |
443 |
> |
if (ncnts > MINSHADCNT) |
444 |
> |
ourthresh = shadthresh / r->rweight; |
445 |
> |
else |
446 |
> |
ourthresh = 0; |
447 |
|
/* test for shadows */ |
448 |
|
for (nhits = 0, hwt = 0.0, sn = 0; sn < ncnts; |
449 |
|
hwt += (double)source[scp->sno].nhits / |
518 |
|
} |
519 |
|
|
520 |
|
|
521 |
< |
extern void |
521 |
> |
void |
522 |
|
srcscatter( /* compute source scattering into ray */ |
523 |
< |
register RAY *r |
523 |
> |
RAY *r |
524 |
|
) |
525 |
|
{ |
526 |
|
int oldsampndx; |
683 |
|
distglow(m, r, raydist(r,PRIMARY))) |
684 |
|
|
685 |
|
|
686 |
< |
extern int |
686 |
> |
int |
687 |
|
m_light( /* ray hit a light source */ |
688 |
< |
register OBJREC *m, |
689 |
< |
register RAY *r |
688 |
> |
OBJREC *m, |
689 |
> |
RAY *r |
690 |
|
) |
691 |
|
{ |
692 |
|
/* check for over-counting */ |