--- ray/src/rt/source.c 1996/05/28 13:41:41 2.25 +++ ray/src/rt/source.c 2003/05/14 20:43:46 2.33 @@ -1,19 +1,16 @@ -/* Copyright (c) 1995 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: source.c,v 2.33 2003/05/14 20:43:46 greg Exp $"; #endif - /* * source.c - routines dealing with illumination sources. * - * 8/20/85 + * External symbols declared in source.h */ +#include "copyright.h" + #include "ray.h" -#include "octree.h" - #include "otypes.h" #include "source.h" @@ -47,6 +44,7 @@ static CNTPTR *cntord; /* source ordering in direct static int maxcntr = 0; /* size of contribution arrays */ +void marksources() /* find and mark source objects */ { int foundsource = 0; @@ -56,7 +54,7 @@ marksources() /* find and mark source objects */ /* initialize dispatch table */ initstypes(); /* find direct sources */ - for (i = 0; i < nobjects; i++) { + for (i = 0; i < nsceneobjs; i++) { o = objptr(i); @@ -125,6 +123,25 @@ memerr: } +void +freesources() /* free all source structures */ +{ + if (nsources > 0) { + free((void *)source); + source = NULL; + nsources = 0; + } + if (maxcntr <= 0) + return; + free((void *)srccnt); + srccnt = NULL; + free((void *)cntord); + cntord = NULL; + maxcntr = 0; +} + + +int srcray(sr, r, si) /* send a ray to a source, return domega */ register RAY *sr; /* returned source ray */ RAY *r; /* ray which hit object */ @@ -162,6 +179,7 @@ SRCINDEX *si; /* source sample index */ } +void srcvalue(r) /* punch ray to source and compute value */ register RAY *r; { @@ -202,6 +220,7 @@ nomat: } +int sourcehit(r) /* check to see if ray hit distant source */ register RAY *r; { @@ -227,9 +246,12 @@ register RAY *r; } if (r->ro != NULL) { + r->robj = objndx(r->ro); for (i = 0; i < 3; i++) r->ron[i] = -r->rdir[i]; r->rod = 1.0; + r->pert[0] = r->pert[1] = r->pert[2] = 0.0; + r->uv[0] = r->uv[1] = 0.0; r->rox = NULL; return(1); } @@ -249,12 +271,13 @@ register CNTPTR *sc1, *sc2; } +void direct(r, f, p) /* add direct component */ RAY *r; /* ray that hit surface */ -int (*f)(); /* direct component coefficient function */ +void (*f)(); /* direct component coefficient function */ char *p; /* data for f */ { - extern int (*trace)(); + extern void (*trace)(); register int sn; register CONTRIB *scp; SRCINDEX si; @@ -270,9 +293,9 @@ char *p; /* data for f */ for (sn = 0; srcray(&sr, r, &si); sn++) { if (sn >= maxcntr) { maxcntr = sn + MAXSPART; - srccnt = (CONTRIB *)realloc((char *)srccnt, + srccnt = (CONTRIB *)realloc((void *)srccnt, maxcntr*sizeof(CONTRIB)); - cntord = (CNTPTR *)realloc((char *)cntord, + cntord = (CNTPTR *)realloc((void *)cntord, maxcntr*sizeof(CNTPTR)); if (srccnt == NULL | cntord == NULL) error(SYSTEM, "out of memory in direct"); @@ -374,6 +397,7 @@ char *p; /* data for f */ } +void srcscatter(r) /* compute source scattering into ray */ register RAY *r; { @@ -423,6 +447,7 @@ register RAY *r; copycolor(sr.cext, r->cext); copycolor(sr.albedo, r->albedo); sr.gecc = r->gecc; + sr.slights = r->slights; rayvalue(&sr); /* eval. source ray */ if (bright(sr.rcol) <= FTINY) continue; @@ -524,6 +549,7 @@ return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);} distglow(m, r, raydist(r,PRIMARY))) +int m_light(m, r) /* ray hit a light source */ register OBJREC *m; register RAY *r; @@ -536,7 +562,7 @@ register RAY *r; /* check for passed illum */ if (passillum(m, r)) { if (m->oargs.nsargs && strcmp(m->oargs.sarg[0], VOIDID)) - return(rayshade(r, modifier(m->oargs.sarg[0]))); + return(rayshade(r,lastmod(objndx(m),m->oargs.sarg[0]))); raytrans(r); return(1); }