22 |
|
int siz |
23 |
|
) |
24 |
|
{ |
25 |
< |
if (siz == 0) { |
25 |
> |
if (siz <= 0) { |
26 |
|
if (distsiz > 0) |
27 |
|
free((void *)distarr); |
28 |
|
distarr = NULL; |
46 |
|
{ |
47 |
|
COLORV *colp; |
48 |
|
|
49 |
< |
if (rv == 0) |
49 |
> |
if (rv == 0) /* no result ready */ |
50 |
|
return(0); |
51 |
|
if (rv < 0) |
52 |
|
error(USER, "ray tracing process died"); |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
< |
static void |
130 |
> |
void |
131 |
|
flatdir( /* compute uniform hemispherical direction */ |
132 |
< |
register FVECT dv, |
132 |
> |
FVECT dv, |
133 |
|
double alt, |
134 |
|
double azi |
135 |
|
) |
184 |
|
return(my_default(ob, il, nm)); |
185 |
|
} |
186 |
|
/* set up sampling */ |
187 |
– |
if (il->sampdens <= 0) { |
188 |
– |
nalt = nazi = 1; /* diffuse assumption */ |
189 |
– |
} else { |
190 |
– |
n = PI * il->sampdens; |
191 |
– |
nalt = sqrt(n/PI) + .5; |
192 |
– |
nazi = PI*nalt + .5; |
193 |
– |
} |
187 |
|
if (il->sd != NULL) { |
188 |
|
if (!getBSDF_xfm(xfm, fa->norm, il->udir)) { |
189 |
|
objerror(ob, WARNING, "illegal up direction"); |
191 |
|
return(my_default(ob, il, nm)); |
192 |
|
} |
193 |
|
n = il->sd->ninc; |
194 |
< |
} else |
194 |
> |
} else { |
195 |
> |
if (il->sampdens <= 0) { |
196 |
> |
nalt = nazi = 1; /* diffuse assumption */ |
197 |
> |
} else { |
198 |
> |
n = PI * il->sampdens; |
199 |
> |
nalt = sqrt(n/PI) + .5; |
200 |
> |
nazi = PI*nalt + .5; |
201 |
> |
} |
202 |
|
n = nazi*nalt; |
203 |
+ |
} |
204 |
|
newdist(n); |
205 |
|
/* take first edge >= sqrt(area) */ |
206 |
|
for (j = fa->nv-1, i = 0; i < fa->nv; j = i++) { |
232 |
|
nmisses = 0; |
233 |
|
for (dim[1] = 0; dim[1] < n; dim[1]++) |
234 |
|
for (i = 0; i < il->nsamps; i++) { |
235 |
< |
/* random direction */ |
235 |
> |
/* randomize direction */ |
236 |
|
h = ilhash(dim, 2) + i; |
237 |
|
if (il->sd != NULL) { |
238 |
|
r_BSDF_incvec(dir, il->sd, dim[1], urand(h), xfm); |
246 |
|
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - |
247 |
|
dn[2]*fa->norm[j]; |
248 |
|
} |
249 |
< |
/* random location */ |
249 |
> |
/* randomize location */ |
250 |
|
do { |
251 |
|
multisamp(sp, 2, urand(h+4862+nmisses)); |
252 |
|
r1 = ur[0] + (ur[1]-ur[0]) * sp[0]; |
271 |
|
raysamp(dim[1], org, dir); |
272 |
|
} |
273 |
|
rayclean(); |
274 |
< |
if (il->sd != NULL) /* run distribution through BSDF */ |
274 |
> |
if (il->sd != NULL) { /* run distribution through BSDF */ |
275 |
> |
nalt = sqrt(il->sd->nout/PI) + .5; |
276 |
> |
nazi = PI*nalt + .5; |
277 |
|
redistribute(il->sd, nalt, nazi, u, v, fa->norm, xfm); |
278 |
+ |
} |
279 |
|
/* write out the face and its distribution */ |
280 |
|
if (average(il, distarr, n)) { |
281 |
|
if (il->sampdens > 0) |
378 |
|
/* get/check arguments */ |
379 |
|
co = getcone(ob, 0); |
380 |
|
/* set up sampling */ |
377 |
– |
if (il->sampdens <= 0) |
378 |
– |
nalt = nazi = 1; |
379 |
– |
else { |
380 |
– |
n = PI * il->sampdens; |
381 |
– |
nalt = sqrt(n/PI) + .5; |
382 |
– |
nazi = PI*nalt + .5; |
383 |
– |
} |
381 |
|
if (il->sd != NULL) { |
382 |
|
if (!getBSDF_xfm(xfm, co->ad, il->udir)) { |
383 |
|
objerror(ob, WARNING, "illegal up direction"); |
385 |
|
return(my_default(ob, il, nm)); |
386 |
|
} |
387 |
|
n = il->sd->ninc; |
388 |
< |
} else |
388 |
> |
} else { |
389 |
> |
if (il->sampdens <= 0) { |
390 |
> |
nalt = nazi = 1; /* diffuse assumption */ |
391 |
> |
} else { |
392 |
> |
n = PI * il->sampdens; |
393 |
> |
nalt = sqrt(n/PI) + .5; |
394 |
> |
nazi = PI*nalt + .5; |
395 |
> |
} |
396 |
|
n = nazi*nalt; |
397 |
+ |
} |
398 |
|
newdist(n); |
399 |
|
mkaxes(u, v, co->ad); |
400 |
|
dim[0] = random(); |
403 |
|
for (i = 0; i < il->nsamps; i++) { |
404 |
|
/* next sample point */ |
405 |
|
h = ilhash(dim,2) + i; |
406 |
< |
/* random direction */ |
406 |
> |
/* randomize direction */ |
407 |
|
if (il->sd != NULL) { |
408 |
|
r_BSDF_incvec(dir, il->sd, dim[1], urand(h), xfm); |
409 |
|
} else { |
413 |
|
r2 = (dim[1] - alti*nazi + sp[1] - .5)/nazi; |
414 |
|
flatdir(dn, r1, r2); |
415 |
|
for (j = 0; j < 3; j++) |
416 |
< |
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j]; |
416 |
> |
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j]; |
417 |
|
} |
418 |
< |
/* random location */ |
418 |
> |
/* randomize location */ |
419 |
|
multisamp(sp, 2, urand(h+8371)); |
420 |
|
r3 = sqrt(CO_R0(co)*CO_R0(co) + |
421 |
|
sp[0]*(CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co))); |
433 |
|
raysamp(dim[1], org, dir); |
434 |
|
} |
435 |
|
rayclean(); |
436 |
< |
if (il->sd != NULL) /* run distribution through BSDF */ |
436 |
> |
if (il->sd != NULL) { /* run distribution through BSDF */ |
437 |
> |
nalt = sqrt(il->sd->nout/PI) + .5; |
438 |
> |
nazi = PI*nalt + .5; |
439 |
|
redistribute(il->sd, nalt, nazi, u, v, co->ad, xfm); |
440 |
+ |
} |
441 |
|
/* write out the ring and its distribution */ |
442 |
|
if (average(il, distarr, n)) { |
443 |
|
if (il->sampdens > 0) |