1 |
greg |
2.1 |
#ifndef lint |
2 |
greg |
2.24 |
static const char RCSid[] = "$Id: renderopts.c,v 2.23 2023/11/17 20:02:07 greg Exp $"; |
3 |
greg |
2.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* renderopts.c - process common rendering options |
6 |
|
|
* |
7 |
|
|
* External symbols declared in ray.h |
8 |
|
|
*/ |
9 |
|
|
|
10 |
greg |
2.2 |
#include "copyright.h" |
11 |
greg |
2.1 |
|
12 |
|
|
#include "ray.h" |
13 |
greg |
2.5 |
#include "paths.h" |
14 |
greg |
2.16 |
#include "pmapopt.h" |
15 |
greg |
2.1 |
|
16 |
greg |
2.19 |
extern char *progname; /* global argv[0] */ |
17 |
|
|
|
18 |
|
|
char RFeatureList[2048] = /* newline-separated feature list */ |
19 |
greg |
2.20 |
"VirtualSources\nSecondarySources\nSourceSubsampling\n" |
20 |
|
|
"SourceVisibility\nAmbientModifierSelection\n" |
21 |
|
|
"PathTracing\nRussianRoulette\nLowDiscrepancySeq\n" |
22 |
|
|
"SpecularSampling\nMaterialMixtures\nAntimatter\nBackFaceVisibility\n" |
23 |
greg |
2.22 |
"ScatteringModels=WGMD,Ashikhmin-Shirley\n" |
24 |
greg |
2.19 |
"TabulatedBSDFs=DataFile,KlemsXML,TensorTreeXML,+ViewPeakExtraction\n" |
25 |
|
|
"Instancing=Octree,TriangleMesh\nAliases\n" |
26 |
greg |
2.23 |
#if MAXCSAMP>3 |
27 |
|
|
"Hyperspectral\n" |
28 |
|
|
#endif |
29 |
greg |
2.19 |
#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 |
|
|
if (!(cp = strstr(mysublist, subfeat)) || |
80 |
greg |
2.21 |
(cp[-1] != ',') & (cp[-1] != '=') || |
81 |
greg |
2.19 |
(cp[n] != ',') & (cp[n] != '\n')) |
82 |
|
|
return(0); /* missing this one! */ |
83 |
|
|
} |
84 |
|
|
return(1); /* matched them all */ |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
int |
89 |
|
|
feature_status( /* report active feature list / check specifics */ |
90 |
|
|
int ac, |
91 |
|
|
char *av[] |
92 |
|
|
) |
93 |
|
|
{ |
94 |
|
|
if (ac <= 0) /* report entire list? */ |
95 |
|
|
fputs(RFeatureList, stdout); |
96 |
|
|
|
97 |
|
|
for ( ; ac-- > 0; av++) { /* check each argument */ |
98 |
|
|
char *cp; |
99 |
|
|
if (!*av[0]) continue; |
100 |
|
|
if ((cp = strchr(av[0], '=')) != NULL) { |
101 |
|
|
if (!match_subfeatures(get_feature(av[0]), cp+1)) |
102 |
|
|
goto missing_feature; |
103 |
|
|
} else if ((cp = get_feature(av[0])) != NULL) { |
104 |
|
|
char *tp = strchr(cp, '='); |
105 |
|
|
if (tp && tp < strchr(cp, '\n')) |
106 |
|
|
do |
107 |
|
|
fputc(*cp, stdout); |
108 |
|
|
while (*cp++ != '\n'); |
109 |
|
|
} else |
110 |
|
|
goto missing_feature; |
111 |
|
|
} |
112 |
|
|
return(0); /* return satisfactory status */ |
113 |
|
|
missing_feature: /* or report error */ |
114 |
|
|
fprintf(stderr, "%s: missing feature - %s\n", progname, av[0]); |
115 |
|
|
return(1); |
116 |
|
|
} |
117 |
|
|
|
118 |
greg |
2.1 |
|
119 |
greg |
2.15 |
int |
120 |
schorsch |
2.4 |
getrenderopt( /* get next render option */ |
121 |
|
|
int ac, |
122 |
|
|
char *av[] |
123 |
|
|
) |
124 |
greg |
2.1 |
{ |
125 |
|
|
#define check(ol,al) if (av[0][ol] || \ |
126 |
|
|
badarg(ac-1,av+1,al)) \ |
127 |
|
|
return(-1) |
128 |
schorsch |
2.17 |
#define check_bool(olen,var) switch (av[0][olen]) { \ |
129 |
greg |
2.1 |
case '\0': var = !var; break; \ |
130 |
|
|
case 'y': case 'Y': case 't': case 'T': \ |
131 |
|
|
case '+': case '1': var = 1; break; \ |
132 |
|
|
case 'n': case 'N': case 'f': case 'F': \ |
133 |
|
|
case '-': case '0': var = 0; break; \ |
134 |
|
|
default: return(-1); } |
135 |
|
|
static char **amblp; /* pointer to build ambient list */ |
136 |
|
|
int rval; |
137 |
|
|
/* is it even an option? */ |
138 |
|
|
if (ac < 1 || av[0] == NULL || av[0][0] != '-') |
139 |
|
|
return(-1); |
140 |
|
|
/* check if it's one we know */ |
141 |
|
|
switch (av[0][1]) { |
142 |
greg |
2.10 |
case 'u': /* uncorrelated sampling */ |
143 |
schorsch |
2.17 |
check_bool(2,rand_samp); |
144 |
greg |
2.9 |
return(0); |
145 |
greg |
2.1 |
case 'b': /* back face vis. */ |
146 |
|
|
if (av[0][2] == 'v') { |
147 |
schorsch |
2.17 |
check_bool(3,backvis); |
148 |
greg |
2.1 |
return(0); |
149 |
|
|
} |
150 |
|
|
break; |
151 |
|
|
case 'd': /* direct */ |
152 |
|
|
switch (av[0][2]) { |
153 |
|
|
case 't': /* threshold */ |
154 |
|
|
check(3,"f"); |
155 |
|
|
shadthresh = atof(av[1]); |
156 |
|
|
return(1); |
157 |
|
|
case 'c': /* certainty */ |
158 |
|
|
check(3,"f"); |
159 |
|
|
shadcert = atof(av[1]); |
160 |
|
|
return(1); |
161 |
|
|
case 'j': /* jitter */ |
162 |
|
|
check(3,"f"); |
163 |
|
|
dstrsrc = atof(av[1]); |
164 |
|
|
return(1); |
165 |
|
|
case 'r': /* relays */ |
166 |
|
|
check(3,"i"); |
167 |
|
|
directrelay = atoi(av[1]); |
168 |
|
|
return(1); |
169 |
|
|
case 'p': /* pretest */ |
170 |
|
|
check(3,"i"); |
171 |
|
|
vspretest = atoi(av[1]); |
172 |
|
|
return(1); |
173 |
|
|
case 'v': /* visibility */ |
174 |
schorsch |
2.17 |
check_bool(3,directvis); |
175 |
greg |
2.1 |
return(0); |
176 |
|
|
case 's': /* size */ |
177 |
|
|
check(3,"f"); |
178 |
|
|
srcsizerat = atof(av[1]); |
179 |
|
|
return(1); |
180 |
|
|
} |
181 |
|
|
break; |
182 |
|
|
case 's': /* specular */ |
183 |
|
|
switch (av[0][2]) { |
184 |
|
|
case 't': /* threshold */ |
185 |
|
|
check(3,"f"); |
186 |
|
|
specthresh = atof(av[1]); |
187 |
|
|
return(1); |
188 |
greg |
2.14 |
case 's': /* sampling */ |
189 |
greg |
2.1 |
check(3,"f"); |
190 |
|
|
specjitter = atof(av[1]); |
191 |
|
|
return(1); |
192 |
|
|
} |
193 |
|
|
break; |
194 |
|
|
case 'l': /* limit */ |
195 |
|
|
switch (av[0][2]) { |
196 |
|
|
case 'r': /* recursion */ |
197 |
|
|
check(3,"i"); |
198 |
|
|
maxdepth = atoi(av[1]); |
199 |
|
|
return(1); |
200 |
|
|
case 'w': /* weight */ |
201 |
|
|
check(3,"f"); |
202 |
|
|
minweight = atof(av[1]); |
203 |
|
|
return(1); |
204 |
|
|
} |
205 |
|
|
break; |
206 |
|
|
case 'i': /* irradiance */ |
207 |
schorsch |
2.17 |
check_bool(2,do_irrad); |
208 |
greg |
2.1 |
return(0); |
209 |
|
|
case 'a': /* ambient */ |
210 |
|
|
switch (av[0][2]) { |
211 |
|
|
case 'v': /* value */ |
212 |
|
|
check(3,"fff"); |
213 |
|
|
setcolor(ambval, atof(av[1]), |
214 |
|
|
atof(av[2]), |
215 |
|
|
atof(av[3])); |
216 |
|
|
return(3); |
217 |
|
|
case 'w': /* weight */ |
218 |
|
|
check(3,"i"); |
219 |
|
|
ambvwt = atoi(av[1]); |
220 |
|
|
return(1); |
221 |
|
|
case 'a': /* accuracy */ |
222 |
|
|
check(3,"f"); |
223 |
|
|
ambacc = atof(av[1]); |
224 |
|
|
return(1); |
225 |
|
|
case 'r': /* resolution */ |
226 |
|
|
check(3,"i"); |
227 |
|
|
ambres = atoi(av[1]); |
228 |
|
|
return(1); |
229 |
|
|
case 'd': /* divisions */ |
230 |
|
|
check(3,"i"); |
231 |
|
|
ambdiv = atoi(av[1]); |
232 |
|
|
return(1); |
233 |
|
|
case 's': /* super-samp */ |
234 |
|
|
check(3,"i"); |
235 |
|
|
ambssamp = atoi(av[1]); |
236 |
|
|
return(1); |
237 |
|
|
case 'b': /* bounces */ |
238 |
|
|
check(3,"i"); |
239 |
|
|
ambounce = atoi(av[1]); |
240 |
|
|
return(1); |
241 |
|
|
case 'i': /* include */ |
242 |
|
|
case 'I': |
243 |
|
|
check(3,"s"); |
244 |
|
|
if (ambincl != 1) { |
245 |
|
|
ambincl = 1; |
246 |
|
|
amblp = amblist; |
247 |
|
|
} |
248 |
|
|
if (av[0][2] == 'I') { /* file */ |
249 |
greg |
2.18 |
rval = wordfile(amblp, AMBLLEN-(amblp-amblist), |
250 |
greg |
2.3 |
getpath(av[1],getrlibpath(),R_OK)); |
251 |
greg |
2.1 |
if (rval < 0) { |
252 |
|
|
sprintf(errmsg, |
253 |
greg |
2.7 |
"cannot open ambient include file \"%s\"", av[1]); |
254 |
greg |
2.1 |
error(SYSTEM, errmsg); |
255 |
|
|
} |
256 |
|
|
amblp += rval; |
257 |
|
|
} else { |
258 |
greg |
2.6 |
*amblp++ = savqstr(av[1]); |
259 |
greg |
2.1 |
*amblp = NULL; |
260 |
|
|
} |
261 |
|
|
return(1); |
262 |
|
|
case 'e': /* exclude */ |
263 |
|
|
case 'E': |
264 |
|
|
check(3,"s"); |
265 |
|
|
if (ambincl != 0) { |
266 |
|
|
ambincl = 0; |
267 |
|
|
amblp = amblist; |
268 |
|
|
} |
269 |
|
|
if (av[0][2] == 'E') { /* file */ |
270 |
greg |
2.18 |
rval = wordfile(amblp, AMBLLEN-(amblp-amblist), |
271 |
greg |
2.3 |
getpath(av[1],getrlibpath(),R_OK)); |
272 |
greg |
2.1 |
if (rval < 0) { |
273 |
|
|
sprintf(errmsg, |
274 |
greg |
2.7 |
"cannot open ambient exclude file \"%s\"", av[1]); |
275 |
greg |
2.1 |
error(SYSTEM, errmsg); |
276 |
|
|
} |
277 |
|
|
amblp += rval; |
278 |
|
|
} else { |
279 |
greg |
2.6 |
*amblp++ = savqstr(av[1]); |
280 |
greg |
2.1 |
*amblp = NULL; |
281 |
|
|
} |
282 |
|
|
return(1); |
283 |
|
|
case 'f': /* file */ |
284 |
|
|
check(3,"s"); |
285 |
greg |
2.6 |
ambfile = savqstr(av[1]); |
286 |
greg |
2.1 |
return(1); |
287 |
|
|
} |
288 |
|
|
break; |
289 |
|
|
case 'm': /* medium */ |
290 |
|
|
switch (av[0][2]) { |
291 |
|
|
case 'e': /* extinction */ |
292 |
|
|
check(3,"fff"); |
293 |
|
|
setcolor(cextinction, atof(av[1]), |
294 |
|
|
atof(av[2]), |
295 |
|
|
atof(av[3])); |
296 |
|
|
return(3); |
297 |
|
|
case 'a': /* albedo */ |
298 |
|
|
check(3,"fff"); |
299 |
|
|
setcolor(salbedo, atof(av[1]), |
300 |
|
|
atof(av[2]), |
301 |
|
|
atof(av[3])); |
302 |
|
|
return(3); |
303 |
|
|
case 'g': /* eccentr. */ |
304 |
|
|
check(3,"f"); |
305 |
|
|
seccg = atof(av[1]); |
306 |
|
|
return(1); |
307 |
|
|
case 's': /* sampling */ |
308 |
|
|
check(3,"f"); |
309 |
|
|
ssampdist = atof(av[1]); |
310 |
|
|
return(1); |
311 |
|
|
} |
312 |
|
|
break; |
313 |
greg |
2.23 |
#if MAXCSAMP>3 |
314 |
|
|
case 'c': /* spectral sampling */ |
315 |
|
|
switch (av[0][2]) { |
316 |
|
|
case 's': /* spectral bin count */ |
317 |
|
|
check(3,"i"); |
318 |
|
|
NCSAMP = atoi(av[1]); |
319 |
|
|
return(1); |
320 |
|
|
case 'w': /* wavelength extrema */ |
321 |
|
|
check(3,"ff"); |
322 |
|
|
WLPART[0] = atof(av[1]); |
323 |
|
|
WLPART[3] = atof(av[2]); |
324 |
greg |
2.24 |
return(2); |
325 |
greg |
2.23 |
} |
326 |
|
|
break; |
327 |
|
|
#endif |
328 |
greg |
2.1 |
} |
329 |
greg |
2.16 |
|
330 |
|
|
/* PMAP: Parse photon mapping options */ |
331 |
|
|
return(getPmapRenderOpt(ac, av)); |
332 |
|
|
|
333 |
|
|
/* return(-1); */ /* unknown option */ |
334 |
greg |
2.1 |
|
335 |
|
|
#undef check |
336 |
schorsch |
2.17 |
#undef check_bool |
337 |
greg |
2.1 |
} |
338 |
|
|
|
339 |
|
|
|
340 |
greg |
2.15 |
void |
341 |
schorsch |
2.4 |
print_rdefaults(void) /* print default render values to stdout */ |
342 |
greg |
2.1 |
{ |
343 |
|
|
printf(do_irrad ? "-i+\t\t\t\t# irradiance calculation on\n" : |
344 |
|
|
"-i-\t\t\t\t# irradiance calculation off\n"); |
345 |
greg |
2.11 |
printf(rand_samp ? "-u+\t\t\t\t# uncorrelated Monte Carlo sampling\n" : |
346 |
greg |
2.12 |
"-u-\t\t\t\t# correlated quasi-Monte Carlo sampling\n"); |
347 |
greg |
2.1 |
printf(backvis ? "-bv+\t\t\t\t# back face visibility on\n" : |
348 |
|
|
"-bv-\t\t\t\t# back face visibility off\n"); |
349 |
|
|
printf("-dt %f\t\t\t# direct threshold\n", shadthresh); |
350 |
|
|
printf("-dc %f\t\t\t# direct certainty\n", shadcert); |
351 |
|
|
printf("-dj %f\t\t\t# direct jitter\n", dstrsrc); |
352 |
|
|
printf("-ds %f\t\t\t# direct sampling\n", srcsizerat); |
353 |
|
|
printf("-dr %-9d\t\t\t# direct relays\n", directrelay); |
354 |
|
|
printf("-dp %-9d\t\t\t# direct pretest density\n", vspretest); |
355 |
|
|
printf(directvis ? "-dv+\t\t\t\t# direct visibility on\n" : |
356 |
|
|
"-dv-\t\t\t\t# direct visibility off\n"); |
357 |
greg |
2.14 |
printf("-ss %f\t\t\t# specular sampling\n", specjitter); |
358 |
greg |
2.1 |
printf("-st %f\t\t\t# specular threshold\n", specthresh); |
359 |
|
|
printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED), |
360 |
|
|
colval(ambval,GRN), colval(ambval, BLU)); |
361 |
|
|
printf("-aw %-9d\t\t\t# ambient value weight\n", ambvwt); |
362 |
|
|
printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce); |
363 |
|
|
printf("-aa %f\t\t\t# ambient accuracy\n", ambacc); |
364 |
|
|
printf("-ar %-9d\t\t\t# ambient resolution\n", ambres); |
365 |
|
|
printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv); |
366 |
|
|
printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp); |
367 |
|
|
printf("-me %.2e %.2e %.2e\t# mist extinction coefficient\n", |
368 |
|
|
colval(cextinction,RED), |
369 |
|
|
colval(cextinction,GRN), |
370 |
|
|
colval(cextinction,BLU)); |
371 |
|
|
printf("-ma %f %f %f\t# mist scattering albedo\n", colval(salbedo,RED), |
372 |
|
|
colval(salbedo,GRN), colval(salbedo,BLU)); |
373 |
|
|
printf("-mg %f\t\t\t# mist scattering eccentricity\n", seccg); |
374 |
|
|
printf("-ms %f\t\t\t# mist sampling distance\n", ssampdist); |
375 |
greg |
2.23 |
if (NCSAMP > 3) { |
376 |
|
|
printf("-cs %-2d\t\t\t\t# number of spectral bins\n", NCSAMP); |
377 |
|
|
printf("-cw %3.0f %3.0f\t\t\t# wavelength limits (nm)\n", |
378 |
|
|
WLPART[3], WLPART[0]); |
379 |
|
|
} |
380 |
greg |
2.8 |
printf("-lr %-9d\t\t\t# limit reflection%s\n", maxdepth, |
381 |
|
|
maxdepth<=0 ? " (Russian roulette)" : ""); |
382 |
greg |
2.13 |
printf("-lw %.2e\t\t\t# limit weight\n", minweight); |
383 |
greg |
2.16 |
|
384 |
|
|
/* PMAP: output photon map defaults */ |
385 |
|
|
printPmapDefaults(); |
386 |
greg |
2.1 |
} |