10 |
|
#include <string.h> |
11 |
|
#include <stdlib.h> |
12 |
|
#include <math.h> |
13 |
+ |
#include "rtprocess.h" |
14 |
|
#include "bsdfrep.h" |
15 |
|
|
16 |
|
const float colarr[6][3] = { |
91 |
|
#ifdef DEBUG |
92 |
|
fprintf(stderr, "Minimum BSDF set to %.4f\n", bsdf_min); |
93 |
|
#endif |
94 |
< |
min_log = log(bsdf_min*.5); |
94 |
> |
min_log = log(bsdf_min*.5 + 1e-5); |
95 |
|
/* output BSDF rep. */ |
96 |
|
for (n = 0; (n < 6) & (2*n+3 < argc); n++) { |
97 |
< |
double theta = atof(argv[2*n+2]); |
97 |
> |
double theta = (M_PI/180.)*atof(argv[2*n+2]); |
98 |
> |
double phi = (M_PI/180.)*atof(argv[2*n+3]); |
99 |
> |
if (theta < -FTINY) { |
100 |
> |
fprintf(stderr, "%s: theta values must be positive\n", |
101 |
> |
progname); |
102 |
> |
return(1); |
103 |
> |
} |
104 |
|
if (inpXML) { |
105 |
< |
input_orient = (theta <= 90.) ? 1 : -1; |
105 |
> |
input_orient = (theta <= M_PI/2.) ? 1 : -1; |
106 |
|
output_orient = doTrans ? -input_orient : input_orient; |
107 |
|
} |
108 |
< |
idir[2] = sin((M_PI/180.)*theta); |
109 |
< |
idir[0] = idir[2] * cos((M_PI/180.)*atof(argv[2*n+3])); |
110 |
< |
idir[1] = idir[2] * sin((M_PI/180.)*atof(argv[2*n+3])); |
108 |
> |
idir[2] = sin(theta); |
109 |
> |
idir[0] = idir[2] * cos(phi); |
110 |
> |
idir[1] = idir[2] * sin(phi); |
111 |
|
idir[2] = input_orient * sqrt(1. - idir[2]*idir[2]); |
112 |
|
#ifdef DEBUG |
113 |
|
fprintf(stderr, "Computing BSDF for incident direction (%.1f,%.1f)\n", |
137 |
|
for (i = 0; i < rbf->nrbf; i++) { |
138 |
|
ovec_from_pos(odir, rbf->rbfa[i].gx, rbf->rbfa[i].gy); |
139 |
|
bsdf = eval_rbfrep(rbf, odir) / (output_orient*odir[2]); |
140 |
< |
bsdf = log(bsdf) - min_log; |
140 |
> |
bsdf = log(bsdf + 1e-5) - min_log; |
141 |
|
printf("pmat sphere p%d\n0\n0\n4 %f %f %f %f\n", |
142 |
|
i+1, odir[0]*bsdf, odir[1]*bsdf, odir[2]*bsdf, |
143 |
|
.007*bsdf); |
144 |
|
} |
145 |
|
} |
146 |
|
fflush(stdout); |
147 |
< |
sprintf(buf, "gensurf tmat bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); |
147 |
> |
sprintf(buf, "gensurf tmat bsdf%d - - - %d %d", n+1, |
148 |
> |
GRIDRES-1, GRIDRES-1); |
149 |
|
fp = popen(buf, "w"); |
150 |
|
if (fp == NULL) { |
151 |
|
fprintf(stderr, "%s: cannot open '| %s'\n", progname, buf); |
163 |
|
} else |
164 |
|
bsdf = eval_rbfrep(rbf, odir) / |
165 |
|
(output_orient*odir[2]); |
166 |
< |
bsdf = log(bsdf) - min_log; |
166 |
> |
bsdf = log(bsdf + 1e-5) - min_log; |
167 |
|
fprintf(fp, "%.8e %.8e %.8e\n", |
168 |
|
odir[0]*bsdf, odir[1]*bsdf, odir[2]*bsdf); |
169 |
|
} |