| 11 |
|
#include "face.h" |
| 12 |
|
#include "cone.h" |
| 13 |
|
#include "source.h" |
| 14 |
+ |
#include "paths.h" |
| 15 |
|
|
| 16 |
|
#ifndef NBSDFSAMPS |
| 17 |
|
#define NBSDFSAMPS 256 /* BSDF resampling count */ |
| 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)); |
| 249 |
|
dv[2] = sqrt(1. - alt); |
| 250 |
|
} |
| 251 |
|
|
| 252 |
+ |
|
| 253 |
|
int |
| 254 |
|
flatindex( /* compute index for hemispherical direction */ |
| 255 |
|
FVECT dv, |
| 271 |
|
|
| 272 |
|
|
| 273 |
|
int |
| 274 |
+ |
printgeom( /* print out detailed geometry for BSDF */ |
| 275 |
+ |
struct BSDF_data *sd, |
| 276 |
+ |
char *xfrot, |
| 277 |
+ |
FVECT ctr, |
| 278 |
+ |
double s1, |
| 279 |
+ |
double s2 |
| 280 |
+ |
) |
| 281 |
+ |
{ |
| 282 |
+ |
static char mgftemp[] = TEMPLATE; |
| 283 |
+ |
char cmdbuf[64]; |
| 284 |
+ |
FILE *fp; |
| 285 |
+ |
double sca; |
| 286 |
+ |
|
| 287 |
+ |
if (sd == NULL || sd->mgf == NULL) |
| 288 |
+ |
return(0); |
| 289 |
+ |
if (sd->dim[0] <= FTINY || sd->dim[1] <= FTINY) |
| 290 |
+ |
return(0); |
| 291 |
+ |
if ((s1 > s2) ^ (sd->dim[0] > sd->dim[1])) { |
| 292 |
+ |
sca = s1; s1 = s2; s2 = sca; |
| 293 |
+ |
} |
| 294 |
+ |
s1 /= sd->dim[0]; |
| 295 |
+ |
s2 /= sd->dim[1]; |
| 296 |
+ |
sca = s1 > s2 ? s1 : s2; |
| 297 |
+ |
strcpy(mgftemp, TEMPLATE); |
| 298 |
+ |
if ((fp = fopen(mktemp(mgftemp), "w")) == NULL) |
| 299 |
+ |
error(SYSTEM, "cannot create temporary file for MGF"); |
| 300 |
+ |
/* prepend our transform */ |
| 301 |
+ |
fprintf(fp, "xf%s -s %.5f -t %.5g %.5g %.5g\n", |
| 302 |
+ |
xfrot, sca, ctr[0], ctr[1], ctr[2]); |
| 303 |
+ |
/* output given MGF description */ |
| 304 |
+ |
fputs(sd->mgf, fp); |
| 305 |
+ |
fputs("\nxf\n", fp); |
| 306 |
+ |
if (fclose(fp) == EOF) |
| 307 |
+ |
error(SYSTEM, "error writing MGF temporary file"); |
| 308 |
+ |
/* execute mgf2rad to convert MGF */ |
| 309 |
+ |
strcpy(cmdbuf, "mgf2rad "); |
| 310 |
+ |
strcpy(cmdbuf+8, mgftemp); |
| 311 |
+ |
fflush(stdout); |
| 312 |
+ |
system(cmdbuf); |
| 313 |
+ |
unlink(mgftemp); /* clean up */ |
| 314 |
+ |
return(1); |
| 315 |
+ |
} |
| 316 |
+ |
|
| 317 |
+ |
|
| 318 |
+ |
int |
| 319 |
|
my_default( /* default illum action */ |
| 320 |
|
OBJREC *ob, |
| 321 |
|
struct illum_args *il, |
| 345 |
|
FVECT u, v; |
| 346 |
|
double ur[2], vr[2]; |
| 347 |
|
MAT4 xfm; |
| 348 |
+ |
char xfrot[64]; |
| 349 |
|
int nallow; |
| 350 |
|
FACE *fa; |
| 351 |
|
int i, j; |
| 357 |
|
} |
| 358 |
|
/* set up sampling */ |
| 359 |
|
if (il->sd != NULL) { |
| 360 |
< |
if (!getBSDF_xfm(xfm, fa->norm, il->udir)) { |
| 360 |
> |
if (!getBSDF_xfm(xfm, fa->norm, il->udir, xfrot)) { |
| 361 |
|
objerror(ob, WARNING, "illegal up direction"); |
| 362 |
|
freeface(ob); |
| 363 |
|
return(my_default(ob, il, nm)); |
| 399 |
|
if (r2 < vr[0]) vr[0] = r2; |
| 400 |
|
if (r2 > vr[1]) vr[1] = r2; |
| 401 |
|
} |
| 402 |
+ |
/* output detailed geometry? */ |
| 403 |
+ |
if (!(il->flags & IL_LIGHT) && il->sd != NULL && il->sd->mgf != NULL && |
| 404 |
+ |
il->thick <= FTINY) { |
| 405 |
+ |
for (j = 3; j--; ) |
| 406 |
+ |
org[j] = .5*(ur[0]+ur[1])*u[j] + |
| 407 |
+ |
.5*(vr[0]+vr[1])*v[j] + |
| 408 |
+ |
fa->offset*fa->norm[j]; |
| 409 |
+ |
printgeom(il->sd, xfrot, org, ur[1]-ur[0], vr[1]-vr[0]); |
| 410 |
+ |
} |
| 411 |
|
dim[0] = random(); |
| 412 |
|
/* sample polygon */ |
| 413 |
|
nallow = 5*n*il->nsamps; |
| 452 |
|
raysamp(dim[1], org, dir); |
| 453 |
|
} |
| 454 |
|
/* add in direct component? */ |
| 455 |
< |
if (!directvis && (il->flags & IL_LIGHT || il->sd != NULL)) { |
| 455 |
> |
if (il->flags & IL_LIGHT || il->sd != NULL) { |
| 456 |
|
MAT4 ixfm; |
| 457 |
|
if (il->sd == NULL) { |
| 458 |
|
for (i = 3; i--; ) { |
| 606 |
|
co = getcone(ob, 0); |
| 607 |
|
/* set up sampling */ |
| 608 |
|
if (il->sd != NULL) { |
| 609 |
< |
if (!getBSDF_xfm(xfm, co->ad, il->udir)) { |
| 609 |
> |
if (!getBSDF_xfm(xfm, co->ad, il->udir, NULL)) { |
| 610 |
|
objerror(ob, WARNING, "illegal up direction"); |
| 611 |
|
freecone(ob); |
| 612 |
|
return(my_default(ob, il, nm)); |
| 660 |
|
raysamp(dim[1], org, dir); |
| 661 |
|
} |
| 662 |
|
/* add in direct component? */ |
| 663 |
< |
if (!directvis && (il->flags & IL_LIGHT || il->sd != NULL)) { |
| 663 |
> |
if (il->flags & IL_LIGHT || il->sd != NULL) { |
| 664 |
|
MAT4 ixfm; |
| 665 |
|
if (il->sd == NULL) { |
| 666 |
|
for (i = 3; i--; ) { |
| 809 |
|
if (o == direct_out) |
| 810 |
|
addcolor(col, cdir); /* minus direct */ |
| 811 |
|
scalecolor(col, wt); |
| 812 |
< |
cp = &distarr[3*o]; |
| 812 |
> |
cp = &distarr[3*(k*nazi + j)]; |
| 813 |
|
addcolor(cp, col); /* sum into distribution */ |
| 814 |
|
} |
| 815 |
|
} |