33 |
|
* |
34 |
|
* Up to five real arguments may be given for MAT_MIST: |
35 |
|
* |
36 |
< |
* [ext_r ext_g ext_b [albedo [gecc]]] |
36 |
> |
* [ext_r ext_g ext_b [albedo_r albedo_g albedo_b [gecc]]] |
37 |
|
* |
38 |
|
* The primaries indicate medium extinction per unit length (absorption |
39 |
< |
* plus scattering). The albedo is the ratio of scattering to extinction, |
39 |
> |
* plus scattering), which is added to the global extinction coefficient, set |
40 |
> |
* by the -me option. The albedo is the ratio of scattering to extinction, |
41 |
|
* and is set globally by the -ma option (salbedo) and overridden here. |
42 |
|
* The Heyney-Greenstein eccentricity parameter (-mg seccg) indicates how much |
43 |
|
* scattering favors the forward direction. A value of 0 means isotropic |
44 |
|
* scattering. A value approaching 1 indicates strong forward scattering. |
45 |
|
*/ |
46 |
|
|
47 |
< |
#define MAXSLIST 32 /* maximum sources to check */ |
47 |
> |
#ifndef MAXSLIST |
48 |
> |
#define MAXSLIST 32 /* maximum sources to check */ |
49 |
> |
#endif |
50 |
> |
|
51 |
|
#define RELAYDELIM '>' /* relay delimiter character */ |
52 |
|
|
53 |
|
extern COLOR cextinction; /* global coefficient of extinction */ |
54 |
< |
extern double salbedo; /* global scattering albedo */ |
54 |
> |
extern COLOR salbedo; /* global scattering albedo */ |
55 |
|
extern double seccg; /* global scattering eccentricity */ |
56 |
|
|
57 |
|
|
70 |
|
|
71 |
|
|
72 |
|
static int |
73 |
< |
srcmatch(sn, id) /* check for an id match on a light source */ |
74 |
< |
register int sn; |
75 |
< |
char *id; |
73 |
> |
srcmatch(sp, id) /* check for an id match on a light source */ |
74 |
> |
register SRCREC *sp; |
75 |
> |
register char *id; |
76 |
|
{ |
77 |
|
extern char *index(); |
78 |
|
register char *cp; |
79 |
< |
again: |
80 |
< |
if (source[sn].so == NULL) /* just in case */ |
81 |
< |
return(0); |
78 |
< |
if ((cp = index(id, RELAYDELIM)) != NULL) { /* relay source */ |
79 |
< |
if (!(source[sn].sflags & SVIRTUAL)) |
79 |
> |
/* check for relay sources */ |
80 |
> |
while ((cp = index(id, RELAYDELIM)) != NULL) { |
81 |
> |
if (!(sp->sflags & SVIRTUAL) || sp->so == NULL) |
82 |
|
return(0); |
83 |
< |
*cp = '\0'; |
82 |
< |
if (strcmp(id, source[sn].so->oname)) { |
83 |
< |
*cp = RELAYDELIM; |
83 |
> |
if (strncmp(id, sp->so->oname, cp-id) || sp->so->oname[cp-id]) |
84 |
|
return(0); |
85 |
< |
} |
86 |
< |
*cp = RELAYDELIM; |
87 |
< |
id = cp + 1; /* recurse */ |
88 |
< |
sn = source[sn].sa.sv.sn; |
89 |
< |
goto again; |
85 |
> |
id = cp + 1; /* relay to next */ |
86 |
> |
sp = source + sp->sa.sv.sn; |
87 |
|
} |
88 |
< |
if (source[sn].sflags & SVIRTUAL) |
88 |
> |
if (sp->sflags & SVIRTUAL || sp->so == NULL) |
89 |
|
return(0); |
90 |
< |
return(!strcmp(id, source[sn].so->oname)); |
90 |
> |
return(!strcmp(id, sp->so->oname)); |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
+ |
static |
95 |
+ |
add2slist(r, sl) /* add source list to ray's */ |
96 |
+ |
register RAY *r; |
97 |
+ |
register int *sl; |
98 |
+ |
{ |
99 |
+ |
static int slspare[MAXSLIST+1]; /* in case of emergence */ |
100 |
+ |
register int i; |
101 |
+ |
|
102 |
+ |
if (sl == NULL || sl[0] == 0) /* nothing to add */ |
103 |
+ |
return; |
104 |
+ |
if (r->slights == NULL) |
105 |
+ |
(r->slights = slspare)[0] = 0; /* just once per ray path */ |
106 |
+ |
for (i = sl[0]; i > 0; i--) |
107 |
+ |
if (!inslist(r->slights, sl[i])) { |
108 |
+ |
if (r->slights[0] >= MAXSLIST) |
109 |
+ |
error(USER, "scattering source list overflow"); |
110 |
+ |
r->slights[++r->slights[0]] = sl[i]; |
111 |
+ |
} |
112 |
+ |
} |
113 |
+ |
|
114 |
+ |
|
115 |
|
m_mist(m, r) /* process a ray entering or leaving some mist */ |
116 |
|
OBJREC *m; |
117 |
|
register RAY *r; |
125 |
|
/* check arguments */ |
126 |
|
if (m->oargs.nfargs > 5) |
127 |
|
objerror(m, USER, "bad arguments"); |
110 |
– |
if (m->oargs.nsargs > MAXSLIST) |
111 |
– |
objerror(m, USER, "too many sources in list"); |
128 |
|
/* get source indices */ |
129 |
|
if (m->oargs.nsargs > 0 && (myslist = (int *)m->os) == NULL) { |
130 |
+ |
if (m->oargs.nsargs > MAXSLIST) |
131 |
+ |
objerror(m, USER, "too many sources in list"); |
132 |
|
myslist = (int *)malloc((m->oargs.nsargs+1)*sizeof(int)); |
133 |
|
if (myslist == NULL) |
134 |
|
goto memerr; |
135 |
< |
myslist[0] = m->oargs.nsargs; /* size is first in set */ |
136 |
< |
for (j = myslist[0]; j > 0; j--) { |
135 |
> |
myslist[0] = 0; /* size is first in list */ |
136 |
> |
for (j = 0; j < m->oargs.nsargs; j++) { |
137 |
|
i = nsources; /* look up each source id */ |
138 |
|
while (i--) |
139 |
< |
if (srcmatch(i, m->oargs.sarg[j-1])) |
139 |
> |
if (srcmatch(source+i, m->oargs.sarg[j])) |
140 |
|
break; |
141 |
|
if (i < 0) { |
142 |
|
sprintf(errmsg, "unknown source \"%s\"", |
143 |
< |
m->oargs.sarg[j-1]); |
143 |
> |
m->oargs.sarg[j]); |
144 |
|
objerror(m, WARNING, errmsg); |
145 |
+ |
} else if (inslist(myslist, i)) { |
146 |
+ |
sprintf(errmsg, "duplicate source \"%s\"", |
147 |
+ |
m->oargs.sarg[j]); |
148 |
+ |
objerror(m, WARNING, errmsg); |
149 |
|
} else |
150 |
< |
myslist[j] = i; |
150 |
> |
myslist[++myslist[0]] = i; |
151 |
|
} |
152 |
|
m->os = (char *)myslist; |
153 |
|
} |
163 |
|
return(1); |
164 |
|
VCOPY(p.rdir, r->rdir); |
165 |
|
p.slights = newslist; |
166 |
< |
if (r->slights != NULL) |
166 |
> |
if (r->slights != NULL) /* copy old list if one */ |
167 |
|
for (j = r->slights[0]; j >= 0; j--) |
168 |
|
p.slights[j] = r->slights[j]; |
169 |
|
else |
170 |
|
p.slights[0] = 0; |
171 |
|
if (r->rod > 0.) { /* entering ray */ |
172 |
|
addcolor(p.cext, mext); |
173 |
< |
if (m->oargs.nfargs > 3) |
174 |
< |
p.albedo = m->oargs.farg[3]; |
175 |
< |
if (m->oargs.nfargs > 4) |
176 |
< |
p.gecc = m->oargs.farg[4]; |
177 |
< |
if (myslist != NULL) /* add to list */ |
178 |
< |
for (j = myslist[0]; j > 0; j--) |
157 |
< |
if (!inslist(p.slights, myslist[j])) { |
158 |
< |
if (p.slights[0] >= MAXSLIST) |
159 |
< |
error(USER, |
160 |
< |
"scattering source list overflow"); |
161 |
< |
p.slights[++p.slights[0]] = myslist[j]; |
162 |
< |
} |
173 |
> |
if (m->oargs.nfargs > 5) |
174 |
> |
setcolor(p.albedo, m->oargs.farg[3], |
175 |
> |
m->oargs.farg[4], m->oargs.farg[5]); |
176 |
> |
if (m->oargs.nfargs > 6) |
177 |
> |
p.gecc = m->oargs.farg[6]; |
178 |
> |
add2slist(&p, myslist); /* add to list */ |
179 |
|
} else { /* leaving ray */ |
164 |
– |
re = colval(r->cext,RED) - colval(mext,RED); |
165 |
– |
ge = colval(r->cext,GRN) - colval(mext,GRN); |
166 |
– |
be = colval(r->cext,BLU) - colval(mext,BLU); |
167 |
– |
setcolor(p.cext, re<0. ? 0. : re, |
168 |
– |
ge<0. ? 0. : ge, |
169 |
– |
be<0. ? 0. : be); |
170 |
– |
if (m->oargs.nfargs > 3) |
171 |
– |
p.albedo = salbedo; |
172 |
– |
if (m->oargs.nfargs > 4) |
173 |
– |
p.gecc = seccg; |
180 |
|
if (myslist != NULL) { /* delete from list */ |
181 |
|
for (j = myslist[0]; j > 0; j--) |
182 |
|
if (i = inslist(p.slights, myslist[j])) |
184 |
|
for (i = 0, j = 1; j <= p.slights[0]; j++) |
185 |
|
if (p.slights[j] != -1) |
186 |
|
p.slights[++i] = p.slights[j]; |
187 |
+ |
if (p.slights[0] - i < myslist[0]) { /* fix old */ |
188 |
+ |
addcolor(r->cext, mext); |
189 |
+ |
if (m->oargs.nfargs > 5) |
190 |
+ |
setcolor(r->albedo, m->oargs.farg[3], |
191 |
+ |
m->oargs.farg[4], m->oargs.farg[5]); |
192 |
+ |
if (m->oargs.nfargs > 6) |
193 |
+ |
r->gecc = m->oargs.farg[6]; |
194 |
+ |
add2slist(r, myslist); |
195 |
+ |
} |
196 |
|
p.slights[0] = i; |
197 |
|
} |
198 |
+ |
if ((re = colval(r->cext,RED) - colval(mext,RED)) < |
199 |
+ |
colval(cextinction,RED)) |
200 |
+ |
re = colval(cextinction,RED); |
201 |
+ |
if ((ge = colval(r->cext,GRN) - colval(mext,GRN)) < |
202 |
+ |
colval(cextinction,GRN)) |
203 |
+ |
ge = colval(cextinction,GRN); |
204 |
+ |
if ((be = colval(r->cext,BLU) - colval(mext,BLU)) < |
205 |
+ |
colval(cextinction,BLU)) |
206 |
+ |
be = colval(cextinction,BLU); |
207 |
+ |
setcolor(p.cext, re, ge, be); |
208 |
+ |
if (m->oargs.nfargs > 5) |
209 |
+ |
copycolor(p.albedo, salbedo); |
210 |
+ |
if (m->oargs.nfargs > 6) |
211 |
+ |
p.gecc = seccg; |
212 |
|
} |
213 |
|
rayvalue(&p); /* calls rayparticipate() */ |
214 |
|
copycolor(r->rcol, p.rcol); /* return value */ |