--- ray/src/rt/source.c 1993/04/06 17:55:51 2.11 +++ ray/src/rt/source.c 1995/04/25 19:51:38 2.16 @@ -68,6 +68,9 @@ marksources() /* find and mark source objects */ o->otype != OBJ_SOURCE && m->oargs.farg[3] <= FTINY) continue; /* don't bother */ + if (m->oargs.farg[0] <= FTINY && m->oargs.farg[1] <= FTINY && + m->oargs.farg[2] <= FTINY) + continue; /* don't bother */ if (sfun[o->otype].of == NULL || sfun[o->otype].of->setsrc == NULL) @@ -152,7 +155,7 @@ SRCINDEX *si; /* source sample index */ srcvalue(r) /* punch ray to source and compute value */ -RAY *r; +register RAY *r; { register SRCREC *sp; @@ -161,7 +164,8 @@ RAY *r; /* check intersection */ if (!(*ofun[sp->so->otype].funp)(sp->so, r)) return; - raycont(r); /* compute contribution */ + if (!rayshade(r, r->ro->omod)) /* compute contribution */ + goto nomat; return; } /* compute intersection */ @@ -169,9 +173,11 @@ RAY *r; (*ofun[sp->so->otype].funp)(sp->so, r)) { if (sp->sa.success >= 0) sp->sa.success++; - raycont(r); /* compute contribution */ + if (!rayshade(r, r->ro->omod)) /* compute contribution */ + goto nomat; return; } + /* we missed our mark! */ if (sp->sa.success < 0) return; /* bitched already */ sp->sa.success -= AIMREQT; @@ -180,6 +186,9 @@ RAY *r; sprintf(errmsg, "aiming failure for light source \"%s\"", sp->so->oname); error(WARNING, errmsg); /* issue warning */ + return; +nomat: + objerror(r->ro, USER, "material not found"); } @@ -299,8 +308,10 @@ char *p; /* data for f */ /* modify threshold */ ourthresh = shadthresh / r->rweight; /* test for shadows */ - nhits = 0; - for (sn = 0; sn < ncnts; sn++) { + for (nhits = 0, hwt = 0.0, sn = 0; sn < ncnts; + hwt += (double)source[scp->sno].nhits / + (double)source[scp->sno].ntests, + sn++) { /* check threshold */ if ((sn+nshadcheck>=ncnts ? cntord[sn].brt : cntord[sn].brt-cntord[sn+nshadcheck].brt) @@ -316,7 +327,8 @@ char *p; /* data for f */ ( sr.ro != source[scp->sno].so || source[scp->sno].sflags & SFOLLOW )) { /* follow entire path */ - raycont(&sr); + if (!raycont(&sr)) + objerror(sr.ro, USER, "material not found"); if (trace != NULL) (*trace)(&sr); /* trace execution */ if (bright(sr.rcol) <= FTINY) @@ -329,13 +341,13 @@ char *p; /* data for f */ nhits++; source[scp->sno].nhits++; } - /* surface hit rate */ - if (sn > 0) - hwt = (double)nhits / (double)sn; + /* source hit rate */ + if (hwt > FTINY) + hwt = (double)nhits / hwt; else hwt = 0.5; #ifdef DEBUG - sprintf(errmsg, "%d tested, %d untested, %f hit rate\n", + sprintf(errmsg, "%d tested, %d untested, %f conditional hit rate\n", sn, ncnts-sn, hwt); eputs(errmsg); #endif @@ -344,6 +356,8 @@ char *p; /* data for f */ scp = srccnt + cntord[sn].sndx; prob = hwt * (double)source[scp->sno].nhits / (double)source[scp->sno].ntests; + if (prob > 1.0) + prob = 1.0; scalecolor(scp->val, prob); addcolor(r->rcol, scp->val); } @@ -371,6 +385,7 @@ static int weaksrcmod(obj) int obj; /* efficiency boos return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);} #define illumblock(m, r) (!(source[r->rsrc].sflags&SVIRTUAL) && \ + r->rod > 0.0 && \ weaksrcmod(source[r->rsrc].so->omod)) /* wrongsource * @@ -407,13 +422,6 @@ return(o->otype==MAT_ILLUM|o->otype==MAT_GLOW);} !(r->crtype&SHADOW || r->rod < 0.0 || \ distglow(m, r))) -/* overcount * - * - * All overcounting possibilities are contained here. - */ - -#define overcount(m, r) (badcomponent(m,r) || wrongsource(m,r)) - /* passillum * * * An illum passes to another material type when we didn't hit it @@ -439,26 +447,27 @@ register OBJREC *m; register RAY *r; { /* check for over-counting */ - if (overcount(m, r)) - return; + if (badcomponent(m, r)) + return(1); + if (wrongsource(m,r)) + return(1); /* check for passed illum */ if (passillum(m, r)) { - if (m->oargs.nsargs < 1 || !strcmp(m->oargs.sarg[0], VOIDID)) - raytrans(r); - else - rayshade(r, modifier(m->oargs.sarg[0])); - return; + if (m->oargs.nsargs && strcmp(m->oargs.sarg[0], VOIDID)) + return(rayshade(r, modifier(m->oargs.sarg[0]))); + raytrans(r); + return(1); } /* otherwise treat as source */ /* check for behind */ if (r->rod < 0.0) - return; + return(1); /* check for invisibility */ if (srcignore(m, r)) - return; + return(1); /* check for outside spot */ if (m->otype==MAT_SPOT && spotout(r, makespot(m), r->rot>=FHUGE)) - return; + return(1); /* get distribution pattern */ raytexture(r, m->omod); /* get source color */ @@ -467,4 +476,5 @@ register RAY *r; m->oargs.farg[2]); /* modify value */ multcolor(r->rcol, r->pcol); + return(1); }