11 |
|
#include "face.h" |
12 |
|
#include "cone.h" |
13 |
|
#include "source.h" |
14 |
+ |
#include "paths.h" |
15 |
|
|
16 |
|
#ifndef NBSDFSAMPS |
17 |
< |
#define NBSDFSAMPS 32 /* BSDF resampling count */ |
17 |
> |
#define NBSDFSAMPS 256 /* BSDF resampling count */ |
18 |
|
#endif |
19 |
|
|
20 |
|
COLORV * distarr = NULL; /* distribution array */ |
29 |
|
{ |
30 |
|
if (siz <= 0) { |
31 |
|
if (distsiz > 0) |
32 |
< |
free((void *)distarr); |
32 |
> |
free(distarr); |
33 |
|
distarr = NULL; |
34 |
|
distsiz = 0; |
35 |
|
return; |
36 |
|
} |
37 |
|
if (distsiz < siz) { |
38 |
|
if (distsiz > 0) |
39 |
< |
free((void *)distarr); |
39 |
> |
free(distarr); |
40 |
|
distarr = (COLORV *)malloc(sizeof(COLOR)*siz); |
41 |
|
if (distarr == NULL) |
42 |
|
error(SYSTEM, "out of memory in newdist"); |
62 |
|
{ |
63 |
|
if (direct_discount == NULL) |
64 |
|
return; |
65 |
< |
free((void *)direct_discount); |
65 |
> |
free(direct_discount); |
66 |
|
direct_discount = NULL; |
67 |
|
} |
68 |
|
|
108 |
|
VCOPY(myRay.rorg, org); |
109 |
|
VCOPY(myRay.rdir, dir); |
110 |
|
myRay.rmax = .0; |
111 |
< |
rayorigin(&myRay, PRIMARY, NULL, NULL); |
111 |
> |
rayorigin(&myRay, PRIMARY|SPECULAR, NULL, NULL); |
112 |
|
myRay.rno = ndx; |
113 |
|
/* queue ray, check result */ |
114 |
|
process_ray(&myRay, ray_pqueue(&myRay)); |
123 |
|
MAT4 ixfm |
124 |
|
) |
125 |
|
{ |
126 |
< |
int nalt, nazi; |
126 |
> |
int nalt=1, nazi=1; |
127 |
|
SRCINDEX si; |
128 |
|
RAY sr; |
129 |
|
FVECT v; |
130 |
|
double d; |
131 |
|
int i, j; |
132 |
|
/* get sampling density */ |
133 |
< |
if (il->sampdens <= 0) { |
133 |
< |
nalt = nazi = 1; |
134 |
< |
} else { |
133 |
> |
if (il->sd == NULL && il->sampdens > 0) { |
134 |
|
i = PI * il->sampdens; |
135 |
|
nalt = sqrt(i/PI) + .5; |
136 |
|
nazi = PI*nalt + .5; |
154 |
|
d = -1.0001*il->thick - 5.*FTINY; |
155 |
|
else |
156 |
|
d = 5.*FTINY; |
157 |
< |
for (i = 3; i--; ) |
159 |
< |
sr.rorg[i] += d*nrm[i]; |
157 |
> |
VSUM(sr.rorg, sr.rorg, nrm, d); |
158 |
|
samplendx++; /* increment sample counter */ |
159 |
|
if (!srcray(&sr, NULL, &si)) |
160 |
|
break; /* end of sources */ |
246 |
|
dv[2] = sqrt(1. - alt); |
247 |
|
} |
248 |
|
|
249 |
+ |
|
250 |
|
int |
251 |
|
flatindex( /* compute index for hemispherical direction */ |
252 |
|
FVECT dv, |
268 |
|
|
269 |
|
|
270 |
|
int |
271 |
+ |
printgeom( /* print out detailed geometry for BSDF */ |
272 |
+ |
struct BSDF_data *sd, |
273 |
+ |
char *xfrot, |
274 |
+ |
FVECT ctr, |
275 |
+ |
double s1, |
276 |
+ |
double s2 |
277 |
+ |
) |
278 |
+ |
{ |
279 |
+ |
static char mgftemp[] = TEMPLATE; |
280 |
+ |
char cmdbuf[64]; |
281 |
+ |
FILE *fp; |
282 |
+ |
double sca; |
283 |
+ |
|
284 |
+ |
if (sd == NULL || sd->mgf == NULL) |
285 |
+ |
return(0); |
286 |
+ |
if (sd->dim[0] <= FTINY || sd->dim[1] <= FTINY) |
287 |
+ |
return(0); |
288 |
+ |
if ((s1 > s2) ^ (sd->dim[0] > sd->dim[1])) { |
289 |
+ |
sca = s1; s1 = s2; s2 = sca; |
290 |
+ |
} |
291 |
+ |
s1 /= sd->dim[0]; |
292 |
+ |
s2 /= sd->dim[1]; |
293 |
+ |
sca = s1 > s2 ? s1 : s2; |
294 |
+ |
strcpy(mgftemp, TEMPLATE); |
295 |
+ |
if ((fp = fopen(mktemp(mgftemp), "w")) == NULL) |
296 |
+ |
error(SYSTEM, "cannot create temporary file for MGF"); |
297 |
+ |
/* prepend our transform */ |
298 |
+ |
fprintf(fp, "xf%s -s %.5f -t %.5g %.5g %.5g\n", |
299 |
+ |
xfrot, sca, ctr[0], ctr[1], ctr[2]); |
300 |
+ |
/* output given MGF description */ |
301 |
+ |
fputs(sd->mgf, fp); |
302 |
+ |
fputs("\nxf\n", fp); |
303 |
+ |
if (fclose(fp) == EOF) |
304 |
+ |
error(SYSTEM, "error writing MGF temporary file"); |
305 |
+ |
/* execute mgf2rad to convert MGF */ |
306 |
+ |
strcpy(cmdbuf, "mgf2rad "); |
307 |
+ |
strcpy(cmdbuf+8, mgftemp); |
308 |
+ |
fflush(stdout); |
309 |
+ |
system(cmdbuf); |
310 |
+ |
unlink(mgftemp); /* clean up */ |
311 |
+ |
return(1); |
312 |
+ |
} |
313 |
+ |
|
314 |
+ |
|
315 |
+ |
int |
316 |
|
my_default( /* default illum action */ |
317 |
|
OBJREC *ob, |
318 |
|
struct illum_args *il, |
342 |
|
FVECT u, v; |
343 |
|
double ur[2], vr[2]; |
344 |
|
MAT4 xfm; |
345 |
+ |
char xfrot[64]; |
346 |
|
int nallow; |
347 |
|
FACE *fa; |
348 |
|
int i, j; |
354 |
|
} |
355 |
|
/* set up sampling */ |
356 |
|
if (il->sd != NULL) { |
357 |
< |
if (!getBSDF_xfm(xfm, fa->norm, il->udir)) { |
357 |
> |
if (!getBSDF_xfm(xfm, fa->norm, il->udir, xfrot)) { |
358 |
|
objerror(ob, WARNING, "illegal up direction"); |
359 |
|
freeface(ob); |
360 |
|
return(my_default(ob, il, nm)); |
396 |
|
if (r2 < vr[0]) vr[0] = r2; |
397 |
|
if (r2 > vr[1]) vr[1] = r2; |
398 |
|
} |
399 |
+ |
/* output detailed geometry? */ |
400 |
+ |
if (!(il->flags & IL_LIGHT) && il->sd != NULL && il->sd->mgf != NULL && |
401 |
+ |
il->thick <= FTINY) { |
402 |
+ |
for (j = 3; j--; ) |
403 |
+ |
org[j] = .5*(ur[0]+ur[1])*u[j] + |
404 |
+ |
.5*(vr[0]+vr[1])*v[j] + |
405 |
+ |
fa->offset*fa->norm[j]; |
406 |
+ |
printgeom(il->sd, xfrot, org, ur[1]-ur[0], vr[1]-vr[0]); |
407 |
+ |
} |
408 |
|
dim[0] = random(); |
409 |
|
/* sample polygon */ |
410 |
|
nallow = 5*n*il->nsamps; |
449 |
|
raysamp(dim[1], org, dir); |
450 |
|
} |
451 |
|
/* add in direct component? */ |
452 |
< |
if (!directvis && (il->flags & IL_LIGHT || il->sd != NULL)) { |
452 |
> |
if (il->flags & IL_LIGHT || il->sd != NULL) { |
453 |
|
MAT4 ixfm; |
454 |
|
if (il->sd == NULL) { |
455 |
|
for (i = 3; i--; ) { |
603 |
|
co = getcone(ob, 0); |
604 |
|
/* set up sampling */ |
605 |
|
if (il->sd != NULL) { |
606 |
< |
if (!getBSDF_xfm(xfm, co->ad, il->udir)) { |
606 |
> |
if (!getBSDF_xfm(xfm, co->ad, il->udir, NULL)) { |
607 |
|
objerror(ob, WARNING, "illegal up direction"); |
608 |
|
freecone(ob); |
609 |
|
return(my_default(ob, il, nm)); |
657 |
|
raysamp(dim[1], org, dir); |
658 |
|
} |
659 |
|
/* add in direct component? */ |
660 |
< |
if (!directvis && (il->flags & IL_LIGHT || il->sd != NULL)) { |
660 |
> |
if (il->flags & IL_LIGHT || il->sd != NULL) { |
661 |
|
MAT4 ixfm; |
662 |
|
if (il->sd == NULL) { |
663 |
|
for (i = 3; i--; ) { |
779 |
|
cp = &direct_discount[3*i]; |
780 |
|
copycolor(cdir, cp); |
781 |
|
scalecolor(cdir, -wt); |
782 |
< |
direct_out = flatindex(dv, nalt, nazi); |
782 |
> |
if (b->nout != b->ninc) |
783 |
> |
direct_out = flatindex(dv, nalt, nazi); |
784 |
> |
else |
785 |
> |
direct_out = i; /* assumes dist. mirroring */ |
786 |
|
} |
787 |
|
for (k = nalt; k--; ) /* loop over distribution */ |
788 |
|
for (j = nazi; j--; ) { |
801 |
|
} |
802 |
|
wt = BSDF_value(b, i, o) * (1./NBSDFSAMPS); |
803 |
|
copycolor(col, cinc); |
804 |
< |
o = k*nazi + j; |
804 |
> |
if (b->nout != b->ninc) |
805 |
> |
o = k*nazi + j; |
806 |
|
if (o == direct_out) |
807 |
|
addcolor(col, cdir); /* minus direct */ |
808 |
|
scalecolor(col, wt); |
809 |
< |
cp = &distarr[3*o]; |
809 |
> |
cp = &distarr[3*(k*nazi + j)]; |
810 |
|
addcolor(cp, col); /* sum into distribution */ |
811 |
|
} |
812 |
|
} |