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); |
281 |
|
FVECT dthis, dright; |
282 |
|
register struct srcspan *ss; |
283 |
|
int h, n; |
284 |
< |
double d; |
284 |
> |
double hsum, vsum, d; |
285 |
|
|
286 |
|
sp->dom = 0.0; |
287 |
< |
sp->dir[0] = sp->dir[1] = sp->dir[2] = 0.0; |
287 |
> |
hsum = vsum = 0.0; |
288 |
|
sp->brt = 0.0; |
289 |
|
n = 0; |
290 |
|
for (ss = sp->first; ss != NULL; ss = ss->next) { |
291 |
|
sp->brt += ss->brsum; |
292 |
|
n += ss->r - ss->l; |
293 |
< |
if (compdir(dright, ss->r, ss->v) < 0) |
294 |
< |
compdir(dright, ss->r-2, ss->v); |
295 |
< |
for (h = ss->r-1; h >= ss->l; h--) |
296 |
< |
if (compdir(dthis, h, ss->v) == 0) { |
297 |
< |
d = dist2(dthis, dright); |
298 |
< |
fvsum(sp->dir, sp->dir, dthis, d); |
297 |
< |
sp->dom += d; |
298 |
< |
VCOPY(dright, dthis); |
299 |
< |
} |
293 |
> |
for (h = ss->r-1; h >= ss->l; h--) { |
294 |
> |
d = pixsize(h, ss->v); |
295 |
> |
hsum += d*h; |
296 |
> |
vsum += d*ss->v; |
297 |
> |
sp->dom += d; |
298 |
> |
} |
299 |
|
free((char *)ss); |
300 |
|
} |
301 |
|
sp->first = NULL; |
302 |
|
sp->brt /= (double)n; |
303 |
< |
normalize(sp->dir); |
303 |
> |
compdir(sp->dir, (int)(hsum/sp->dom), (int)(vsum/sp->dom)); |
304 |
|
sp->next = donelist; |
305 |
|
donelist = sp; |
306 |
|
if (verbose) |
307 |
|
fprintf(stderr, |
308 |
< |
"%s: found source at (%.3f,%.3f,%.3f), dw %.5f, br %.1f (%d samps)\n", |
308 |
> |
"%s: source at [%.3f,%.3f,%.3f], dw %.5f, br %.1f (%d samps)\n", |
309 |
|
progname, sp->dir[0], sp->dir[1], sp->dir[2], |
310 |
|
sp->dom, sp->brt, n); |
311 |
|
} |
339 |
|
fprintf(stderr, "%s: absorbing small sources...\n", progname); |
340 |
|
head.next = donelist; |
341 |
|
last = &head; |
342 |
< |
for (this = donelist; this != NULL; this = this->next) |
342 |
> |
for (this = head.next; this != NULL; this = this->next) |
343 |
|
if (TOOSMALL(this)) { |
344 |
|
last->next = this->next; |
345 |
< |
buddy = findbuddy(this, donelist); |
345 |
> |
buddy = findbuddy(this, head.next); |
346 |
|
if (buddy != NULL) |
347 |
|
mergesource(buddy, this); |
348 |
|
else |
358 |
|
register struct source *s; |
359 |
|
{ |
360 |
|
FVECT dir; |
361 |
< |
register int i, n; |
361 |
> |
double d; |
362 |
> |
register int i; |
363 |
|
|
364 |
|
for (i = 0; i < nglardirs; i++) { |
365 |
|
spinvector(dir, ourview.vdir, ourview.vup, indirect[i].theta); |
366 |
< |
n = DOT(dir,s->dir)*s->dom*(sampdens*sampdens) + 0.5; |
367 |
< |
if (n == 0) |
366 |
> |
d = DOT(dir,s->dir)*s->dom*(sampdens*sampdens); |
367 |
> |
if (d <= 0.0) |
368 |
|
continue; |
369 |
< |
indirect[i].sum += n * s->brt; |
370 |
< |
indirect[i].n += n; |
369 |
> |
indirect[i].sum += d * s->brt; |
370 |
> |
indirect[i].n += d; |
371 |
|
} |
372 |
|
for ( ; s->first != NULL; s->first = s->first->next) |
373 |
|
free((char *)s->first); |