--- ray/src/util/glaresrc.c 1991/03/21 17:11:50 1.10 +++ ray/src/util/glaresrc.c 1991/04/22 08:20:58 1.14 @@ -72,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) @@ -80,19 +80,20 @@ 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; + 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); @@ -105,8 +106,8 @@ double br; } return; } - if (h >= hlim) { /* right region */ - d = (double)(-h+hlim)/sampdens; + if (h >= hl) { /* right region */ + d = (double)(-h+hl)/sampdens; if (d <= -1.0+FTINY) return; tanb = d/sqrt(1.0-d*d); @@ -121,7 +122,7 @@ double br; } /* 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 += d; @@ -141,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); @@ -276,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); } @@ -340,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