--- ray/src/util/glaresrc.c 1991/03/20 12:18:14 1.7 +++ ray/src/util/glaresrc.c 1991/04/22 08:20:58 1.14 @@ -49,6 +49,11 @@ analyze() /* analyze our scene */ memerr("view span brightness buffer"); for (v = vsize; v >= -vsize; v--) { close_sources(v); +#ifndef DEBUG + if (verbose) + fprintf(stderr, "%s: analyzing... %3ld%%\r", + progname, 100L*(vsize-v)/(2*vsize)); +#endif getviewspan(v, spanbr); left = hsize + 1; for (h = -hsize; h <= hsize; h++) { @@ -67,7 +72,7 @@ analyze() /* analyze our scene */ addsrcspan(newspan(left,h,v,spanbr)); left = hsize + 1; } - addindirect(h, spanbr[h+hsize]); + addindirect(h, v, spanbr[h+hsize]); } } if (left < h) @@ -75,51 +80,52 @@ analyze() /* analyze our scene */ } free((char *)spanbr); close_allsrcs(); - absorb_specks(); } -addindirect(h, br) /* add brightness to indirect illuminances */ -int h; +addindirect(h, v, br) /* add brightness to indirect illuminances */ +int h, v; double br; { double tanb, d; + int hl; register int i; - if (h <= -hlim) { /* left region */ - d = (double)(h+hlim)/sampdens; - if (d <= -1.0+FTINY) + hl = hlim(v); + if (h <= -hl) { /* left region */ + d = (double)(-h-hl)/sampdens; + if (d >= 1.0-FTINY) return; tanb = d/sqrt(1.0-d*d); for (i = 0; i < nglardirs; i++) { d = indirect[i].lcos - tanb*indirect[i].lsin; if (d > 0.0) { indirect[i].sum += d * br; - indirect[i].n++; + indirect[i].n += d; } } return; } - if (h >= hlim) { /* right region */ - d = (double)(h-hlim)/sampdens; - if (d >= 1.0-FTINY) + if (h >= hl) { /* right region */ + d = (double)(-h+hl)/sampdens; + if (d <= -1.0+FTINY) return; tanb = d/sqrt(1.0-d*d); for (i = 0; i < nglardirs; i++) { d = indirect[i].rcos - tanb*indirect[i].rsin; if (d > 0.0) { indirect[i].sum += d * br; - indirect[i].n++; + indirect[i].n += d; } } return; } /* central region */ for (i = 0; i < nglardirs; i++) { - d = cos(h_theta(h) - indirect[i].theta); + d = cos(h_theta(h,v) - indirect[i].theta); if (d > 0.0) { indirect[i].sum += d * br; - indirect[i].n++; + indirect[i].n += d; } } } @@ -136,13 +142,14 @@ comp_thresh() /* compute glare threshold */ progname); brsum = 0.0; nsamps = 0; - for (v = vsize; v >= -vsize; v -= TSAMPSTEP) + for (v = vsize; v >= -vsize; v -= TSAMPSTEP) { for (h = -hsize; h <= hsize; h += TSAMPSTEP) { if ((br = getviewpix(h, v)) < 0.0) continue; brsum += br; nsamps++; } + } if (nsamps == 0) { fprintf(stderr, "%s: no viewable scene!\n", progname); exit(1); @@ -153,7 +160,9 @@ comp_thresh() /* compute glare threshold */ exit(1); } if (verbose) { +#ifdef DEBUG pict_stats(); +#endif fprintf(stderr, "%s: threshold set to %f cd/m2 from %d samples\n", progname, threshold, nsamps); @@ -269,37 +278,33 @@ close_allsrcs() /* done with everything */ donesource(sp) /* finished with this source */ register struct source *sp; { - FVECT dthis, dright; register struct srcspan *ss; int h, n; - double d; + double hsum, vsum, d; sp->dom = 0.0; - sp->dir[0] = sp->dir[1] = sp->dir[2] = 0.0; + hsum = vsum = 0.0; sp->brt = 0.0; n = 0; for (ss = sp->first; ss != NULL; ss = ss->next) { sp->brt += ss->brsum; n += ss->r - ss->l; - if (compdir(dright, ss->r, ss->v) < 0) - compdir(dright, ss->r-2, ss->v); - for (h = ss->r-1; h >= ss->l; h--) - if (compdir(dthis, h, ss->v) == 0) { - d = dist2(dthis, dright); - fvsum(sp->dir, sp->dir, dthis, d); - sp->dom += d; - VCOPY(dright, dthis); - } + for (h = ss->l; h < ss->r; h++) { + d = pixsize(h, ss->v); + hsum += d*h; + vsum += d*ss->v; + sp->dom += d; + } free((char *)ss); } sp->first = NULL; sp->brt /= (double)n; - normalize(sp->dir); + compdir(sp->dir, (int)(hsum/sp->dom), (int)(vsum/sp->dom)); sp->next = donelist; donelist = sp; if (verbose) fprintf(stderr, - "%s: found source at (%.3f,%.3f,%.3f), dw %.5f, br %.1f (%d samps)\n", + "%s: source at [%.3f,%.3f,%.3f], dw %.5f, br %.1f (%d samps)\n", progname, sp->dir[0], sp->dir[1], sp->dir[2], sp->dom, sp->brt, n); } @@ -333,10 +338,10 @@ absorb_specks() /* eliminate too-small sources */ fprintf(stderr, "%s: absorbing small sources...\n", progname); head.next = donelist; last = &head; - for (this = donelist; this != NULL; this = this->next) + for (this = head.next; this != NULL; this = this->next) if (TOOSMALL(this)) { last->next = this->next; - buddy = findbuddy(this, donelist); + buddy = findbuddy(this, head.next); if (buddy != NULL) mergesource(buddy, this); else @@ -352,15 +357,16 @@ absorb(s) /* absorb a source into indirect */ register struct source *s; { FVECT dir; - register int i, n; + double d; + register int i; for (i = 0; i < nglardirs; i++) { spinvector(dir, ourview.vdir, ourview.vup, indirect[i].theta); - n = DOT(dir,s->dir)*s->dom*(sampdens*sampdens) + 0.5; - if (n == 0) + d = DOT(dir,s->dir)*s->dom*(sampdens*sampdens); + if (d <= 0.0) continue; - indirect[i].sum += n * s->brt; - indirect[i].n += n; + indirect[i].sum += d * s->brt; + indirect[i].n += d; } for ( ; s->first != NULL; s->first = s->first->next) free((char *)s->first);