| 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; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
|
| 89 |
< |
static |
| 89 |
> |
static void |
| 90 |
|
add2slist(r, sl) /* add source list to ray's */ |
| 91 |
|
register RAY *r; |
| 92 |
|
register int *sl; |
| 101 |
|
for (i = sl[0]; i > 0; i--) |
| 102 |
|
if (!inslist(r->slights, sl[i])) { |
| 103 |
|
if (r->slights[0] >= MAXSLIST) |
| 104 |
< |
error(USER, "scattering source list overflow"); |
| 104 |
> |
error(INTERNAL, |
| 105 |
> |
"scattering source list overflow"); |
| 106 |
|
r->slights[++r->slights[0]] = sl[i]; |
| 107 |
|
} |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
|
| 111 |
+ |
int |
| 112 |
|
m_mist(m, r) /* process a ray entering or leaving some mist */ |
| 113 |
|
OBJREC *m; |
| 114 |
|
register RAY *r; |
| 120 |
|
double re, ge, be; |
| 121 |
|
register int i, j; |
| 122 |
|
/* check arguments */ |
| 123 |
< |
if (m->oargs.nfargs > 5) |
| 123 |
> |
if (m->oargs.nfargs > 7) |
| 124 |
|
objerror(m, USER, "bad arguments"); |
| 125 |
|
/* get source indices */ |
| 126 |
|
if (m->oargs.nsargs > 0 && (myslist = (int *)m->os) == NULL) { |
| 127 |
|
if (m->oargs.nsargs > MAXSLIST) |
| 128 |
< |
objerror(m, USER, "too many sources in list"); |
| 128 |
> |
objerror(m, INTERNAL, "too many sources in list"); |
| 129 |
|
myslist = (int *)malloc((m->oargs.nsargs+1)*sizeof(int)); |
| 130 |
|
if (myslist == NULL) |
| 131 |
|
goto memerr; |
| 167 |
|
p.slights[0] = 0; |
| 168 |
|
if (r->rod > 0.) { /* entering ray */ |
| 169 |
|
addcolor(p.cext, mext); |
| 170 |
< |
if (m->oargs.nfargs > 3) |
| 171 |
< |
p.albedo = m->oargs.farg[3]; |
| 172 |
< |
if (m->oargs.nfargs > 4) |
| 173 |
< |
p.gecc = m->oargs.farg[4]; |
| 170 |
> |
if (m->oargs.nfargs > 5) |
| 171 |
> |
setcolor(p.albedo, m->oargs.farg[3], |
| 172 |
> |
m->oargs.farg[4], m->oargs.farg[5]); |
| 173 |
> |
if (m->oargs.nfargs > 6) |
| 174 |
> |
p.gecc = m->oargs.farg[6]; |
| 175 |
|
add2slist(&p, myslist); /* add to list */ |
| 176 |
|
} else { /* leaving ray */ |
| 177 |
|
if (myslist != NULL) { /* delete from list */ |
| 183 |
|
p.slights[++i] = p.slights[j]; |
| 184 |
|
if (p.slights[0] - i < myslist[0]) { /* fix old */ |
| 185 |
|
addcolor(r->cext, mext); |
| 186 |
< |
if (m->oargs.nfargs > 3) |
| 187 |
< |
r->albedo = m->oargs.farg[3]; |
| 188 |
< |
if (m->oargs.nfargs > 4) |
| 189 |
< |
r->gecc = m->oargs.farg[4]; |
| 186 |
> |
if (m->oargs.nfargs > 5) |
| 187 |
> |
setcolor(r->albedo, m->oargs.farg[3], |
| 188 |
> |
m->oargs.farg[4], m->oargs.farg[5]); |
| 189 |
> |
if (m->oargs.nfargs > 6) |
| 190 |
> |
r->gecc = m->oargs.farg[6]; |
| 191 |
|
add2slist(r, myslist); |
| 192 |
|
} |
| 193 |
|
p.slights[0] = i; |
| 194 |
|
} |
| 195 |
< |
re = colval(r->cext,RED) - colval(mext,RED); |
| 196 |
< |
ge = colval(r->cext,GRN) - colval(mext,GRN); |
| 197 |
< |
be = colval(r->cext,BLU) - colval(mext,BLU); |
| 198 |
< |
setcolor(p.cext, re<0. ? 0. : re, |
| 199 |
< |
ge<0. ? 0. : ge, |
| 200 |
< |
be<0. ? 0. : be); |
| 201 |
< |
if (m->oargs.nfargs > 3) |
| 202 |
< |
p.albedo = salbedo; |
| 203 |
< |
if (m->oargs.nfargs > 4) |
| 195 |
> |
if ((re = colval(r->cext,RED) - colval(mext,RED)) < |
| 196 |
> |
colval(cextinction,RED)) |
| 197 |
> |
re = colval(cextinction,RED); |
| 198 |
> |
if ((ge = colval(r->cext,GRN) - colval(mext,GRN)) < |
| 199 |
> |
colval(cextinction,GRN)) |
| 200 |
> |
ge = colval(cextinction,GRN); |
| 201 |
> |
if ((be = colval(r->cext,BLU) - colval(mext,BLU)) < |
| 202 |
> |
colval(cextinction,BLU)) |
| 203 |
> |
be = colval(cextinction,BLU); |
| 204 |
> |
setcolor(p.cext, re, ge, be); |
| 205 |
> |
if (m->oargs.nfargs > 5) |
| 206 |
> |
copycolor(p.albedo, salbedo); |
| 207 |
> |
if (m->oargs.nfargs > 6) |
| 208 |
|
p.gecc = seccg; |
| 209 |
|
} |
| 210 |
|
rayvalue(&p); /* calls rayparticipate() */ |