11 |
|
#include <stdio.h> |
12 |
|
#include <stdlib.h> |
13 |
|
#include <math.h> |
14 |
+ |
#include "random.h" |
15 |
|
#include "platform.h" |
16 |
+ |
#include "rtprocess.h" |
17 |
|
#include "calcomp.h" |
18 |
|
#include "bsdfrep.h" |
19 |
|
/* global argv[0] */ |
26 |
|
const double ssamp_thresh = 0.35; |
27 |
|
/* number of super-samples */ |
28 |
|
const int nssamp = 100; |
29 |
+ |
/* limit on number of RBF lobes */ |
30 |
+ |
static int lobe_lim = 15000; |
31 |
|
|
32 |
|
/* Output XML prologue to stdout */ |
33 |
|
static void |
46 |
|
puts("<Optical>"); |
47 |
|
puts("<Layer>"); |
48 |
|
puts("\t<Material>"); |
49 |
< |
puts("\t\t<Name>Name</Name>"); |
50 |
< |
puts("\t\t<Manufacturer>Manufacturer</Manufacturer>"); |
49 |
> |
printf("\t\t<Name>%s</Name>\n", bsdf_name[0] ? bsdf_name : "Unknown"); |
50 |
> |
printf("\t\t<Manufacturer>%s</Manufacturer>\n", |
51 |
> |
bsdf_manuf[0] ? bsdf_manuf : "Unknown"); |
52 |
|
puts("\t\t<DeviceType>Other</DeviceType>"); |
53 |
|
puts("\t</Material>"); |
54 |
|
puts("\t<DataDefinition>"); |
117 |
|
{ |
118 |
|
const int sqres = 1<<samp_order; |
119 |
|
FILE *ofp = NULL; |
120 |
+ |
int assignD = 0; |
121 |
|
char cmd[128]; |
122 |
|
int ix, ox, oy; |
123 |
|
double iovec[6]; |
125 |
|
|
126 |
|
data_prologue(); /* begin output */ |
127 |
|
if (pctcull >= 0) { |
128 |
< |
sprintf(cmd, "rttree_reduce -h -a -ff -r 3 -t %f -g %d", |
128 |
> |
sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d", |
129 |
|
pctcull, samp_order); |
130 |
|
fflush(stdout); |
131 |
|
ofp = popen(cmd, "w"); |
135 |
|
exit(1); |
136 |
|
} |
137 |
|
SET_FILE_BINARY(ofp); |
138 |
+ |
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
139 |
+ |
flockfile(ofp); |
140 |
+ |
#endif |
141 |
|
} else |
142 |
|
fputs("{\n", stdout); |
143 |
+ |
/* need to assign Dx, Dy, Dz? */ |
144 |
+ |
if (funame != NULL) |
145 |
+ |
assignD = (fundefined(funame) < 6); |
146 |
|
/* run through directions */ |
147 |
|
for (ix = 0; ix < sqres/2; ix++) { |
148 |
|
RBFNODE *rbf = NULL; |
150 |
|
iovec[1] = .0; |
151 |
|
iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]); |
152 |
|
if (funame == NULL) |
153 |
< |
rbf = advect_rbf(iovec); |
153 |
> |
rbf = advect_rbf(iovec, lobe_lim); |
154 |
|
for (ox = 0; ox < sqres; ox++) { |
155 |
|
float last_bsdf = -1; |
156 |
|
for (oy = 0; oy < sqres; oy++) { |
161 |
|
bsdf = eval_rbfrep(rbf, iovec+3) * |
162 |
|
output_orient/iovec[5]; |
163 |
|
else { |
164 |
< |
double ssa[3], ssvec[6]; |
164 |
> |
double ssa[3], ssvec[6], sum; |
165 |
|
int ssi; |
166 |
+ |
if (assignD) { |
167 |
+ |
varset("Dx", '=', -iovec[3]); |
168 |
+ |
varset("Dy", '=', -iovec[4]); |
169 |
+ |
varset("Dz", '=', -iovec[5]); |
170 |
+ |
++eclock; |
171 |
+ |
} |
172 |
|
bsdf = funvalue(funame, 6, iovec); |
173 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
174 |
< |
bsdf = 0; /* super-sample voxel */ |
174 |
> |
sum = 0; /* super-sample voxel */ |
175 |
|
for (ssi = nssamp; ssi--; ) { |
176 |
< |
SDmultiSamp(ssa, 3, (ssi+drand48())/nssamp); |
176 |
> |
SDmultiSamp(ssa, 3, (ssi+frandom())/nssamp); |
177 |
|
ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.; |
178 |
|
ssvec[1] = .0; |
179 |
|
ssvec[2] = input_orient * |
183 |
|
ssvec[5] = output_orient * |
184 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
185 |
|
ssvec[4]*ssvec[4]); |
186 |
< |
bsdf += funvalue(funame, 6, ssvec); |
186 |
> |
if (assignD) { |
187 |
> |
varset("Dx", '=', -iovec[3]); |
188 |
> |
varset("Dy", '=', -iovec[4]); |
189 |
> |
varset("Dz", '=', -iovec[5]); |
190 |
> |
++eclock; |
191 |
> |
} |
192 |
> |
sum += funvalue(funame, 6, ssvec); |
193 |
|
} |
194 |
< |
bsdf /= (float)nssamp; |
194 |
> |
bsdf = sum/nssamp; |
195 |
|
} |
196 |
|
} |
197 |
|
if (pctcull >= 0) |
224 |
|
{ |
225 |
|
const int sqres = 1<<samp_order; |
226 |
|
FILE *ofp = NULL; |
227 |
+ |
int assignD = 0; |
228 |
|
char cmd[128]; |
229 |
|
int ix, iy, ox, oy; |
230 |
|
double iovec[6]; |
232 |
|
|
233 |
|
data_prologue(); /* begin output */ |
234 |
|
if (pctcull >= 0) { |
235 |
< |
sprintf(cmd, "rttree_reduce -h -a -ff -r 4 -t %f -g %d", |
235 |
> |
sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d", |
236 |
> |
(input_orient>0 ^ output_orient>0) ? "" : " -a", |
237 |
|
pctcull, samp_order); |
238 |
|
fflush(stdout); |
239 |
|
ofp = popen(cmd, "w"); |
242 |
|
progname); |
243 |
|
exit(1); |
244 |
|
} |
245 |
+ |
SET_FILE_BINARY(ofp); |
246 |
+ |
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
247 |
+ |
flockfile(ofp); |
248 |
+ |
#endif |
249 |
|
} else |
250 |
|
fputs("{\n", stdout); |
251 |
+ |
/* need to assign Dx, Dy, Dz? */ |
252 |
+ |
if (funame != NULL) |
253 |
+ |
assignD = (fundefined(funame) < 6); |
254 |
|
/* run through directions */ |
255 |
|
for (ix = 0; ix < sqres; ix++) |
256 |
|
for (iy = 0; iy < sqres; iy++) { |
259 |
|
iovec[2] = input_orient * |
260 |
|
sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]); |
261 |
|
if (funame == NULL) |
262 |
< |
rbf = advect_rbf(iovec); |
262 |
> |
rbf = advect_rbf(iovec, lobe_lim); |
263 |
|
for (ox = 0; ox < sqres; ox++) { |
264 |
|
float last_bsdf = -1; |
265 |
|
for (oy = 0; oy < sqres; oy++) { |
270 |
|
bsdf = eval_rbfrep(rbf, iovec+3) * |
271 |
|
output_orient/iovec[5]; |
272 |
|
else { |
273 |
< |
double ssa[4], ssvec[6]; |
273 |
> |
double ssa[4], ssvec[6], sum; |
274 |
|
int ssi; |
275 |
+ |
if (assignD) { |
276 |
+ |
varset("Dx", '=', -iovec[3]); |
277 |
+ |
varset("Dy", '=', -iovec[4]); |
278 |
+ |
varset("Dz", '=', -iovec[5]); |
279 |
+ |
++eclock; |
280 |
+ |
} |
281 |
|
bsdf = funvalue(funame, 6, iovec); |
282 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
283 |
< |
bsdf = 0; /* super-sample voxel */ |
283 |
> |
sum = 0; /* super-sample voxel */ |
284 |
|
for (ssi = nssamp; ssi--; ) { |
285 |
< |
SDmultiSamp(ssa, 4, (ssi+drand48())/nssamp); |
285 |
> |
SDmultiSamp(ssa, 4, (ssi+frandom())/nssamp); |
286 |
|
SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres, |
287 |
|
1.-(iy+ssa[1])/sqres); |
288 |
|
ssvec[2] = output_orient * |
293 |
|
ssvec[5] = output_orient * |
294 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
295 |
|
ssvec[4]*ssvec[4]); |
296 |
< |
bsdf += funvalue(funame, 6, ssvec); |
296 |
> |
if (assignD) { |
297 |
> |
varset("Dx", '=', -iovec[3]); |
298 |
> |
varset("Dy", '=', -iovec[4]); |
299 |
> |
varset("Dz", '=', -iovec[5]); |
300 |
> |
++eclock; |
301 |
> |
} |
302 |
> |
sum += funvalue(funame, 6, ssvec); |
303 |
|
} |
304 |
< |
bsdf /= (float)nssamp; |
304 |
> |
bsdf = sum/nssamp; |
305 |
|
} |
306 |
|
} |
307 |
|
if (pctcull >= 0) |
369 |
|
case 'g': |
370 |
|
samp_order = atoi(argv[++i]); |
371 |
|
break; |
372 |
+ |
case 'l': |
373 |
+ |
lobe_lim = atoi(argv[++i]); |
374 |
+ |
break; |
375 |
|
default: |
376 |
|
goto userr; |
377 |
|
} |
378 |
|
if (single_plane_incident >= 0) { /* function-based BSDF? */ |
379 |
|
void (*evf)(char *s) = single_plane_incident ? |
380 |
|
&eval_isotropic : &eval_anisotropic; |
381 |
< |
if (i != argc-1 || fundefined(argv[i]) != 6) { |
381 |
> |
if (i != argc-1 || fundefined(argv[i]) < 3) { |
382 |
|
fprintf(stderr, |
383 |
|
"%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n", |
384 |
|
progname); |
385 |
+ |
fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n"); |
386 |
|
goto userr; |
387 |
|
} |
388 |
+ |
++eclock; |
389 |
|
xml_prologue(argc, argv); /* start XML output */ |
390 |
|
if (dofwd) { |
391 |
|
input_orient = -1; |
438 |
|
return(0); |
439 |
|
userr: |
440 |
|
fprintf(stderr, |
441 |
< |
"Usage: %s [-g Nlog2][-t pctcull] [bsdf.sir ..] > bsdf.xml\n", |
441 |
> |
"Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", |
442 |
|
progname); |
443 |
|
fprintf(stderr, |
444 |
|
" or: %s -t{3|4} [-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n", |