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