72 |
|
addsrcspan(newspan(left,h,v,spanbr)); |
73 |
|
left = hsize + 1; |
74 |
|
} |
75 |
< |
addindirect(h, spanbr[h+hsize]); |
75 |
> |
addindirect(h, v, spanbr[h+hsize]); |
76 |
|
} |
77 |
|
} |
78 |
|
if (left < h) |
80 |
|
} |
81 |
|
free((char *)spanbr); |
82 |
|
close_allsrcs(); |
83 |
– |
absorb_specks(); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
< |
addindirect(h, br) /* add brightness to indirect illuminances */ |
87 |
< |
int h; |
86 |
> |
addindirect(h, v, br) /* add brightness to indirect illuminances */ |
87 |
> |
int h, v; |
88 |
|
double br; |
89 |
|
{ |
90 |
|
double tanb, d; |
91 |
+ |
int hl; |
92 |
|
register int i; |
93 |
|
|
94 |
< |
if (h <= -hlim) { /* left region */ |
95 |
< |
d = (double)(h+hlim)/sampdens; |
96 |
< |
if (d <= -1.0+FTINY) |
94 |
> |
hl = hlim(v); |
95 |
> |
if (h <= -hl) { /* left region */ |
96 |
> |
d = (double)(-h-hl)/sampdens; |
97 |
> |
if (d >= 1.0-FTINY) |
98 |
|
return; |
99 |
|
tanb = d/sqrt(1.0-d*d); |
100 |
|
for (i = 0; i < nglardirs; i++) { |
101 |
|
d = indirect[i].lcos - tanb*indirect[i].lsin; |
102 |
|
if (d > 0.0) { |
103 |
|
indirect[i].sum += d * br; |
104 |
< |
indirect[i].n++; |
104 |
> |
indirect[i].n += d; |
105 |
|
} |
106 |
|
} |
107 |
|
return; |
108 |
|
} |
109 |
< |
if (h >= hlim) { /* right region */ |
110 |
< |
d = (double)(h-hlim)/sampdens; |
111 |
< |
if (d >= 1.0-FTINY) |
109 |
> |
if (h >= hl) { /* right region */ |
110 |
> |
d = (double)(-h+hl)/sampdens; |
111 |
> |
if (d <= -1.0+FTINY) |
112 |
|
return; |
113 |
|
tanb = d/sqrt(1.0-d*d); |
114 |
|
for (i = 0; i < nglardirs; i++) { |
115 |
|
d = indirect[i].rcos - tanb*indirect[i].rsin; |
116 |
|
if (d > 0.0) { |
117 |
|
indirect[i].sum += d * br; |
118 |
< |
indirect[i].n++; |
118 |
> |
indirect[i].n += d; |
119 |
|
} |
120 |
|
} |
121 |
|
return; |
122 |
|
} |
123 |
|
/* central region */ |
124 |
|
for (i = 0; i < nglardirs; i++) { |
125 |
< |
d = cos(h_theta(h) - indirect[i].theta); |
125 |
> |
d = cos(h_theta(h,v) - indirect[i].theta); |
126 |
|
if (d > 0.0) { |
127 |
|
indirect[i].sum += d * br; |
128 |
< |
indirect[i].n++; |
128 |
> |
indirect[i].n += d; |
129 |
|
} |
130 |
|
} |
131 |
|
} |
142 |
|
progname); |
143 |
|
brsum = 0.0; |
144 |
|
nsamps = 0; |
145 |
< |
for (v = vsize; v >= -vsize; v -= TSAMPSTEP) |
145 |
> |
for (v = vsize; v >= -vsize; v -= TSAMPSTEP) { |
146 |
|
for (h = -hsize; h <= hsize; h += TSAMPSTEP) { |
147 |
|
if ((br = getviewpix(h, v)) < 0.0) |
148 |
|
continue; |
149 |
|
brsum += br; |
150 |
|
nsamps++; |
151 |
|
} |
152 |
+ |
} |
153 |
|
if (nsamps == 0) { |
154 |
|
fprintf(stderr, "%s: no viewable scene!\n", progname); |
155 |
|
exit(1); |
278 |
|
donesource(sp) /* finished with this source */ |
279 |
|
register struct source *sp; |
280 |
|
{ |
279 |
– |
FVECT dthis, dright; |
281 |
|
register struct srcspan *ss; |
282 |
|
int h, n; |
283 |
< |
double d; |
283 |
> |
double hsum, vsum, d; |
284 |
|
|
285 |
|
sp->dom = 0.0; |
286 |
< |
sp->dir[0] = sp->dir[1] = sp->dir[2] = 0.0; |
286 |
> |
hsum = vsum = 0.0; |
287 |
|
sp->brt = 0.0; |
288 |
|
n = 0; |
289 |
|
for (ss = sp->first; ss != NULL; ss = ss->next) { |
290 |
|
sp->brt += ss->brsum; |
291 |
|
n += ss->r - ss->l; |
292 |
< |
if (compdir(dright, ss->r, ss->v) < 0) |
293 |
< |
compdir(dright, ss->r-2, ss->v); |
294 |
< |
for (h = ss->r-1; h >= ss->l; h--) |
295 |
< |
if (compdir(dthis, h, ss->v) == 0) { |
296 |
< |
d = dist2(dthis, dright); |
297 |
< |
fvsum(sp->dir, sp->dir, dthis, d); |
297 |
< |
sp->dom += d; |
298 |
< |
VCOPY(dright, dthis); |
299 |
< |
} |
292 |
> |
for (h = ss->l; h < ss->r; h++) { |
293 |
> |
d = pixsize(h, ss->v); |
294 |
> |
hsum += d*h; |
295 |
> |
vsum += d*ss->v; |
296 |
> |
sp->dom += d; |
297 |
> |
} |
298 |
|
free((char *)ss); |
299 |
|
} |
300 |
|
sp->first = NULL; |
301 |
|
sp->brt /= (double)n; |
302 |
< |
normalize(sp->dir); |
302 |
> |
compdir(sp->dir, (int)(hsum/sp->dom), (int)(vsum/sp->dom)); |
303 |
|
sp->next = donelist; |
304 |
|
donelist = sp; |
305 |
|
if (verbose) |
306 |
|
fprintf(stderr, |
307 |
< |
"%s: found source at (%.3f,%.3f,%.3f), dw %.5f, br %.1f (%d samps)\n", |
307 |
> |
"%s: source at [%.3f,%.3f,%.3f], dw %.5f, br %.1f (%d samps)\n", |
308 |
|
progname, sp->dir[0], sp->dir[1], sp->dir[2], |
309 |
|
sp->dom, sp->brt, n); |
310 |
|
} |
338 |
|
fprintf(stderr, "%s: absorbing small sources...\n", progname); |
339 |
|
head.next = donelist; |
340 |
|
last = &head; |
341 |
< |
for (this = donelist; this != NULL; this = this->next) |
341 |
> |
for (this = head.next; this != NULL; this = this->next) |
342 |
|
if (TOOSMALL(this)) { |
343 |
|
last->next = this->next; |
344 |
< |
buddy = findbuddy(this, donelist); |
344 |
> |
buddy = findbuddy(this, head.next); |
345 |
|
if (buddy != NULL) |
346 |
|
mergesource(buddy, this); |
347 |
|
else |
357 |
|
register struct source *s; |
358 |
|
{ |
359 |
|
FVECT dir; |
360 |
< |
register int i, n; |
360 |
> |
double d; |
361 |
> |
register int i; |
362 |
|
|
363 |
|
for (i = 0; i < nglardirs; i++) { |
364 |
|
spinvector(dir, ourview.vdir, ourview.vup, indirect[i].theta); |
365 |
< |
n = DOT(dir,s->dir)*s->dom*(sampdens*sampdens) + 0.5; |
366 |
< |
if (n == 0) |
365 |
> |
d = DOT(dir,s->dir)*s->dom*(sampdens*sampdens); |
366 |
> |
if (d <= 0.0) |
367 |
|
continue; |
368 |
< |
indirect[i].sum += n * s->brt; |
369 |
< |
indirect[i].n += n; |
368 |
> |
indirect[i].sum += d * s->brt; |
369 |
> |
indirect[i].n += d; |
370 |
|
} |
371 |
|
for ( ; s->first != NULL; s->first = s->first->next) |
372 |
|
free((char *)s->first); |