1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* source.c - routines dealing with illumination sources. |
6 |
|
* |
7 |
< |
* 8/20/85 |
7 |
> |
* External symbols declared in source.h |
8 |
|
*/ |
9 |
|
|
10 |
+ |
#include "copyright.h" |
11 |
+ |
|
12 |
|
#include "ray.h" |
13 |
|
|
15 |
– |
#include "octree.h" |
16 |
– |
|
14 |
|
#include "otypes.h" |
15 |
|
|
16 |
|
#include "source.h" |
44 |
|
static int maxcntr = 0; /* size of contribution arrays */ |
45 |
|
|
46 |
|
|
47 |
+ |
void |
48 |
|
marksources() /* find and mark source objects */ |
49 |
|
{ |
50 |
|
int foundsource = 0; |
54 |
|
/* initialize dispatch table */ |
55 |
|
initstypes(); |
56 |
|
/* find direct sources */ |
57 |
< |
for (i = 0; i < nobjects; i++) { |
57 |
> |
for (i = 0; i < nsceneobjs; i++) { |
58 |
|
|
59 |
|
o = objptr(i); |
60 |
|
|
115 |
|
maxcntr = nsources + MAXSPART; /* start with this many */ |
116 |
|
srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB)); |
117 |
|
cntord = (CNTPTR *)malloc(maxcntr*sizeof(CNTPTR)); |
118 |
< |
if (srccnt == NULL | cntord == NULL) |
118 |
> |
if ((srccnt == NULL) | (cntord == NULL)) |
119 |
|
goto memerr; |
120 |
|
return; |
121 |
|
memerr: |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
+ |
void |
127 |
+ |
freesources() /* free all source structures */ |
128 |
+ |
{ |
129 |
+ |
if (nsources > 0) { |
130 |
+ |
free((void *)source); |
131 |
+ |
source = NULL; |
132 |
+ |
nsources = 0; |
133 |
+ |
} |
134 |
+ |
if (maxcntr <= 0) |
135 |
+ |
return; |
136 |
+ |
free((void *)srccnt); |
137 |
+ |
srccnt = NULL; |
138 |
+ |
free((void *)cntord); |
139 |
+ |
cntord = NULL; |
140 |
+ |
maxcntr = 0; |
141 |
+ |
} |
142 |
+ |
|
143 |
+ |
|
144 |
+ |
int |
145 |
|
srcray(sr, r, si) /* send a ray to a source, return domega */ |
146 |
|
register RAY *sr; /* returned source ray */ |
147 |
|
RAY *r; /* ray which hit object */ |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
+ |
void |
183 |
|
srcvalue(r) /* punch ray to source and compute value */ |
184 |
|
register RAY *r; |
185 |
|
{ |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
+ |
int |
224 |
|
sourcehit(r) /* check to see if ray hit distant source */ |
225 |
|
register RAY *r; |
226 |
|
{ |
250 |
|
for (i = 0; i < 3; i++) |
251 |
|
r->ron[i] = -r->rdir[i]; |
252 |
|
r->rod = 1.0; |
253 |
+ |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
254 |
+ |
r->uv[0] = r->uv[1] = 0.0; |
255 |
|
r->rox = NULL; |
256 |
|
return(1); |
257 |
|
} |
271 |
|
} |
272 |
|
|
273 |
|
|
274 |
+ |
void |
275 |
|
direct(r, f, p) /* add direct component */ |
276 |
|
RAY *r; /* ray that hit surface */ |
277 |
< |
int (*f)(); /* direct component coefficient function */ |
277 |
> |
void (*f)(); /* direct component coefficient function */ |
278 |
|
char *p; /* data for f */ |
279 |
|
{ |
280 |
< |
extern int (*trace)(); |
280 |
> |
extern void (*trace)(); |
281 |
|
register int sn; |
282 |
|
register CONTRIB *scp; |
283 |
|
SRCINDEX si; |
293 |
|
for (sn = 0; srcray(&sr, r, &si); sn++) { |
294 |
|
if (sn >= maxcntr) { |
295 |
|
maxcntr = sn + MAXSPART; |
296 |
< |
srccnt = (CONTRIB *)realloc((char *)srccnt, |
296 |
> |
srccnt = (CONTRIB *)realloc((void *)srccnt, |
297 |
|
maxcntr*sizeof(CONTRIB)); |
298 |
< |
cntord = (CNTPTR *)realloc((char *)cntord, |
298 |
> |
cntord = (CNTPTR *)realloc((void *)cntord, |
299 |
|
maxcntr*sizeof(CNTPTR)); |
300 |
< |
if (srccnt == NULL | cntord == NULL) |
300 |
> |
if ((srccnt == NULL) | (cntord == NULL)) |
301 |
|
error(SYSTEM, "out of memory in direct"); |
302 |
|
} |
303 |
|
cntord[sn].sndx = sn; |
355 |
|
rayorigin(&sr, r, SHADOW, 1.0); |
356 |
|
VCOPY(sr.rdir, scp->dir); |
357 |
|
sr.rsrc = scp->sno; |
358 |
< |
source[scp->sno].ntests++; /* keep statistics */ |
358 |
> |
/* keep statistics */ |
359 |
> |
if (source[scp->sno].ntests++ > 0xfffffff0) { |
360 |
> |
source[scp->sno].ntests >>= 1; |
361 |
> |
source[scp->sno].nhits >>= 1; |
362 |
> |
} |
363 |
|
if (localhit(&sr, &thescene) && |
364 |
|
( sr.ro != source[scp->sno].so || |
365 |
|
source[scp->sno].sflags & SFOLLOW )) { |
401 |
|
} |
402 |
|
|
403 |
|
|
404 |
+ |
void |
405 |
|
srcscatter(r) /* compute source scattering into ray */ |
406 |
|
register RAY *r; |
407 |
|
{ |
493 |
|
|
494 |
|
static int weaksrcmod(obj) int obj; /* efficiency booster function */ |
495 |
|
{register OBJREC *o = objptr(obj); |
496 |
< |
return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);} |
496 |
> |
return((o->otype==MAT_ILLUM)|(o->otype==MAT_GLOW));} |
497 |
|
|
498 |
|
#define illumblock(m, r) (!(source[r->rsrc].sflags&SVIRTUAL) && \ |
499 |
|
r->rod > 0.0 && \ |
553 |
|
distglow(m, r, raydist(r,PRIMARY))) |
554 |
|
|
555 |
|
|
556 |
+ |
int |
557 |
|
m_light(m, r) /* ray hit a light source */ |
558 |
|
register OBJREC *m; |
559 |
|
register RAY *r; |