--- ray/src/rt/ambient.c 1995/10/24 13:33:23 2.33 +++ ray/src/rt/ambient.c 1995/11/21 14:28:22 2.35 @@ -60,7 +60,8 @@ static int nunflshed = 0; /* number of unflushed ambi #endif static COLOR avsum = BLKCOLOR; /* computed ambient value sum */ -static unsigned int nambvals = 0; /* number of computed ambient values */ +static unsigned int nambvals = 0; /* total number of indirect values */ +static unsigned int nambshare = 0; /* number of values from file */ static unsigned long ambclock = 0; /* ambient access clock */ static unsigned long lastsort = 0; /* time of last value sort */ static long sortintvl = SORT_INTVL; /* time until next sort */ @@ -69,9 +70,10 @@ static long sortintvl = SORT_INTVL; /* time until nex /* * Track access times unless we are sharing ambient values * through memory on a multiprocessor, when we want to avoid - * claiming our own memory (copy on write). + * claiming our own memory (copy on write). Go ahead anyway + * if more than two thirds of our values are unshared. */ -#define tracktime (shm_boundary == NULL || ambfp == NULL) +#define tracktime (shm_boundary == NULL || nambvals > 3*nambshare) #define AMBFLUSH (BUFSIZ/AMBVALSIZ) @@ -143,6 +145,7 @@ char *afile; avinsert(avstore(&amb)); /* align */ fseek(ambfp, -((ftell(ambfp)-headlen)%AMBVALSIZ), 1); + nambshare = nambvals; } else if ((ambfp = fopen(afile, "w+")) != NULL) initambfile(1); else { @@ -176,9 +179,10 @@ OBJECT obj; } -ambient(acol, r) /* compute ambient component for ray */ +ambient(acol, r, nrm) /* compute ambient component for ray */ COLOR acol; register RAY *r; +FVECT nrm; { static int rdepth = 0; /* ambient recursion */ double d; @@ -205,14 +209,14 @@ register RAY *r; sortambvals(0); /* get ambient value */ setcolor(acol, 0.0, 0.0, 0.0); - d = sumambient(acol, r, rdepth, + d = sumambient(acol, r, nrm, rdepth, &atrunk, thescene.cuorg, thescene.cusize); if (d > FTINY) { scalecolor(acol, 1.0/d); return; } rdepth++; /* need to cache new value */ - d = makeambient(acol, r, rdepth-1); + d = makeambient(acol, r, nrm, rdepth-1); rdepth--; if (d > FTINY) return; @@ -230,9 +234,10 @@ dumbamb: /* return global value */ double -sumambient(acol, r, al, at, c0, s) /* get interpolated ambient value */ +sumambient(acol, r, rn, al, at, c0, s) /* get interpolated ambient value */ COLOR acol; register RAY *r; +FVECT rn; int al; AMBTREE *at; FVECT c0; @@ -296,7 +301,7 @@ double s; else wt = 1.0 / wt; wsum += wt; - extambient(ct, av, r->rop, r->ron); + extambient(ct, av, r->rop, rn); scalecolor(ct, wt); addcolor(acol, ct); } @@ -315,16 +320,17 @@ double s; break; } if (j == 3) - wsum += sumambient(acol, r, al, at->kid+i, ck0, s); + wsum += sumambient(acol, r, rn, al, at->kid+i, ck0, s); } return(wsum); } double -makeambient(acol, r, al) /* make a new ambient value */ +makeambient(acol, r, rn, al) /* make a new ambient value */ COLOR acol; register RAY *r; +FVECT rn; int al; { AMBVAL amb; @@ -346,6 +352,8 @@ int al; VCOPY(amb.gdir, gd); /* insert into tree */ avsave(&amb); /* and save to file */ + if (rn != r->ron) + extambient(acol, &amb, r->rop, rn); /* texture */ return(amb.rad); }