--- ray/src/rt/source.c 2022/06/08 17:18:41 2.79 +++ ray/src/rt/source.c 2024/11/15 20:47:42 2.84 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: source.c,v 2.79 2022/06/08 17:18:41 greg Exp $"; +static const char RCSid[] = "$Id: source.c,v 2.84 2024/11/15 20:47:42 greg Exp $"; #endif /* * source.c - routines dealing with illumination sources. @@ -27,8 +27,8 @@ static const char RCSid[] = "$Id: source.c,v 2.79 2022 typedef struct { int sno; /* source number */ FVECT dir; /* source direction */ - COLOR coef; /* material coefficient */ - COLOR val; /* contribution */ + SCOLOR coef; /* material coefficient */ + SCOLOR val; /* contribution */ } CONTRIB; /* direct contribution */ typedef struct { @@ -200,16 +200,19 @@ freesources(void) /* free all source structures */ while (nsources--) freeobscache(&source[nsources]); #endif - free((void *)source); +#ifdef SSKIPOPT + sskip_rsi(NULL); +#endif + free(source); source = NULL; nsources = 0; } markclip(NULL); if (maxcntr <= 0) return; - free((void *)srccnt); + free(srccnt); srccnt = NULL; - free((void *)cntord); + free(cntord); cntord = NULL; maxcntr = 0; } @@ -435,23 +438,31 @@ direct( /* add direct component */ scp->sno = sr.rsrc; #if SHADCACHE /* check shadow cache */ if (si.np == 1 && srcblocked(&sr)) { - cntord[sn].brt = 0.0; + cntord[sn].brt = 0.0; /* & count as test */ + if (source[scp->sno].ntests++ > 0xfffffff0) { + source[scp->sno].ntests >>= 1; + source[scp->sno].nhits >>= 1; + } continue; } #endif /* compute coefficient */ (*f)(scp->coef, p, sr.rdir, si.dom); - cntord[sn].brt = intens(scp->coef); + cntord[sn].brt = sintens(scp->coef); if (cntord[sn].brt <= 0.0) continue; +#ifdef SSKIPOPT + if (ssf_select != NULL && sskip_chk(ssf_select, scp->sno)) + scalescolor(scp->coef, r->scorr); +#endif VCOPY(scp->dir, sr.rdir); - copycolor(sr.rcoef, scp->coef); + copyscolor(sr.rcoef, scp->coef); /* compute potential */ sr.revf = srcvalue; rayvalue(&sr); - multcolor(sr.rcol, sr.rcoef); - copycolor(scp->val, sr.rcol); - cntord[sn].brt = bright(sr.rcol); + smultscolor(sr.rcol, sr.rcoef); + copyscolor(scp->val, sr.rcol); + cntord[sn].brt = pbright(sr.rcol); } /* sort contributions */ qsort(cntord, sn, sizeof(CNTPTR), cntcmp); @@ -486,12 +497,12 @@ direct( /* add direct component */ if (sn >= MINSHADCNT && (sn+nshadcheck>=ncnts ? cntord[sn].brt : cntord[sn].brt-cntord[sn+nshadcheck].brt) - < ourthresh*bright(r->rcol)) + < ourthresh*pbright(r->rcol)) break; scp = srccnt + cntord[sn].sndx; /* test for hit */ - rayorigin(&sr, SHADOW, r, NULL); - copycolor(sr.rcoef, scp->coef); + rayorigin(&sr, thrudir(r,scp->dir) ? TSHADOW : RSHADOW, r, NULL); + copyscolor(sr.rcoef, scp->coef); VCOPY(sr.rdir, scp->dir); sr.rsrc = scp->sno; /* keep statistics */ @@ -506,7 +517,7 @@ direct( /* add direct component */ raycont(&sr); if (trace != NULL) (*trace)(&sr); /* trace execution */ - if (bright(sr.rcol) <= FTINY) { + if (scolor_mean(sr.rcol) <= FTINY) { #if SHADCACHE if ((scp <= srccnt || scp[-1].sno != scp->sno) && (scp >= srccnt+ncnts-1 || @@ -516,8 +527,8 @@ direct( /* add direct component */ continue; /* missed! */ } rayparticipate(&sr); - multcolor(sr.rcol, sr.rcoef); - copycolor(scp->val, sr.rcol); + smultscolor(sr.rcol, sr.rcoef); + copyscolor(scp->val, sr.rcol); } else if (trace != NULL && (source[scp->sno].sflags & (SDISTANT|SVIRTUAL|SFOLLOW)) == (SDISTANT|SFOLLOW) && @@ -526,7 +537,7 @@ direct( /* add direct component */ /* skip call to rayparticipate() & scp->val update */ } /* add contribution if hit */ - addcolor(r->rcol, scp->val); + saddscolor(r->rcol, scp->val); nhits++; source[scp->sno].nhits++; } @@ -546,8 +557,8 @@ direct( /* add direct component */ prob = hwt * (double)source[scp->sno].nhits / (double)source[scp->sno].ntests; if (prob < 1.0) - scalecolor(scp->val, prob); - addcolor(r->rcol, scp->val); + scalescolor(scp->val, prob); + saddscolor(r->rcol, scp->val); } } @@ -592,13 +603,15 @@ srcscatter( /* compute source scattering into ray */ setcolor(cvext, re > 92. ? 0. : exp(-re), ge > 92. ? 0. : exp(-ge), be > 92. ? 0. : exp(-be)); - if (intens(cvext) <= FTINY) + if (intens(cvext) <= FTINY*FTINY) break; /* too far away */ sr.rorg[0] = r->rorg[0] + r->rdir[0]*t; sr.rorg[1] = r->rorg[1] + r->rdir[1]*t; sr.rorg[2] = r->rorg[2] + r->rdir[2]*t; if (!volumePhotonMapping) { + if (srcskip(r->slights[i], r)) + continue; initsrcindex(&si); /* sample ray to this source */ si.sn = r->slights[i]; nopart(&si, &sr); @@ -614,7 +627,7 @@ srcscatter( /* compute source scattering into ray */ sr.gecc = r->gecc; sr.slights = r->slights; rayvalue(&sr); /* eval. source ray */ - if (bright(sr.rcol) <= FTINY) { + if (pbright(sr.rcol) <= FTINY) { #if SHADCACHE srcblocker(&sr); /* add blocker to cache */ #endif @@ -629,7 +642,11 @@ srcscatter( /* compute source scattering into ray */ } /* other factors */ d *= si.dom * r->rot / (4.*PI*nsamps); - scalecolor(sr.rcol, d); +#ifdef SSKIPOPT + if (ssf_select != NULL && sskip_chk(ssf_select, sr.rsrc)) + d *= r->scorr; +#endif + scalescolor(sr.rcol, d); } else { /* PMAP: Add ambient inscattering from * volume photons; note we reverse the @@ -640,12 +657,12 @@ srcscatter( /* compute source scattering into ray */ sr.rdir [2] = -r -> rdir [2]; sr.gecc = r -> gecc; inscatterVolumePmap(&sr, sr.rcol); - scalecolor(sr.rcol, r -> rot / nsamps); + scalescolor(sr.rcol, r -> rot / nsamps); } - multcolor(sr.rcol, r->cext); - multcolor(sr.rcol, r->albedo); - multcolor(sr.rcol, cvext); - addcolor(r->rcol, sr.rcol); /* add it in */ + smultcolor(sr.rcol, r->cext); + smultcolor(sr.rcol, r->albedo); + smultcolor(sr.rcol, cvext); + saddscolor(r->rcol, sr.rcol); /* add it in */ } } samplendx = oldsampndx; @@ -746,11 +763,11 @@ m_light( /* ray hit a light source */ { /* check for over-counting */ if (badcomponent(m, r)) { - setcolor(r->rcoef, 0.0, 0.0, 0.0); + scolorblack(r->rcoef); return(1); } if (wrongsource(m, r)) { - setcolor(r->rcoef, 0.0, 0.0, 0.0); + scolorblack(r->rcoef); return(1); } /* check for passed illum */ @@ -762,7 +779,7 @@ m_light( /* ray hit a light source */ } /* check for invisibility */ if (srcignore(m, r)) { - setcolor(r->rcoef, 0.0, 0.0, 0.0); + scolorblack(r->rcoef); return(1); } /* otherwise treat as source */ @@ -777,10 +794,10 @@ m_light( /* ray hit a light source */ /* get distribution pattern */ raytexture(r, m->omod); /* get source color */ - setcolor(r->rcol, m->oargs.farg[0], + setscolor(r->rcol, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]); /* modify value */ - multcolor(r->rcol, r->pcol); + smultscolor(r->rcol, r->pcol); return(1); }