1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: renderopts.c,v 2.16 2015/02/24 19:39:27 greg Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* renderopts.c - process common rendering options |
6 |
* |
7 |
* External symbols declared in ray.h |
8 |
*/ |
9 |
|
10 |
#include "copyright.h" |
11 |
|
12 |
#include "ray.h" |
13 |
#include "paths.h" |
14 |
#include "pmapopt.h" |
15 |
|
16 |
|
17 |
int |
18 |
getrenderopt( /* get next render option */ |
19 |
int ac, |
20 |
char *av[] |
21 |
) |
22 |
{ |
23 |
#define check(ol,al) if (av[0][ol] || \ |
24 |
badarg(ac-1,av+1,al)) \ |
25 |
return(-1) |
26 |
#define check_bool(olen,var) switch (av[0][olen]) { \ |
27 |
case '\0': var = !var; break; \ |
28 |
case 'y': case 'Y': case 't': case 'T': \ |
29 |
case '+': case '1': var = 1; break; \ |
30 |
case 'n': case 'N': case 'f': case 'F': \ |
31 |
case '-': case '0': var = 0; break; \ |
32 |
default: return(-1); } |
33 |
static char **amblp; /* pointer to build ambient list */ |
34 |
int rval; |
35 |
/* is it even an option? */ |
36 |
if (ac < 1 || av[0] == NULL || av[0][0] != '-') |
37 |
return(-1); |
38 |
/* check if it's one we know */ |
39 |
switch (av[0][1]) { |
40 |
case 'u': /* uncorrelated sampling */ |
41 |
check_bool(2,rand_samp); |
42 |
return(0); |
43 |
case 'b': /* back face vis. */ |
44 |
if (av[0][2] == 'v') { |
45 |
check_bool(3,backvis); |
46 |
return(0); |
47 |
} |
48 |
break; |
49 |
case 'd': /* direct */ |
50 |
switch (av[0][2]) { |
51 |
case 't': /* threshold */ |
52 |
check(3,"f"); |
53 |
shadthresh = atof(av[1]); |
54 |
return(1); |
55 |
case 'c': /* certainty */ |
56 |
check(3,"f"); |
57 |
shadcert = atof(av[1]); |
58 |
return(1); |
59 |
case 'j': /* jitter */ |
60 |
check(3,"f"); |
61 |
dstrsrc = atof(av[1]); |
62 |
return(1); |
63 |
case 'r': /* relays */ |
64 |
check(3,"i"); |
65 |
directrelay = atoi(av[1]); |
66 |
return(1); |
67 |
case 'p': /* pretest */ |
68 |
check(3,"i"); |
69 |
vspretest = atoi(av[1]); |
70 |
return(1); |
71 |
case 'v': /* visibility */ |
72 |
check_bool(3,directvis); |
73 |
return(0); |
74 |
case 's': /* size */ |
75 |
check(3,"f"); |
76 |
srcsizerat = atof(av[1]); |
77 |
return(1); |
78 |
} |
79 |
break; |
80 |
case 's': /* specular */ |
81 |
switch (av[0][2]) { |
82 |
case 't': /* threshold */ |
83 |
check(3,"f"); |
84 |
specthresh = atof(av[1]); |
85 |
return(1); |
86 |
case 's': /* sampling */ |
87 |
check(3,"f"); |
88 |
specjitter = atof(av[1]); |
89 |
return(1); |
90 |
} |
91 |
break; |
92 |
case 'l': /* limit */ |
93 |
switch (av[0][2]) { |
94 |
case 'r': /* recursion */ |
95 |
check(3,"i"); |
96 |
maxdepth = atoi(av[1]); |
97 |
return(1); |
98 |
case 'w': /* weight */ |
99 |
check(3,"f"); |
100 |
minweight = atof(av[1]); |
101 |
return(1); |
102 |
} |
103 |
break; |
104 |
case 'i': /* irradiance */ |
105 |
check_bool(2,do_irrad); |
106 |
return(0); |
107 |
case 'a': /* ambient */ |
108 |
switch (av[0][2]) { |
109 |
case 'v': /* value */ |
110 |
check(3,"fff"); |
111 |
setcolor(ambval, atof(av[1]), |
112 |
atof(av[2]), |
113 |
atof(av[3])); |
114 |
return(3); |
115 |
case 'w': /* weight */ |
116 |
check(3,"i"); |
117 |
ambvwt = atoi(av[1]); |
118 |
return(1); |
119 |
case 'a': /* accuracy */ |
120 |
check(3,"f"); |
121 |
ambacc = atof(av[1]); |
122 |
return(1); |
123 |
case 'r': /* resolution */ |
124 |
check(3,"i"); |
125 |
ambres = atoi(av[1]); |
126 |
return(1); |
127 |
case 'd': /* divisions */ |
128 |
check(3,"i"); |
129 |
ambdiv = atoi(av[1]); |
130 |
return(1); |
131 |
case 's': /* super-samp */ |
132 |
check(3,"i"); |
133 |
ambssamp = atoi(av[1]); |
134 |
return(1); |
135 |
case 'b': /* bounces */ |
136 |
check(3,"i"); |
137 |
ambounce = atoi(av[1]); |
138 |
return(1); |
139 |
case 'i': /* include */ |
140 |
case 'I': |
141 |
check(3,"s"); |
142 |
if (ambincl != 1) { |
143 |
ambincl = 1; |
144 |
amblp = amblist; |
145 |
} |
146 |
if (av[0][2] == 'I') { /* file */ |
147 |
rval = wordfile(amblp, |
148 |
getpath(av[1],getrlibpath(),R_OK)); |
149 |
if (rval < 0) { |
150 |
sprintf(errmsg, |
151 |
"cannot open ambient include file \"%s\"", av[1]); |
152 |
error(SYSTEM, errmsg); |
153 |
} |
154 |
amblp += rval; |
155 |
} else { |
156 |
*amblp++ = savqstr(av[1]); |
157 |
*amblp = NULL; |
158 |
} |
159 |
return(1); |
160 |
case 'e': /* exclude */ |
161 |
case 'E': |
162 |
check(3,"s"); |
163 |
if (ambincl != 0) { |
164 |
ambincl = 0; |
165 |
amblp = amblist; |
166 |
} |
167 |
if (av[0][2] == 'E') { /* file */ |
168 |
rval = wordfile(amblp, |
169 |
getpath(av[1],getrlibpath(),R_OK)); |
170 |
if (rval < 0) { |
171 |
sprintf(errmsg, |
172 |
"cannot open ambient exclude file \"%s\"", av[1]); |
173 |
error(SYSTEM, errmsg); |
174 |
} |
175 |
amblp += rval; |
176 |
} else { |
177 |
*amblp++ = savqstr(av[1]); |
178 |
*amblp = NULL; |
179 |
} |
180 |
return(1); |
181 |
case 'f': /* file */ |
182 |
check(3,"s"); |
183 |
ambfile = savqstr(av[1]); |
184 |
return(1); |
185 |
} |
186 |
break; |
187 |
case 'm': /* medium */ |
188 |
switch (av[0][2]) { |
189 |
case 'e': /* extinction */ |
190 |
check(3,"fff"); |
191 |
setcolor(cextinction, atof(av[1]), |
192 |
atof(av[2]), |
193 |
atof(av[3])); |
194 |
return(3); |
195 |
case 'a': /* albedo */ |
196 |
check(3,"fff"); |
197 |
setcolor(salbedo, atof(av[1]), |
198 |
atof(av[2]), |
199 |
atof(av[3])); |
200 |
return(3); |
201 |
case 'g': /* eccentr. */ |
202 |
check(3,"f"); |
203 |
seccg = atof(av[1]); |
204 |
return(1); |
205 |
case 's': /* sampling */ |
206 |
check(3,"f"); |
207 |
ssampdist = atof(av[1]); |
208 |
return(1); |
209 |
} |
210 |
break; |
211 |
} |
212 |
|
213 |
/* PMAP: Parse photon mapping options */ |
214 |
return(getPmapRenderOpt(ac, av)); |
215 |
|
216 |
/* return(-1); */ /* unknown option */ |
217 |
|
218 |
#undef check |
219 |
#undef check_bool |
220 |
} |
221 |
|
222 |
|
223 |
void |
224 |
print_rdefaults(void) /* print default render values to stdout */ |
225 |
{ |
226 |
printf(do_irrad ? "-i+\t\t\t\t# irradiance calculation on\n" : |
227 |
"-i-\t\t\t\t# irradiance calculation off\n"); |
228 |
printf(rand_samp ? "-u+\t\t\t\t# uncorrelated Monte Carlo sampling\n" : |
229 |
"-u-\t\t\t\t# correlated quasi-Monte Carlo sampling\n"); |
230 |
printf(backvis ? "-bv+\t\t\t\t# back face visibility on\n" : |
231 |
"-bv-\t\t\t\t# back face visibility off\n"); |
232 |
printf("-dt %f\t\t\t# direct threshold\n", shadthresh); |
233 |
printf("-dc %f\t\t\t# direct certainty\n", shadcert); |
234 |
printf("-dj %f\t\t\t# direct jitter\n", dstrsrc); |
235 |
printf("-ds %f\t\t\t# direct sampling\n", srcsizerat); |
236 |
printf("-dr %-9d\t\t\t# direct relays\n", directrelay); |
237 |
printf("-dp %-9d\t\t\t# direct pretest density\n", vspretest); |
238 |
printf(directvis ? "-dv+\t\t\t\t# direct visibility on\n" : |
239 |
"-dv-\t\t\t\t# direct visibility off\n"); |
240 |
printf("-ss %f\t\t\t# specular sampling\n", specjitter); |
241 |
printf("-st %f\t\t\t# specular threshold\n", specthresh); |
242 |
printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED), |
243 |
colval(ambval,GRN), colval(ambval, BLU)); |
244 |
printf("-aw %-9d\t\t\t# ambient value weight\n", ambvwt); |
245 |
printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce); |
246 |
printf("-aa %f\t\t\t# ambient accuracy\n", ambacc); |
247 |
printf("-ar %-9d\t\t\t# ambient resolution\n", ambres); |
248 |
printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv); |
249 |
printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp); |
250 |
printf("-me %.2e %.2e %.2e\t# mist extinction coefficient\n", |
251 |
colval(cextinction,RED), |
252 |
colval(cextinction,GRN), |
253 |
colval(cextinction,BLU)); |
254 |
printf("-ma %f %f %f\t# mist scattering albedo\n", colval(salbedo,RED), |
255 |
colval(salbedo,GRN), colval(salbedo,BLU)); |
256 |
printf("-mg %f\t\t\t# mist scattering eccentricity\n", seccg); |
257 |
printf("-ms %f\t\t\t# mist sampling distance\n", ssampdist); |
258 |
printf("-lr %-9d\t\t\t# limit reflection%s\n", maxdepth, |
259 |
maxdepth<=0 ? " (Russian roulette)" : ""); |
260 |
printf("-lw %.2e\t\t\t# limit weight\n", minweight); |
261 |
|
262 |
/* PMAP: output photon map defaults */ |
263 |
printPmapDefaults(); |
264 |
} |