ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_mist.c
(Generate patch)

Comparing ray/src/rt/m_mist.c (file contents):
Revision 2.1 by greg, Fri Dec 8 21:27:10 1995 UTC vs.
Revision 2.9 by gregl, Wed May 28 14:38:32 1997 UTC

# Line 33 | Line 33 | static char SCCSid[] = "$SunId$ LBL";
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  
# Line 66 | Line 70 | register int  n;
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(INTERNAL,
110 +                                        "scattering source list overflow");
111 +                        r->slights[++r->slights[0]] = sl[i];
112 +                }
113 + }
114 +
115 +
116   m_mist(m, r)            /* process a ray entering or leaving some mist */
117   OBJREC  *m;
118   register RAY  *r;
# Line 105 | Line 124 | register RAY  *r;
124          double  re, ge, be;
125          register int  i, j;
126                                          /* check arguments */
127 <        if (m->oargs.nfargs > 5)
127 >        if (m->oargs.nfargs > 7)
128                  objerror(m, USER, "bad arguments");
110        if (m->oargs.nsargs > MAXSLIST)
111                objerror(m, USER, "too many sources in list");
129                                          /* get source indices */
130          if (m->oargs.nsargs > 0 && (myslist = (int *)m->os) == NULL) {
131 +                if (m->oargs.nsargs > MAXSLIST)
132 +                        objerror(m, INTERNAL, "too many sources in list");
133                  myslist = (int *)malloc((m->oargs.nsargs+1)*sizeof(int));
134                  if (myslist == NULL)
135                          goto memerr;
136 <                myslist[0] = m->oargs.nsargs;   /* size is first in set */
137 <                for (j = myslist[0]; j > 0; j--) {
136 >                myslist[0] = 0;                 /* size is first in list */
137 >                for (j = 0; j < m->oargs.nsargs; j++) {
138                          i = nsources;           /* look up each source id */
139                          while (i--)
140 <                                if (srcmatch(i, m->oargs.sarg[j-1]))
140 >                                if (srcmatch(source+i, m->oargs.sarg[j]))
141                                          break;
142                          if (i < 0) {
143                                  sprintf(errmsg, "unknown source \"%s\"",
144 <                                                m->oargs.sarg[j-1]);
144 >                                                m->oargs.sarg[j]);
145                                  objerror(m, WARNING, errmsg);
146 +                        } else if (inslist(myslist, i)) {
147 +                                sprintf(errmsg, "duplicate source \"%s\"",
148 +                                                m->oargs.sarg[j]);
149 +                                objerror(m, WARNING, errmsg);
150                          } else
151 <                                myslist[j] = i;
151 >                                myslist[++myslist[0]] = i;
152                  }
153                  m->os = (char *)myslist;
154          }
# Line 141 | Line 164 | register RAY  *r;
164                  return(1);
165          VCOPY(p.rdir, r->rdir);
166          p.slights = newslist;
167 <        if (r->slights != NULL)
167 >        if (r->slights != NULL)                 /* copy old list if one */
168                  for (j = r->slights[0]; j >= 0; j--)
169                          p.slights[j] = r->slights[j];
170          else
171                  p.slights[0] = 0;
172          if (r->rod > 0.) {                      /* entering ray */
173                  addcolor(p.cext, mext);
174 <                if (m->oargs.nfargs > 3)
175 <                        p.albedo = m->oargs.farg[3];
176 <                if (m->oargs.nfargs > 4)
177 <                        p.gecc = m->oargs.farg[4];
178 <                if (myslist != NULL)                    /* add to list */
179 <                        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 <                                }
174 >                if (m->oargs.nfargs > 5)
175 >                        setcolor(p.albedo, m->oargs.farg[3],
176 >                                        m->oargs.farg[4], m->oargs.farg[5]);
177 >                if (m->oargs.nfargs > 6)
178 >                        p.gecc = m->oargs.farg[6];
179 >                add2slist(&p, myslist);                 /* add to list */
180          } 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;
181                  if (myslist != NULL) {                  /* delete from list */
182                          for (j = myslist[0]; j > 0; j--)
183                                  if (i = inslist(p.slights, myslist[j]))
# Line 178 | Line 185 | register RAY  *r;
185                          for (i = 0, j = 1; j <= p.slights[0]; j++)
186                                  if (p.slights[j] != -1)
187                                          p.slights[++i] = p.slights[j];
188 +                        if (p.slights[0] - i < myslist[0]) {    /* fix old */
189 +                                addcolor(r->cext, mext);
190 +                                if (m->oargs.nfargs > 5)
191 +                                        setcolor(r->albedo, m->oargs.farg[3],
192 +                                        m->oargs.farg[4], m->oargs.farg[5]);
193 +                                if (m->oargs.nfargs > 6)
194 +                                        r->gecc = m->oargs.farg[6];
195 +                                add2slist(r, myslist);
196 +                        }
197                          p.slights[0] = i;
198                  }
199 +                if ((re = colval(r->cext,RED) - colval(mext,RED)) <
200 +                                colval(cextinction,RED))
201 +                        re = colval(cextinction,RED);
202 +                if ((ge = colval(r->cext,GRN) - colval(mext,GRN)) <
203 +                                colval(cextinction,GRN))
204 +                        ge = colval(cextinction,GRN);
205 +                if ((be = colval(r->cext,BLU) - colval(mext,BLU)) <
206 +                                colval(cextinction,BLU))
207 +                        be = colval(cextinction,BLU);
208 +                setcolor(p.cext, re, ge, be);
209 +                if (m->oargs.nfargs > 5)
210 +                        copycolor(p.albedo, salbedo);
211 +                if (m->oargs.nfargs > 6)
212 +                        p.gecc = seccg;
213          }
214          rayvalue(&p);                           /* calls rayparticipate() */
215          copycolor(r->rcol, p.rcol);             /* return value */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines