--- ray/src/rt/ambient.c 2014/06/19 16:26:55 2.91 +++ ray/src/rt/ambient.c 2015/02/24 19:39:26 2.94 @@ -1,6 +1,4 @@ -#ifndef lint -static const char RCSid[] = "$Id: ambient.c,v 2.91 2014/06/19 16:26:55 greg Exp $"; -#endif +static const char RCSid[] = "$Id: ambient.c,v 2.94 2015/02/24 19:39:26 greg Exp $"; /* * ambient.c - routines dealing with ambient (inter-reflected) component. * @@ -17,6 +15,7 @@ static const char RCSid[] = "$Id: ambient.c,v 2.91 201 #include "resolu.h" #include "ambient.h" #include "random.h" +#include "pmapamb.h" #ifndef OCTSCALE #define OCTSCALE 1.0 /* ceil((valid rad.)/(cube size)) */ @@ -271,7 +270,7 @@ static int plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, static double sumambient(COLOR acol, RAY *r, FVECT rn, int al, AMBTREE *at, FVECT c0, double s); static int makeambient(COLOR acol, RAY *r, FVECT rn, int al); -static void extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv, +static int extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv, FVECT uvw[3]); void @@ -282,10 +281,22 @@ multambient( /* compute ambient component & multiply ) { static int rdepth = 0; /* ambient recursion */ - COLOR acol; + COLOR acol, caustic; int ok; double d, l; + /* PMAP: Factor in ambient from photon map, if enabled and ray is + * ambient. Return as all ambient components accounted for, else + * continue. */ + if (ambPmap(aval, r, rdepth)) + return; + + /* PMAP: Factor in specular-diffuse ambient (caustics) from photon + * map, if enabled and ray is primary, else caustic is zero. Continue + * with RADIANCE ambient calculation */ + copycolor(caustic, aval); + ambPmapCaustic(caustic, r, rdepth); + if (ambdiv <= 0) /* no ambient calculation */ goto dumbamb; /* check number of bounces */ @@ -305,6 +316,9 @@ multambient( /* compute ambient component & multiply if (!ok) goto dumbamb; copycolor(aval, acol); + + /* PMAP: add in caustic */ + addcolor(aval, caustic); return; } @@ -314,25 +328,39 @@ multambient( /* compute ambient component & multiply setcolor(acol, 0.0, 0.0, 0.0); d = sumambient(acol, r, nrm, rdepth, &atrunk, thescene.cuorg, thescene.cusize); + if (d > FTINY) { d = 1.0/d; scalecolor(acol, d); multcolor(aval, acol); + + /* PMAP: add in caustic */ + addcolor(aval, caustic); return; } + rdepth++; /* need to cache new value */ ok = makeambient(acol, r, nrm, rdepth-1); rdepth--; + if (ok) { multcolor(aval, acol); /* computed new value */ + + /* PMAP: add in caustic */ + addcolor(aval, caustic); return; } + dumbamb: /* return global value */ if ((ambvwt <= 0) | (navsum == 0)) { multcolor(aval, ambval); + + /* PMAP: add in caustic */ + addcolor(aval, caustic); return; } - l = bright(ambval); /* average in computations */ + + l = bright(ambval); /* average in computations */ if (l > FTINY) { d = (log(l)*(double)ambvwt + avsum) / (double)(ambvwt + navsum); @@ -486,7 +514,8 @@ sumambient( /* get interpolated ambient value */ /* * Extrapolate value and compute final weight (hat function) */ - extambient(ct, av, r->rop, rn, uvw); + if (!extambient(ct, av, r->rop, rn, uvw)) + continue; d = tfunc(maxangle, sqrt(delta_r2), 0.0) * tfunc(ambacc, sqrt(delta_t2), 0.0); scalecolor(ct, d); @@ -537,7 +566,7 @@ makeambient( /* make a new ambient value for storage } -static void +static int extambient( /* extrapolate value at pv, nv */ COLOR cr, AMBVAL *ap, @@ -546,6 +575,7 @@ extambient( /* extrapolate value at pv, nv */ FVECT uvw[3] ) { + const double min_d = 0.05; static FVECT my_uvw[3]; FVECT v1; int i; @@ -565,12 +595,11 @@ extambient( /* extrapolate value at pv, nv */ for (i = 3; i--; ) d += v1[i] * (ap->gdir[0]*uvw[0][i] + ap->gdir[1]*uvw[1][i]); - if (d <= 0.0) { - setcolor(cr, 0.0, 0.0, 0.0); - return; - } + if (d < min_d) /* should not use if we can avoid it */ + d = min_d; copycolor(cr, ap->val); scalecolor(cr, d); + return(d > min_d); } @@ -633,9 +662,20 @@ multambient( /* compute ambient component & multiply ) { static int rdepth = 0; /* ambient recursion */ - COLOR acol; + COLOR acol, caustic; double d, l; + /* PMAP: Factor in ambient from global photon map (if enabled) and return + * as all ambient components accounted for */ + if (ambGlobalPmap(aval, r, rdepth)) + return; + + /* PMAP: Otherwise factor in ambient from caustic photon map + * (ambCausticPmap() returns zero if caustic photons disabled) and + * continue with RADIANCE ambient calculation */ + copycolor(caustic, aval); + ambCausticPmap(caustic, r, rdepth); + if (ambdiv <= 0) /* no ambient calculation */ goto dumbamb; /* check number of bounces */ @@ -653,7 +693,10 @@ multambient( /* compute ambient component & multiply rdepth--; if (d <= FTINY) goto dumbamb; - copycolor(aval, acol); + copycolor(aval, acol); + + /* PMAP: add in caustic */ + addcolor(aval, caustic); return; } @@ -663,24 +706,38 @@ multambient( /* compute ambient component & multiply setcolor(acol, 0.0, 0.0, 0.0); d = sumambient(acol, r, nrm, rdepth, &atrunk, thescene.cuorg, thescene.cusize); + if (d > FTINY) { d = 1.0/d; scalecolor(acol, d); multcolor(aval, acol); + + /* PMAP: add in caustic */ + addcolor(aval, caustic); return; } + rdepth++; /* need to cache new value */ d = makeambient(acol, r, nrm, rdepth-1); rdepth--; + if (d > FTINY) { multcolor(aval, acol); /* got new value */ + + /* PMAP: add in caustic */ + addcolor(aval, caustic); return; } + dumbamb: /* return global value */ if ((ambvwt <= 0) | (navsum == 0)) { multcolor(aval, ambval); + + /* PMAP: add in caustic */ + addcolor(aval, caustic); return; } + l = bright(ambval); /* average in computations */ if (l > FTINY) { d = (log(l)*(double)ambvwt + avsum) /