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.5 by greg, Thu Mar 21 10:24:59 1996 UTC

# Line 36 | Line 36 | static char SCCSid[] = "$SunId$ LBL";
36   *      [ext_r  ext_g  ext_b  [albedo [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  
46 #define MAXSLIST        32              /* maximum sources to check */
47   #define RELAYDELIM      '>'             /* relay delimiter character */
48  
49   extern COLOR  cextinction;              /* global coefficient of extinction */
# Line 66 | Line 66 | register int  n;
66  
67  
68   static int
69 < srcmatch(sn, id)        /* check for an id match on a light source */
70 < register int  sn;
71 < char  *id;
69 > srcmatch(sp, id)        /* check for an id match on a light source */
70 > register SRCREC  *sp;
71 > register char  *id;
72   {
73          extern char  *index();
74          register char  *cp;
75 < again:
76 <        if (source[sn].so == NULL)              /* just in case */
77 <                return(0);
78 <        if ((cp = index(id, RELAYDELIM)) != NULL) {     /* relay source */
79 <                if (!(source[sn].sflags & SVIRTUAL))
75 >                                                /* check for relay sources */
76 >        while ((cp = index(id, RELAYDELIM)) != NULL) {
77 >                if (!(sp->sflags & SVIRTUAL) || sp->so == NULL)
78                          return(0);
79 <                *cp = '\0';
82 <                if (strcmp(id, source[sn].so->oname)) {
83 <                        *cp = RELAYDELIM;
79 >                if (strncmp(id, sp->so->oname, cp-id) || sp->so->oname[cp-id])
80                          return(0);
81 <                }
82 <                *cp = RELAYDELIM;
87 <                id = cp + 1;                            /* recurse */
88 <                sn = source[sn].sa.sv.sn;
89 <                goto again;
81 >                id = cp + 1;                            /* relay to next */
82 >                sp = source + sp->sa.sv.sn;
83          }
84 <        if (source[sn].sflags & SVIRTUAL)
84 >        if (sp->sflags & SVIRTUAL || sp->so == NULL)
85                  return(0);
86 <        return(!strcmp(id, source[sn].so->oname));
86 >        return(!strcmp(id, sp->so->oname));
87   }
88  
89  
90 + static
91 + add2slist(r, sl)        /* add source list to ray's */
92 + register RAY  *r;
93 + register int  *sl;
94 + {
95 +        static int  slspare[MAXSLIST+1];        /* in case of emergence */
96 +        register int  i;
97 +
98 +        if (sl == NULL || sl[0] == 0)           /* nothing to add */
99 +                return;
100 +        if (r->slights == NULL)
101 +                (r->slights = slspare)[0] = 0;  /* just once per ray path */
102 +        for (i = sl[0]; i > 0; i--)
103 +                if (!inslist(r->slights, sl[i])) {
104 +                        if (r->slights[0] >= MAXSLIST)
105 +                                error(USER, "scattering source list overflow");
106 +                        r->slights[++r->slights[0]] = sl[i];
107 +                }
108 + }
109 +
110 +
111   m_mist(m, r)            /* process a ray entering or leaving some mist */
112   OBJREC  *m;
113   register RAY  *r;
# Line 107 | Line 121 | register RAY  *r;
121                                          /* check arguments */
122          if (m->oargs.nfargs > 5)
123                  objerror(m, USER, "bad arguments");
110        if (m->oargs.nsargs > MAXSLIST)
111                objerror(m, USER, "too many sources in list");
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");
128                  myslist = (int *)malloc((m->oargs.nsargs+1)*sizeof(int));
129                  if (myslist == NULL)
130                          goto memerr;
131 <                myslist[0] = m->oargs.nsargs;   /* size is first in set */
132 <                for (j = myslist[0]; j > 0; j--) {
131 >                myslist[0] = 0;                 /* size is first in list */
132 >                for (j = 0; j < m->oargs.nsargs; j++) {
133                          i = nsources;           /* look up each source id */
134                          while (i--)
135 <                                if (srcmatch(i, m->oargs.sarg[j-1]))
135 >                                if (srcmatch(source+i, m->oargs.sarg[j]))
136                                          break;
137                          if (i < 0) {
138                                  sprintf(errmsg, "unknown source \"%s\"",
139 <                                                m->oargs.sarg[j-1]);
139 >                                                m->oargs.sarg[j]);
140                                  objerror(m, WARNING, errmsg);
141 +                        } else if (inslist(myslist, i)) {
142 +                                sprintf(errmsg, "duplicate source \"%s\"",
143 +                                                m->oargs.sarg[j]);
144 +                                objerror(m, WARNING, errmsg);
145                          } else
146 <                                myslist[j] = i;
146 >                                myslist[++myslist[0]] = i;
147                  }
148                  m->os = (char *)myslist;
149          }
# Line 141 | Line 159 | register RAY  *r;
159                  return(1);
160          VCOPY(p.rdir, r->rdir);
161          p.slights = newslist;
162 <        if (r->slights != NULL)
162 >        if (r->slights != NULL)                 /* copy old list if one */
163                  for (j = r->slights[0]; j >= 0; j--)
164                          p.slights[j] = r->slights[j];
165          else
# Line 152 | Line 170 | register RAY  *r;
170                          p.albedo = m->oargs.farg[3];
171                  if (m->oargs.nfargs > 4)
172                          p.gecc = m->oargs.farg[4];
173 <                if (myslist != NULL)                    /* add to list */
156 <                        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 >                add2slist(&p, myslist);                 /* add to list */
174          } 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;
175                  if (myslist != NULL) {                  /* delete from list */
176                          for (j = myslist[0]; j > 0; j--)
177                                  if (i = inslist(p.slights, myslist[j]))
# Line 178 | Line 179 | register RAY  *r;
179                          for (i = 0, j = 1; j <= p.slights[0]; j++)
180                                  if (p.slights[j] != -1)
181                                          p.slights[++i] = p.slights[j];
182 +                        if (p.slights[0] - i < myslist[0]) {    /* fix old */
183 +                                addcolor(r->cext, mext);
184 +                                if (m->oargs.nfargs > 3)
185 +                                        r->albedo = m->oargs.farg[3];
186 +                                if (m->oargs.nfargs > 4)
187 +                                        r->gecc = m->oargs.farg[4];
188 +                                add2slist(r, myslist);
189 +                        }
190                          p.slights[0] = i;
191                  }
192 +                if ((re = colval(r->cext,RED) - colval(mext,RED)) <
193 +                                colval(cextinction,RED))
194 +                        re = colval(cextinction,RED);
195 +                if ((ge = colval(r->cext,GRN) - colval(mext,GRN)) <
196 +                                colval(cextinction,GRN))
197 +                        ge = colval(cextinction,GRN);
198 +                if ((be = colval(r->cext,BLU) - colval(mext,BLU)) <
199 +                                colval(cextinction,BLU))
200 +                        be = colval(cextinction,BLU);
201 +                setcolor(p.cext, re, ge, be);
202 +                if (m->oargs.nfargs > 3)
203 +                        p.albedo = salbedo;
204 +                if (m->oargs.nfargs > 4)
205 +                        p.gecc = seccg;
206          }
207          rayvalue(&p);                           /* calls rayparticipate() */
208          copycolor(r->rcol, p.rcol);             /* return value */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines