1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1990 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
32 |
|
SRCREC *source = NULL; /* our list of sources */ |
33 |
|
int nsources = 0; /* the number of sources */ |
34 |
|
|
35 |
+ |
static CONTRIB *srccnt; /* source contributions in direct() */ |
36 |
+ |
static CNTPTR *cntord; /* source ordering in direct() */ |
37 |
|
|
38 |
+ |
|
39 |
|
marksources() /* find and mark source objects */ |
40 |
|
{ |
41 |
|
register OBJREC *o, *m; |
50 |
|
|
51 |
|
m = objptr(o->omod); |
52 |
|
|
53 |
< |
if (m->otype != MAT_LIGHT && |
51 |
< |
m->otype != MAT_ILLUM && |
52 |
< |
m->otype != MAT_GLOW && |
53 |
< |
m->otype != MAT_SPOT) |
53 |
> |
if (!islight(m->otype)) |
54 |
|
continue; |
55 |
|
|
56 |
|
if (m->oargs.nfargs != (m->otype == MAT_GLOW ? 4 : |
68 |
|
source = (SRCREC *)realloc((char *)source, |
69 |
|
(unsigned)(nsources+1)*sizeof(SRCREC)); |
70 |
|
if (source == NULL) |
71 |
< |
error(SYSTEM, "out of memory in marksources"); |
71 |
> |
goto memerr; |
72 |
|
|
73 |
|
newsource(&source[nsources], o); |
74 |
|
|
83 |
|
} |
84 |
|
nsources++; |
85 |
|
} |
86 |
+ |
if (nsources <= 0) { |
87 |
+ |
error(WARNING, "no light sources found"); |
88 |
+ |
return; |
89 |
+ |
} |
90 |
+ |
srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB)); |
91 |
+ |
cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR)); |
92 |
+ |
if (srccnt != NULL && cntord != NULL) |
93 |
+ |
return; |
94 |
+ |
/* fall through */ |
95 |
+ |
memerr: |
96 |
+ |
error(SYSTEM, "out of memory in marksources"); |
97 |
|
} |
98 |
|
|
99 |
|
|
315 |
|
{ |
316 |
|
extern double pow(); |
317 |
|
register int sn; |
307 |
– |
register CONTRIB *srccnt; |
308 |
– |
register CNTPTR *cntord; |
318 |
|
int nshadcheck, ncnts; |
319 |
|
double prob, ourthresh, hwt, test2, hit2; |
320 |
|
RAY sr; |
321 |
< |
|
322 |
< |
srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB)); |
323 |
< |
cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR)); |
315 |
< |
if (srccnt == NULL || cntord == NULL) |
316 |
< |
error(SYSTEM, "out of memory in direct"); |
321 |
> |
/* NOTE: srccnt and cntord global so no recursion */ |
322 |
> |
if (nsources <= 0) |
323 |
> |
return; /* no sources?! */ |
324 |
|
/* compute number to check */ |
325 |
|
nshadcheck = pow((double)nsources, shadcert) + .5; |
326 |
|
/* modify threshold */ |
342 |
|
if (!( source[sn].sflags & SDISTANT ? |
343 |
|
sourcehit(&sr) : |
344 |
|
(*ofun[source[sn].so->otype].funp) |
345 |
< |
(source[sn].so, &sr) )) |
345 |
> |
(source[sn].so, &sr) )) { |
346 |
> |
sprintf(errmsg, |
347 |
> |
"aiming failure for light source \"%s\"", |
348 |
> |
source[sn].so->oname); |
349 |
> |
error(WARNING, errmsg); |
350 |
|
continue; |
351 |
+ |
} |
352 |
|
/* compute contribution */ |
353 |
< |
rayshade(&sr, sr.ro->omod); |
353 |
> |
raycont(&sr); |
354 |
|
multcolor(srccnt[sn].val, sr.rcol); |
355 |
|
cntord[sn].brt = bright(srccnt[sn].val); |
356 |
|
} |
388 |
|
/* test for hit */ |
389 |
|
rayorigin(&sr, r, SHADOW, 1.0); |
390 |
|
VCOPY(sr.rdir, srccnt[cntord[sn].sno].dir); |
391 |
+ |
sr.rsrc = cntord[sn].sno; |
392 |
|
if (localhit(&sr, &thescene) && |
393 |
|
sr.ro != source[cntord[sn].sno].so) { |
394 |
|
/* check for transmission */ |
395 |
< |
if (sr.clipset != NULL && inset(sr.clipset, sr.ro->omod)) |
383 |
< |
raytrans(&sr); |
384 |
< |
else |
385 |
< |
rayshade(&sr, sr.ro->omod); |
395 |
> |
raycont(&sr); |
396 |
|
if (bright(sr.rcol) <= FTINY) |
397 |
|
continue; /* missed! */ |
398 |
|
(*f)(srccnt[cntord[sn].sno].val, p, |
407 |
|
} |
408 |
|
/* weighted hit rate */ |
409 |
|
hwt = hit2 / test2; |
410 |
< |
#ifdef notdef |
410 |
> |
#ifdef DEBUG |
411 |
|
sprintf(errmsg, "%d tested, %d untested, %f hit rate\n", |
412 |
|
sn, ncnts-sn, hwt); |
413 |
|
eputs(errmsg); |
419 |
|
scalecolor(srccnt[cntord[sn].sno].val, prob); |
420 |
|
addcolor(r->rcol, srccnt[cntord[sn].sno].val); |
421 |
|
} |
412 |
– |
|
413 |
– |
free(srccnt); |
414 |
– |
free(cntord); |
422 |
|
} |
423 |
|
|
424 |
|
|
462 |
|
m->oargs.farg[2]); |
463 |
|
/* modify value */ |
464 |
|
multcolor(r->rcol, r->pcol); |
465 |
+ |
/* assign distance */ |
466 |
+ |
r->rt = r->rot; |
467 |
|
} |
468 |
|
} |
460 |
– |
|
461 |
– |
|
462 |
– |
o_source() {} /* intersection with a source is done elsewhere */ |