--- ray/src/rt/ambient.c 1995/11/06 12:03:13 2.34 +++ ray/src/rt/ambient.c 1996/02/14 15:43:22 2.36 @@ -21,9 +21,6 @@ static char SCCSid[] = "$SunId$ LBL"; #ifndef OCTSCALE #define OCTSCALE 1.0 /* ceil((valid rad.)/(cube size)) */ #endif -#ifndef AMBVWT -#define AMBVWT 250 /* relative ambient value weight (# calcs) */ -#endif typedef struct ambtree { AMBVAL *alist; /* ambient value list */ @@ -60,7 +57,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 +67,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 +142,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 { @@ -219,14 +219,12 @@ FVECT nrm; return; dumbamb: /* return global value */ copycolor(acol, ambval); -#if AMBVWT - if (nambvals == 0) + if (ambvwt <= 0 | nambvals == 0) return; - scalecolor(acol, (double)AMBVWT); + scalecolor(acol, (double)ambvwt); addcolor(acol, avsum); /* average in computations */ - d = 1.0/(AMBVWT+nambvals); + d = 1.0/(ambvwt+nambvals); scalecolor(acol, d); -#endif }