10 |
|
#include "copyright.h" |
11 |
|
|
12 |
|
#include "ray.h" |
13 |
+ |
#include "paths.h" |
14 |
+ |
#include "pmapopt.h" |
15 |
|
|
16 |
+ |
extern char *progname; /* global argv[0] */ |
17 |
|
|
18 |
+ |
char RFeatureList[2048] = /* newline-separated feature list */ |
19 |
+ |
"VirtualSources\nSecondarySources\nSourceSubsampling\n" |
20 |
+ |
"SourceVisibility\nAmbientModifierSelection\n" |
21 |
+ |
"PathTracing\nRussianRoulette\nLowDiscrepancySeq\n" |
22 |
+ |
"SpecularSampling\nMaterialMixtures\nAntimatter\nBackFaceVisibility\n" |
23 |
+ |
"ScatteringModels=WGMD,Ashikhmin-Shirley\n" |
24 |
+ |
"TabulatedBSDFs=DataFile,KlemsXML,TensorTreeXML,+ViewPeakExtraction\n" |
25 |
+ |
"Instancing=Octree,TriangleMesh\nAliases\n" |
26 |
+ |
#if MAXCSAMP>3 |
27 |
+ |
"Hyperspectral\n" |
28 |
+ |
#endif |
29 |
+ |
#if !defined(SHADCACHE) || SHADCACHE > 0 |
30 |
+ |
"ShadowCache\n" |
31 |
+ |
#endif |
32 |
+ |
#ifdef DISPERSE |
33 |
+ |
"DielectricDispersion\n" |
34 |
+ |
#endif |
35 |
+ |
/* PMAP_FEATURES XXX @Roland: need to define this in pmapopt.h */ |
36 |
+ |
; |
37 |
+ |
|
38 |
+ |
|
39 |
+ |
static char * |
40 |
+ |
get_feature( /* find a specific feature (with optional sublist) */ |
41 |
+ |
const char *feat |
42 |
+ |
) |
43 |
+ |
{ |
44 |
+ |
char *cp = RFeatureList; |
45 |
+ |
int n = 0; |
46 |
+ |
|
47 |
+ |
while ((feat[n] != '\0') & (feat[n] != '=')) |
48 |
+ |
n++; |
49 |
+ |
if (!n) |
50 |
+ |
return(NULL); |
51 |
+ |
while (*cp) { |
52 |
+ |
if (!strncmp(cp, feat, n) && (cp[n] == '\n') | !feat[n] | (cp[n] == feat[n])) |
53 |
+ |
return(cp); |
54 |
+ |
while (*cp++ != '\n') |
55 |
+ |
; |
56 |
+ |
} |
57 |
+ |
return(NULL); |
58 |
+ |
} |
59 |
+ |
|
60 |
+ |
|
61 |
+ |
static int |
62 |
+ |
match_subfeatures( /* check if subfeatures are supported */ |
63 |
+ |
char *mysublist, |
64 |
+ |
char *reqs |
65 |
+ |
) |
66 |
+ |
{ |
67 |
+ |
if (mysublist) |
68 |
+ |
mysublist = strchr(mysublist, '='); |
69 |
+ |
if (!mysublist++ | !reqs) |
70 |
+ |
return(0); /* not a feature list */ |
71 |
+ |
while (*reqs) { /* check each of their subfeature requests */ |
72 |
+ |
char subfeat[64]; |
73 |
+ |
char *cp = subfeat; |
74 |
+ |
int n; |
75 |
+ |
while (*reqs && (*cp = *reqs++) != ',') |
76 |
+ |
cp++; |
77 |
+ |
*cp = '\0'; |
78 |
+ |
n = cp - subfeat; |
79 |
+ |
for (cp = mysublist; (cp = strstr(cp, subfeat)) != NULL; cp++) |
80 |
+ |
if ((cp[-1] == ',') | (cp[-1] == '=') && |
81 |
+ |
(cp[n] == ',') | (cp[n] == '\n')) |
82 |
+ |
break; /* match */ |
83 |
+ |
if (!cp) |
84 |
+ |
return(0); /* missing this one! */ |
85 |
+ |
} |
86 |
+ |
return(1); /* matched them all */ |
87 |
+ |
} |
88 |
+ |
|
89 |
+ |
|
90 |
|
int |
91 |
< |
getrenderopt(ac, av) /* get next render option */ |
92 |
< |
int ac; |
93 |
< |
char *av[]; |
91 |
> |
feature_status( /* report active feature list / check specifics */ |
92 |
> |
int ac, |
93 |
> |
char *av[] |
94 |
> |
) |
95 |
|
{ |
96 |
+ |
if (ac <= 0) /* report entire list? */ |
97 |
+ |
fputs(RFeatureList, stdout); |
98 |
+ |
|
99 |
+ |
for ( ; ac-- > 0; av++) { /* check each argument */ |
100 |
+ |
char *cp; |
101 |
+ |
if (!*av[0]) continue; |
102 |
+ |
if ((cp = strchr(av[0], '=')) != NULL) { |
103 |
+ |
if (!match_subfeatures(get_feature(av[0]), cp+1)) |
104 |
+ |
goto missing_feature; |
105 |
+ |
} else if ((cp = get_feature(av[0])) != NULL) { |
106 |
+ |
char *tp = strchr(cp, '='); |
107 |
+ |
if (tp && tp < strchr(cp, '\n')) |
108 |
+ |
do |
109 |
+ |
fputc(*cp, stdout); |
110 |
+ |
while (*cp++ != '\n'); |
111 |
+ |
} else |
112 |
+ |
goto missing_feature; |
113 |
+ |
} |
114 |
+ |
return(0); /* return satisfactory status */ |
115 |
+ |
missing_feature: /* or report error */ |
116 |
+ |
fprintf(stderr, "%s: missing feature - %s\n", progname, av[0]); |
117 |
+ |
return(1); |
118 |
+ |
} |
119 |
+ |
|
120 |
+ |
|
121 |
+ |
int |
122 |
+ |
getrenderopt( /* get next render option */ |
123 |
+ |
int ac, |
124 |
+ |
char *av[] |
125 |
+ |
) |
126 |
+ |
{ |
127 |
|
#define check(ol,al) if (av[0][ol] || \ |
128 |
|
badarg(ac-1,av+1,al)) \ |
129 |
|
return(-1) |
130 |
< |
#define bool(olen,var) switch (av[0][olen]) { \ |
130 |
> |
#define check_bool(olen,var) switch (av[0][olen]) { \ |
131 |
|
case '\0': var = !var; break; \ |
132 |
|
case 'y': case 'Y': case 't': case 'T': \ |
133 |
|
case '+': case '1': var = 1; break; \ |
141 |
|
return(-1); |
142 |
|
/* check if it's one we know */ |
143 |
|
switch (av[0][1]) { |
144 |
+ |
case 'u': /* uncorrelated sampling */ |
145 |
+ |
check_bool(2,rand_samp); |
146 |
+ |
return(0); |
147 |
|
case 'b': /* back face vis. */ |
148 |
|
if (av[0][2] == 'v') { |
149 |
< |
bool(3,backvis); |
149 |
> |
check_bool(3,backvis); |
150 |
|
return(0); |
151 |
|
} |
152 |
|
break; |
173 |
|
vspretest = atoi(av[1]); |
174 |
|
return(1); |
175 |
|
case 'v': /* visibility */ |
176 |
< |
bool(3,directvis); |
176 |
> |
check_bool(3,directvis); |
177 |
|
return(0); |
178 |
|
case 's': /* size */ |
179 |
|
check(3,"f"); |
187 |
|
check(3,"f"); |
188 |
|
specthresh = atof(av[1]); |
189 |
|
return(1); |
190 |
< |
case 'j': /* jitter */ |
190 |
> |
case 's': /* sampling */ |
191 |
|
check(3,"f"); |
192 |
|
specjitter = atof(av[1]); |
193 |
|
return(1); |
206 |
|
} |
207 |
|
break; |
208 |
|
case 'i': /* irradiance */ |
209 |
< |
bool(2,do_irrad); |
209 |
> |
check_bool(2,do_irrad); |
210 |
|
return(0); |
211 |
|
case 'a': /* ambient */ |
212 |
|
switch (av[0][2]) { |
248 |
|
amblp = amblist; |
249 |
|
} |
250 |
|
if (av[0][2] == 'I') { /* file */ |
251 |
< |
rval = wordfile(amblp, |
252 |
< |
getpath(av[1],getlibpath(),R_OK)); |
251 |
> |
rval = wordfile(amblp, AMBLLEN-(amblp-amblist), |
252 |
> |
getpath(av[1],getrlibpath(),R_OK)); |
253 |
|
if (rval < 0) { |
254 |
|
sprintf(errmsg, |
255 |
< |
"cannot open ambient include file \"%s\"", av[0]); |
255 |
> |
"cannot open ambient include file \"%s\"", av[1]); |
256 |
|
error(SYSTEM, errmsg); |
257 |
|
} |
258 |
|
amblp += rval; |
259 |
|
} else { |
260 |
< |
*amblp++ = av[1]; |
260 |
> |
*amblp++ = savqstr(av[1]); |
261 |
|
*amblp = NULL; |
262 |
|
} |
263 |
|
return(1); |
269 |
|
amblp = amblist; |
270 |
|
} |
271 |
|
if (av[0][2] == 'E') { /* file */ |
272 |
< |
rval = wordfile(amblp, |
273 |
< |
getpath(av[1],getlibpath(),R_OK)); |
272 |
> |
rval = wordfile(amblp, AMBLLEN-(amblp-amblist), |
273 |
> |
getpath(av[1],getrlibpath(),R_OK)); |
274 |
|
if (rval < 0) { |
275 |
|
sprintf(errmsg, |
276 |
< |
"cannot open ambient exclude file \"%s\"", av[0]); |
276 |
> |
"cannot open ambient exclude file \"%s\"", av[1]); |
277 |
|
error(SYSTEM, errmsg); |
278 |
|
} |
279 |
|
amblp += rval; |
280 |
|
} else { |
281 |
< |
*amblp++ = av[1]; |
281 |
> |
*amblp++ = savqstr(av[1]); |
282 |
|
*amblp = NULL; |
283 |
|
} |
284 |
|
return(1); |
285 |
|
case 'f': /* file */ |
286 |
|
check(3,"s"); |
287 |
< |
ambfile= av[1]; |
287 |
> |
ambfile = savqstr(av[1]); |
288 |
|
return(1); |
289 |
|
} |
290 |
|
break; |
312 |
|
return(1); |
313 |
|
} |
314 |
|
break; |
315 |
+ |
#if MAXCSAMP>3 |
316 |
+ |
case 'c': /* spectral sampling */ |
317 |
+ |
switch (av[0][2]) { |
318 |
+ |
case 's': /* spectral bin count */ |
319 |
+ |
check(3,"i"); |
320 |
+ |
NCSAMP = atoi(av[1]); |
321 |
+ |
return(1); |
322 |
+ |
case 'w': /* wavelength extrema */ |
323 |
+ |
check(3,"ff"); |
324 |
+ |
WLPART[0] = atof(av[1]); |
325 |
+ |
WLPART[3] = atof(av[2]); |
326 |
+ |
return(2); |
327 |
+ |
} |
328 |
+ |
break; |
329 |
+ |
#endif |
330 |
|
} |
331 |
< |
return(-1); /* unknown option */ |
331 |
> |
|
332 |
> |
/* PMAP: Parse photon mapping options */ |
333 |
> |
return(getPmapRenderOpt(ac, av)); |
334 |
> |
|
335 |
> |
/* return(-1); */ /* unknown option */ |
336 |
|
|
337 |
|
#undef check |
338 |
< |
#undef bool |
338 |
> |
#undef check_bool |
339 |
|
} |
340 |
|
|
341 |
|
|
342 |
|
void |
343 |
< |
print_rdefaults() /* print default render values to stdout */ |
343 |
> |
print_rdefaults(void) /* print default render values to stdout */ |
344 |
|
{ |
216 |
– |
register char *cp; |
217 |
– |
|
345 |
|
printf(do_irrad ? "-i+\t\t\t\t# irradiance calculation on\n" : |
346 |
|
"-i-\t\t\t\t# irradiance calculation off\n"); |
347 |
+ |
printf(rand_samp ? "-u+\t\t\t\t# uncorrelated Monte Carlo sampling\n" : |
348 |
+ |
"-u-\t\t\t\t# correlated quasi-Monte Carlo sampling\n"); |
349 |
|
printf(backvis ? "-bv+\t\t\t\t# back face visibility on\n" : |
350 |
|
"-bv-\t\t\t\t# back face visibility off\n"); |
351 |
|
printf("-dt %f\t\t\t# direct threshold\n", shadthresh); |
356 |
|
printf("-dp %-9d\t\t\t# direct pretest density\n", vspretest); |
357 |
|
printf(directvis ? "-dv+\t\t\t\t# direct visibility on\n" : |
358 |
|
"-dv-\t\t\t\t# direct visibility off\n"); |
359 |
< |
printf("-sj %f\t\t\t# specular jitter\n", specjitter); |
359 |
> |
printf("-ss %f\t\t\t# specular sampling\n", specjitter); |
360 |
|
printf("-st %f\t\t\t# specular threshold\n", specthresh); |
361 |
|
printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED), |
362 |
|
colval(ambval,GRN), colval(ambval, BLU)); |
374 |
|
colval(salbedo,GRN), colval(salbedo,BLU)); |
375 |
|
printf("-mg %f\t\t\t# mist scattering eccentricity\n", seccg); |
376 |
|
printf("-ms %f\t\t\t# mist sampling distance\n", ssampdist); |
377 |
< |
printf("-lr %-9d\t\t\t# limit reflection\n", maxdepth); |
378 |
< |
printf("-lw %f\t\t\t# limit weight\n", minweight); |
377 |
> |
if (NCSAMP > 3) { |
378 |
> |
printf("-cs %-2d\t\t\t\t# number of spectral bins\n", NCSAMP); |
379 |
> |
printf("-cw %3.0f %3.0f\t\t\t# wavelength limits (nm)\n", |
380 |
> |
WLPART[3], WLPART[0]); |
381 |
> |
} |
382 |
> |
printf("-lr %-9d\t\t\t# limit reflection%s\n", maxdepth, |
383 |
> |
maxdepth<=0 ? " (Russian roulette)" : ""); |
384 |
> |
printf("-lw %.2e\t\t\t# limit weight\n", minweight); |
385 |
> |
|
386 |
> |
/* PMAP: output photon map defaults */ |
387 |
> |
printPmapDefaults(); |
388 |
|
} |