1 |
– |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Mist volumetric material. |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "ray.h" |
11 |
|
|
12 |
|
#include "source.h" |
32 |
|
* |
33 |
|
* Up to five real arguments may be given for MAT_MIST: |
34 |
|
* |
35 |
< |
* [ext_r ext_g ext_b [albedo [gecc]]] |
35 |
> |
* [ext_r ext_g ext_b [albedo_r albedo_g albedo_b [gecc]]] |
36 |
|
* |
37 |
|
* The primaries indicate medium extinction per unit length (absorption |
38 |
< |
* plus scattering). The albedo is the ratio of scattering to extinction, |
38 |
> |
* plus scattering), which is added to the global extinction coefficient, set |
39 |
> |
* by the -me option. The albedo is the ratio of scattering to extinction, |
40 |
|
* and is set globally by the -ma option (salbedo) and overridden here. |
41 |
|
* The Heyney-Greenstein eccentricity parameter (-mg seccg) indicates how much |
42 |
|
* scattering favors the forward direction. A value of 0 means isotropic |
43 |
|
* scattering. A value approaching 1 indicates strong forward scattering. |
44 |
|
*/ |
45 |
|
|
46 |
+ |
#ifndef MAXSLIST |
47 |
+ |
#define MAXSLIST 32 /* maximum sources to check */ |
48 |
+ |
#endif |
49 |
+ |
|
50 |
|
#define RELAYDELIM '>' /* relay delimiter character */ |
51 |
|
|
48 |
– |
extern COLOR cextinction; /* global coefficient of extinction */ |
49 |
– |
extern double salbedo; /* global scattering albedo */ |
50 |
– |
extern double seccg; /* global scattering eccentricity */ |
52 |
|
|
52 |
– |
|
53 |
|
static int |
54 |
|
inslist(sl, n) /* return index of source n if it's in list sl */ |
55 |
|
register int *sl; |
69 |
|
register SRCREC *sp; |
70 |
|
register char *id; |
71 |
|
{ |
72 |
– |
extern char *index(); |
72 |
|
register char *cp; |
73 |
|
/* check for relay sources */ |
74 |
|
while ((cp = index(id, RELAYDELIM)) != NULL) { |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
< |
static |
88 |
> |
static void |
89 |
|
add2slist(r, sl) /* add source list to ray's */ |
90 |
|
register RAY *r; |
91 |
|
register int *sl; |
100 |
|
for (i = sl[0]; i > 0; i--) |
101 |
|
if (!inslist(r->slights, sl[i])) { |
102 |
|
if (r->slights[0] >= MAXSLIST) |
103 |
< |
error(USER, "scattering source list overflow"); |
103 |
> |
error(INTERNAL, |
104 |
> |
"scattering source list overflow"); |
105 |
|
r->slights[++r->slights[0]] = sl[i]; |
106 |
|
} |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
+ |
int |
111 |
|
m_mist(m, r) /* process a ray entering or leaving some mist */ |
112 |
|
OBJREC *m; |
113 |
|
register RAY *r; |
119 |
|
double re, ge, be; |
120 |
|
register int i, j; |
121 |
|
/* check arguments */ |
122 |
< |
if (m->oargs.nfargs > 5) |
122 |
> |
if (m->oargs.nfargs > 7) |
123 |
|
objerror(m, USER, "bad arguments"); |
124 |
|
/* get source indices */ |
125 |
|
if (m->oargs.nsargs > 0 && (myslist = (int *)m->os) == NULL) { |
126 |
|
if (m->oargs.nsargs > MAXSLIST) |
127 |
< |
objerror(m, USER, "too many sources in list"); |
127 |
> |
objerror(m, INTERNAL, "too many sources in list"); |
128 |
|
myslist = (int *)malloc((m->oargs.nsargs+1)*sizeof(int)); |
129 |
|
if (myslist == NULL) |
130 |
|
goto memerr; |
166 |
|
p.slights[0] = 0; |
167 |
|
if (r->rod > 0.) { /* entering ray */ |
168 |
|
addcolor(p.cext, mext); |
169 |
< |
if (m->oargs.nfargs > 3) |
170 |
< |
p.albedo = m->oargs.farg[3]; |
171 |
< |
if (m->oargs.nfargs > 4) |
172 |
< |
p.gecc = m->oargs.farg[4]; |
169 |
> |
if (m->oargs.nfargs > 5) |
170 |
> |
setcolor(p.albedo, m->oargs.farg[3], |
171 |
> |
m->oargs.farg[4], m->oargs.farg[5]); |
172 |
> |
if (m->oargs.nfargs > 6) |
173 |
> |
p.gecc = m->oargs.farg[6]; |
174 |
|
add2slist(&p, myslist); /* add to list */ |
175 |
|
} else { /* leaving ray */ |
176 |
|
if (myslist != NULL) { /* delete from list */ |
182 |
|
p.slights[++i] = p.slights[j]; |
183 |
|
if (p.slights[0] - i < myslist[0]) { /* fix old */ |
184 |
|
addcolor(r->cext, mext); |
185 |
< |
if (m->oargs.nfargs > 3) |
186 |
< |
r->albedo = m->oargs.farg[3]; |
187 |
< |
if (m->oargs.nfargs > 4) |
188 |
< |
r->gecc = m->oargs.farg[4]; |
185 |
> |
if (m->oargs.nfargs > 5) |
186 |
> |
setcolor(r->albedo, m->oargs.farg[3], |
187 |
> |
m->oargs.farg[4], m->oargs.farg[5]); |
188 |
> |
if (m->oargs.nfargs > 6) |
189 |
> |
r->gecc = m->oargs.farg[6]; |
190 |
|
add2slist(r, myslist); |
191 |
|
} |
192 |
|
p.slights[0] = i; |
193 |
|
} |
194 |
< |
re = colval(r->cext,RED) - colval(mext,RED); |
195 |
< |
ge = colval(r->cext,GRN) - colval(mext,GRN); |
196 |
< |
be = colval(r->cext,BLU) - colval(mext,BLU); |
197 |
< |
setcolor(p.cext, re<0. ? 0. : re, |
198 |
< |
ge<0. ? 0. : ge, |
199 |
< |
be<0. ? 0. : be); |
200 |
< |
if (m->oargs.nfargs > 3) |
201 |
< |
p.albedo = salbedo; |
202 |
< |
if (m->oargs.nfargs > 4) |
194 |
> |
if ((re = colval(r->cext,RED) - colval(mext,RED)) < |
195 |
> |
colval(cextinction,RED)) |
196 |
> |
re = colval(cextinction,RED); |
197 |
> |
if ((ge = colval(r->cext,GRN) - colval(mext,GRN)) < |
198 |
> |
colval(cextinction,GRN)) |
199 |
> |
ge = colval(cextinction,GRN); |
200 |
> |
if ((be = colval(r->cext,BLU) - colval(mext,BLU)) < |
201 |
> |
colval(cextinction,BLU)) |
202 |
> |
be = colval(cextinction,BLU); |
203 |
> |
setcolor(p.cext, re, ge, be); |
204 |
> |
if (m->oargs.nfargs > 5) |
205 |
> |
copycolor(p.albedo, salbedo); |
206 |
> |
if (m->oargs.nfargs > 6) |
207 |
|
p.gecc = seccg; |
208 |
|
} |
209 |
|
rayvalue(&p); /* calls rayparticipate() */ |