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

Comparing ray/src/rt/source.c (file contents):
Revision 1.35 by greg, Thu Jun 20 13:43:29 1991 UTC vs.
Revision 1.44 by greg, Thu Aug 22 11:56:55 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1990 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 43 | Line 43 | marksources()                  /* find and mark source objects */
43   {
44          int  i;
45          register OBJREC  *o, *m;
46 <        register SRCREC  *ns;
46 >        register int  ns;
47                                          /* initialize dispatch table */
48          initstypes();
49                                          /* find direct sources */
# Line 72 | Line 72 | marksources()                  /* find and mark source objects */
72                                  sfun[o->otype].of->setsrc == NULL)
73                          objerror(o, USER, "illegal material");
74  
75 <                if ((ns = newsource()) == NULL)
75 >                if ((ns = newsource()) < 0)
76                          goto memerr;
77  
78 <                (*sfun[o->otype].of->setsrc)(ns, o);
78 >                setsource(&source[ns], o);
79  
80                  if (m->otype == MAT_GLOW) {
81 <                        ns->sflags |= SPROX;
82 <                        ns->sl.prox = m->oargs.farg[3];
81 >                        source[ns].sflags |= SPROX;
82 >                        source[ns].sl.prox = m->oargs.farg[3];
83                          if (o->otype == OBJ_SOURCE)
84 <                                ns->sflags |= SSKIP;
84 >                                source[ns].sflags |= SSKIP;
85                  } else if (m->otype == MAT_SPOT) {
86 <                        ns->sflags |= SSPOT;
87 <                        if ((ns->sl.s = makespot(m)) == NULL)
86 >                        source[ns].sflags |= SSPOT;
87 >                        if ((source[ns].sl.s = makespot(m)) == NULL)
88                                  goto memerr;
89 +                        if (source[ns].sflags & SFLAT &&
90 +                                !checkspot(source[ns].sl.s,source[ns].snorm)) {
91 +                                objerror(o, WARNING,
92 +                                        "invalid spotlight direction");
93 +                                source[ns].sflags |= SSKIP;
94 +                        }
95                  }
96          }
97          if (nsources <= 0) {
# Line 95 | Line 101 | marksources()                  /* find and mark source objects */
101          markvirtuals();                 /* find and add virtual sources */
102          srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB));
103          cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR));
104 <        if (srccnt != NULL && cntord != NULL)
104 >        if (srccnt == NULL || cntord == NULL)
105                  goto memerr;
106          return;
107   memerr:
# Line 122 | Line 128 | register int  sn;              /* source number */
128          sr->rsrc = sn;                          /* remember source */
129                                                  /* get source direction */
130          if (source[sn].sflags & SDISTANT) {
125                if (source[sn].sflags & SSPOT) {        /* check location */
126                        for (i = 0; i < 3; i++)
127                                vd[i] = sr->rorg[i] - source[sn].sl.s->aim[i];
128                        d = DOT(source[sn].sloc,vd);
129                        d = DOT(vd,vd) - d*d;
130                        if (PI*d > source[sn].sl.s->siz)
131                                return(0.0);
132                }
131                                                  /* constant direction */
132                  VCOPY(sr->rdir, source[sn].sloc);
133          } else {                                /* compute direction */
# Line 142 | Line 140 | register int  sn;              /* source number */
140          }
141          if (dstrsrc > FTINY) {
142                                          /* distribute source direction */
143 <                dimlist[ndims++] = sn;
144 <                for (i = 0; i < 3; i++) {
145 <                        dimlist[ndims] = i + 8831;
146 <                        vd[i] = dstrsrc * source[sn].ss *
149 <                (1.0 - 2.0*urand(ilhash(dimlist,ndims+1)+samplendx));
150 <                }
151 <                ndims--;
143 >                dimlist[ndims] = sn + 8831;
144 >                multisamp(vd, 3, urand(ilhash(dimlist,ndims+1)+samplendx));
145 >                for (i = 0; i < 3; i++)
146 >                        vd[i] = dstrsrc * source[sn].ss * (1. - 2.*vd[i]);
147                  if (source[sn].sflags & SFLAT) {        /* project offset */
148                          d = DOT(vd, source[sn].snorm);
149                          for (i = 0; i < 3; i++)
# Line 156 | Line 151 | register int  sn;              /* source number */
151                  }
152                  for (i = 0; i < 3; i++)         /* offset source direction */
153                          sr->rdir[i] += vd[i];
154 +                                                /* normalize */
155 +                d = normalize(sr->rdir);
156  
157 <        } else if (source[sn].sflags & SDISTANT)
158 <                                                /* already normalized */
159 <                return(source[sn].ss2);
157 >        } else if (!(source[sn].sflags & SDISTANT))
158 >                                                /* normalize direction */
159 >                d = normalize(sr->rdir);
160  
161 <        if ((d = normalize(sr->rdir)) == 0.0)
162 <                                                /* at source! */
161 >        if (source[sn].sflags & SDISTANT) {
162 >                if (source[sn].sflags & SSPOT) {        /* check location */
163 >                        for (i = 0; i < 3; i++)
164 >                                vd[i] = source[sn].sl.s->aim[i] - sr->rorg[i];
165 >                        d = DOT(sr->rdir,vd);
166 >                        if (d <= FTINY)
167 >                                return(0.0);
168 >                        d = DOT(vd,vd) - d*d;
169 >                        if (PI*d > source[sn].sl.s->siz)
170 >                                return(0.0);
171 >                }
172 >                return(source[sn].ss2);         /* domega constant */
173 >        }
174 >                                                /* check direction */
175 >        if (d == 0.0)
176                  return(0.0);
167        
168        if (source[sn].sflags & SDISTANT)
169                                                /* domega constant */
170                return(source[sn].ss2);
171
177                                                  /* check proximity */
178          if (source[sn].sflags & SPROX &&
179                          d > source[sn].sl.prox)
# Line 239 | Line 244 | RAY  *r;                       /* ray that hit surface */
244   int  (*f)();                    /* direct component coefficient function */
245   char  *p;                       /* data for f */
246   {
247 +        extern int  (*trace)();
248          extern double  pow();
249          register int  sn;
250          int  nshadcheck, ncnts;
# Line 308 | Line 314 | char  *p;                      /* data for f */
314                                  source[cntord[sn].sno].sflags & SFOLLOW )) {
315                                                  /* follow entire path */
316                          raycont(&sr);
317 +                        if (trace != NULL)
318 +                                (*trace)(&sr);  /* trace execution */
319                          if (bright(sr.rcol) <= FTINY)
320                                  continue;       /* missed! */
321                          copycolor(srccnt[cntord[sn].sno].val, sr.rcol);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines