ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/renderopts.c
Revision: 2.20
Committed: Wed Oct 19 23:10:34 2022 UTC (19 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.19: +5 -5 lines
Log Message:
fix(rcontrib): removed AdaptiveShadowTesting from feature list (didn't belong)

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: renderopts.c,v 2.19 2022/10/19 21:25:20 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 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 "ParticipatingMedia=Mist\nScatteringModels=WGMD,Ashikhmin-Shirley\n"
24 "TabulatedBSDFs=DataFile,KlemsXML,TensorTreeXML,+ViewPeakExtraction\n"
25 "Instancing=Octree,TriangleMesh\nAliases\n"
26 #if !defined(SHADCACHE) || SHADCACHE > 0
27 "ShadowCache\n"
28 #endif
29 #ifdef DISPERSE
30 "DielectricDispersion\n"
31 #endif
32 /* PMAP_FEATURES XXX @Roland: need to define this in pmapopt.h */
33 ;
34
35
36 static char *
37 get_feature( /* find a specific feature (with optional sublist) */
38 const char *feat
39 )
40 {
41 char *cp = RFeatureList;
42 int n = 0;
43
44 while ((feat[n] != '\0') & (feat[n] != '='))
45 n++;
46 if (!n)
47 return(NULL);
48 while (*cp) {
49 if (!strncmp(cp, feat, n) && (cp[n] == '\n') | !feat[n] | (cp[n] == feat[n]))
50 return(cp);
51 while (*cp++ != '\n')
52 ;
53 }
54 return(NULL);
55 }
56
57
58 static int
59 match_subfeatures( /* check if subfeatures are supported */
60 char *mysublist,
61 char *reqs
62 )
63 {
64 if (mysublist)
65 mysublist = strchr(mysublist, '=');
66 if (!mysublist++ | !reqs)
67 return(0); /* not a feature list */
68 while (*reqs) { /* check each of their subfeature requests */
69 char subfeat[64];
70 char *cp = subfeat;
71 int n;
72 while (*reqs && (*cp = *reqs++) != ',')
73 cp++;
74 *cp = '\0';
75 n = cp - subfeat;
76 if (!(cp = strstr(mysublist, subfeat)) ||
77 (cp[n] != ',') & (cp[n] != '\n'))
78 return(0); /* missing this one! */
79 }
80 return(1); /* matched them all */
81 }
82
83
84 int
85 feature_status( /* report active feature list / check specifics */
86 int ac,
87 char *av[]
88 )
89 {
90 if (ac <= 0) /* report entire list? */
91 fputs(RFeatureList, stdout);
92
93 for ( ; ac-- > 0; av++) { /* check each argument */
94 char *cp;
95 if (!*av[0]) continue;
96 if ((cp = strchr(av[0], '=')) != NULL) {
97 if (!match_subfeatures(get_feature(av[0]), cp+1))
98 goto missing_feature;
99 } else if ((cp = get_feature(av[0])) != NULL) {
100 char *tp = strchr(cp, '=');
101 if (tp && tp < strchr(cp, '\n'))
102 do
103 fputc(*cp, stdout);
104 while (*cp++ != '\n');
105 } else
106 goto missing_feature;
107 }
108 return(0); /* return satisfactory status */
109 missing_feature: /* or report error */
110 fprintf(stderr, "%s: missing feature - %s\n", progname, av[0]);
111 return(1);
112 }
113
114
115 int
116 getrenderopt( /* get next render option */
117 int ac,
118 char *av[]
119 )
120 {
121 #define check(ol,al) if (av[0][ol] || \
122 badarg(ac-1,av+1,al)) \
123 return(-1)
124 #define check_bool(olen,var) switch (av[0][olen]) { \
125 case '\0': var = !var; break; \
126 case 'y': case 'Y': case 't': case 'T': \
127 case '+': case '1': var = 1; break; \
128 case 'n': case 'N': case 'f': case 'F': \
129 case '-': case '0': var = 0; break; \
130 default: return(-1); }
131 static char **amblp; /* pointer to build ambient list */
132 int rval;
133 /* is it even an option? */
134 if (ac < 1 || av[0] == NULL || av[0][0] != '-')
135 return(-1);
136 /* check if it's one we know */
137 switch (av[0][1]) {
138 case 'u': /* uncorrelated sampling */
139 check_bool(2,rand_samp);
140 return(0);
141 case 'b': /* back face vis. */
142 if (av[0][2] == 'v') {
143 check_bool(3,backvis);
144 return(0);
145 }
146 break;
147 case 'd': /* direct */
148 switch (av[0][2]) {
149 case 't': /* threshold */
150 check(3,"f");
151 shadthresh = atof(av[1]);
152 return(1);
153 case 'c': /* certainty */
154 check(3,"f");
155 shadcert = atof(av[1]);
156 return(1);
157 case 'j': /* jitter */
158 check(3,"f");
159 dstrsrc = atof(av[1]);
160 return(1);
161 case 'r': /* relays */
162 check(3,"i");
163 directrelay = atoi(av[1]);
164 return(1);
165 case 'p': /* pretest */
166 check(3,"i");
167 vspretest = atoi(av[1]);
168 return(1);
169 case 'v': /* visibility */
170 check_bool(3,directvis);
171 return(0);
172 case 's': /* size */
173 check(3,"f");
174 srcsizerat = atof(av[1]);
175 return(1);
176 }
177 break;
178 case 's': /* specular */
179 switch (av[0][2]) {
180 case 't': /* threshold */
181 check(3,"f");
182 specthresh = atof(av[1]);
183 return(1);
184 case 's': /* sampling */
185 check(3,"f");
186 specjitter = atof(av[1]);
187 return(1);
188 }
189 break;
190 case 'l': /* limit */
191 switch (av[0][2]) {
192 case 'r': /* recursion */
193 check(3,"i");
194 maxdepth = atoi(av[1]);
195 return(1);
196 case 'w': /* weight */
197 check(3,"f");
198 minweight = atof(av[1]);
199 return(1);
200 }
201 break;
202 case 'i': /* irradiance */
203 check_bool(2,do_irrad);
204 return(0);
205 case 'a': /* ambient */
206 switch (av[0][2]) {
207 case 'v': /* value */
208 check(3,"fff");
209 setcolor(ambval, atof(av[1]),
210 atof(av[2]),
211 atof(av[3]));
212 return(3);
213 case 'w': /* weight */
214 check(3,"i");
215 ambvwt = atoi(av[1]);
216 return(1);
217 case 'a': /* accuracy */
218 check(3,"f");
219 ambacc = atof(av[1]);
220 return(1);
221 case 'r': /* resolution */
222 check(3,"i");
223 ambres = atoi(av[1]);
224 return(1);
225 case 'd': /* divisions */
226 check(3,"i");
227 ambdiv = atoi(av[1]);
228 return(1);
229 case 's': /* super-samp */
230 check(3,"i");
231 ambssamp = atoi(av[1]);
232 return(1);
233 case 'b': /* bounces */
234 check(3,"i");
235 ambounce = atoi(av[1]);
236 return(1);
237 case 'i': /* include */
238 case 'I':
239 check(3,"s");
240 if (ambincl != 1) {
241 ambincl = 1;
242 amblp = amblist;
243 }
244 if (av[0][2] == 'I') { /* file */
245 rval = wordfile(amblp, AMBLLEN-(amblp-amblist),
246 getpath(av[1],getrlibpath(),R_OK));
247 if (rval < 0) {
248 sprintf(errmsg,
249 "cannot open ambient include file \"%s\"", av[1]);
250 error(SYSTEM, errmsg);
251 }
252 amblp += rval;
253 } else {
254 *amblp++ = savqstr(av[1]);
255 *amblp = NULL;
256 }
257 return(1);
258 case 'e': /* exclude */
259 case 'E':
260 check(3,"s");
261 if (ambincl != 0) {
262 ambincl = 0;
263 amblp = amblist;
264 }
265 if (av[0][2] == 'E') { /* file */
266 rval = wordfile(amblp, AMBLLEN-(amblp-amblist),
267 getpath(av[1],getrlibpath(),R_OK));
268 if (rval < 0) {
269 sprintf(errmsg,
270 "cannot open ambient exclude file \"%s\"", av[1]);
271 error(SYSTEM, errmsg);
272 }
273 amblp += rval;
274 } else {
275 *amblp++ = savqstr(av[1]);
276 *amblp = NULL;
277 }
278 return(1);
279 case 'f': /* file */
280 check(3,"s");
281 ambfile = savqstr(av[1]);
282 return(1);
283 }
284 break;
285 case 'm': /* medium */
286 switch (av[0][2]) {
287 case 'e': /* extinction */
288 check(3,"fff");
289 setcolor(cextinction, atof(av[1]),
290 atof(av[2]),
291 atof(av[3]));
292 return(3);
293 case 'a': /* albedo */
294 check(3,"fff");
295 setcolor(salbedo, atof(av[1]),
296 atof(av[2]),
297 atof(av[3]));
298 return(3);
299 case 'g': /* eccentr. */
300 check(3,"f");
301 seccg = atof(av[1]);
302 return(1);
303 case 's': /* sampling */
304 check(3,"f");
305 ssampdist = atof(av[1]);
306 return(1);
307 }
308 break;
309 }
310
311 /* PMAP: Parse photon mapping options */
312 return(getPmapRenderOpt(ac, av));
313
314 /* return(-1); */ /* unknown option */
315
316 #undef check
317 #undef check_bool
318 }
319
320
321 void
322 print_rdefaults(void) /* print default render values to stdout */
323 {
324 printf(do_irrad ? "-i+\t\t\t\t# irradiance calculation on\n" :
325 "-i-\t\t\t\t# irradiance calculation off\n");
326 printf(rand_samp ? "-u+\t\t\t\t# uncorrelated Monte Carlo sampling\n" :
327 "-u-\t\t\t\t# correlated quasi-Monte Carlo sampling\n");
328 printf(backvis ? "-bv+\t\t\t\t# back face visibility on\n" :
329 "-bv-\t\t\t\t# back face visibility off\n");
330 printf("-dt %f\t\t\t# direct threshold\n", shadthresh);
331 printf("-dc %f\t\t\t# direct certainty\n", shadcert);
332 printf("-dj %f\t\t\t# direct jitter\n", dstrsrc);
333 printf("-ds %f\t\t\t# direct sampling\n", srcsizerat);
334 printf("-dr %-9d\t\t\t# direct relays\n", directrelay);
335 printf("-dp %-9d\t\t\t# direct pretest density\n", vspretest);
336 printf(directvis ? "-dv+\t\t\t\t# direct visibility on\n" :
337 "-dv-\t\t\t\t# direct visibility off\n");
338 printf("-ss %f\t\t\t# specular sampling\n", specjitter);
339 printf("-st %f\t\t\t# specular threshold\n", specthresh);
340 printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED),
341 colval(ambval,GRN), colval(ambval, BLU));
342 printf("-aw %-9d\t\t\t# ambient value weight\n", ambvwt);
343 printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce);
344 printf("-aa %f\t\t\t# ambient accuracy\n", ambacc);
345 printf("-ar %-9d\t\t\t# ambient resolution\n", ambres);
346 printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv);
347 printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp);
348 printf("-me %.2e %.2e %.2e\t# mist extinction coefficient\n",
349 colval(cextinction,RED),
350 colval(cextinction,GRN),
351 colval(cextinction,BLU));
352 printf("-ma %f %f %f\t# mist scattering albedo\n", colval(salbedo,RED),
353 colval(salbedo,GRN), colval(salbedo,BLU));
354 printf("-mg %f\t\t\t# mist scattering eccentricity\n", seccg);
355 printf("-ms %f\t\t\t# mist sampling distance\n", ssampdist);
356 printf("-lr %-9d\t\t\t# limit reflection%s\n", maxdepth,
357 maxdepth<=0 ? " (Russian roulette)" : "");
358 printf("-lw %.2e\t\t\t# limit weight\n", minweight);
359
360 /* PMAP: output photon map defaults */
361 printPmapDefaults();
362 }