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 */ |
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; |
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)); |