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.26 by greg, Sat Dec 15 15:03:34 1990 UTC vs.
Revision 2.3 by greg, Sun Apr 12 10:05:32 1992 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 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "octree.h"
16  
17 #include  "source.h"
18
17   #include  "otypes.h"
18  
19 < #include  "cone.h"
19 > #include  "source.h"
20  
21 < #include  "face.h"
21 > /*
22 > * Structures used by direct()
23 > */
24  
25 < #include  "random.h"
25 > typedef struct {
26 >        int  sno;               /* source number */
27 >        FVECT  dir;             /* source direction */
28 >        COLOR  coef;            /* material coefficient */
29 >        COLOR  val;             /* contribution */
30 > }  CONTRIB;             /* direct contribution */
31  
32 + typedef struct {
33 +        int  sndx;              /* source index (to CONTRIB array) */
34 +        float  brt;             /* brightness (for comparison) */
35 + }  CNTPTR;              /* contribution pointer */
36  
28 extern double  dstrsrc;                 /* source distribution amount */
29 extern double  shadthresh;              /* relative shadow threshold */
30 extern double  shadcert;                /* shadow testing certainty */
31
32 SRCREC  *source = NULL;                 /* our list of sources */
33 int  nsources = 0;                      /* the number of sources */
34
37   static CONTRIB  *srccnt;                /* source contributions in direct() */
38   static CNTPTR  *cntord;                 /* source ordering in direct() */
39 + static int  maxcntr = 0;                /* size of contribution arrays */
40  
41  
42   marksources()                   /* find and mark source objects */
43   {
44 +        int  foundsource = 0;
45 +        int  i;
46          register OBJREC  *o, *m;
47 <        register int  i;
48 <
47 >        register int  ns;
48 >                                        /* initialize dispatch table */
49 >        initstypes();
50 >                                        /* find direct sources */
51          for (i = 0; i < nobjects; i++) {
52          
53                  o = objptr(i);
54  
55 <                if (o->omod == OVOID)
55 >                if (!issurface(o->otype) || o->omod == OVOID)
56                          continue;
57  
58                  m = objptr(o->omod);
# Line 62 | Line 69 | marksources()                  /* find and mark source objects */
69                                  m->oargs.farg[3] <= FTINY)
70                          continue;                       /* don't bother */
71  
72 <                if (source == NULL)
73 <                        source = (SRCREC *)malloc(sizeof(SRCREC));
74 <                else
75 <                        source = (SRCREC *)realloc((char *)source,
76 <                                        (unsigned)(nsources+1)*sizeof(SRCREC));
70 <                if (source == NULL)
72 >                if (sfun[o->otype].of == NULL ||
73 >                                sfun[o->otype].of->setsrc == NULL)
74 >                        objerror(o, USER, "illegal material");
75 >
76 >                if ((ns = newsource()) < 0)
77                          goto memerr;
78  
79 <                newsource(&source[nsources], o);
79 >                setsource(&source[ns], o);
80  
81                  if (m->otype == MAT_GLOW) {
82 <                        source[nsources].sflags |= SPROX;
83 <                        source[nsources].sl.prox = m->oargs.farg[3];
82 >                        source[ns].sflags |= SPROX;
83 >                        source[ns].sl.prox = m->oargs.farg[3];
84                          if (o->otype == OBJ_SOURCE)
85 <                                source[nsources].sflags |= SSKIP;
85 >                                source[ns].sflags |= SSKIP;
86                  } else if (m->otype == MAT_SPOT) {
87 <                        source[nsources].sflags |= SSPOT;
88 <                        source[nsources].sl.s = makespot(m);
87 >                        source[ns].sflags |= SSPOT;
88 >                        if ((source[ns].sl.s = makespot(m)) == NULL)
89 >                                goto memerr;
90 >                        if (source[ns].sflags & SFLAT &&
91 >                                !checkspot(source[ns].sl.s,source[ns].snorm)) {
92 >                                objerror(o, WARNING,
93 >                                        "invalid spotlight direction");
94 >                                source[ns].sflags |= SSKIP;
95 >                        }
96                  }
97 <                nsources++;
97 >                if (!(source[ns].sflags & SSKIP))
98 >                        foundsource++;
99          }
100 <        if (nsources <= 0) {
100 >        if (!foundsource) {
101                  error(WARNING, "no light sources found");
102                  return;
103          }
104 <        srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB));
105 <        cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR));
106 <        if (srccnt != NULL && cntord != NULL)
107 <                return;
108 <        /* fall through */
104 >        markvirtuals();                 /* find and add virtual sources */
105 >                                /* allocate our contribution arrays */
106 >        maxcntr = nsources + MAXSPART;  /* start with this many */
107 >        srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB));
108 >        cntord = (CNTPTR *)malloc(maxcntr*sizeof(CNTPTR));
109 >        if (srccnt == NULL | cntord == NULL)
110 >                goto memerr;
111 >        return;
112   memerr:
113          error(SYSTEM, "out of memory in marksources");
114   }
115  
116  
117 < newsource(src, so)                      /* add a source to the array */
101 < register SRCREC  *src;
102 < register OBJREC  *so;
103 < {
104 <        double  cos(), tan(), sqrt();
105 <        double  theta;
106 <        FACE  *f;
107 <        CONE  *co;
108 <        int  j;
109 <        register int  i;
110 <        
111 <        src->sflags = 0;
112 <        src->nhits = 1; src->ntests = 2;        /* start probability = 1/2 */
113 <        src->so = so;
114 <
115 <        switch (so->otype) {
116 <        case OBJ_SOURCE:
117 <                if (so->oargs.nfargs != 4)
118 <                        objerror(so, USER, "bad arguments");
119 <                src->sflags |= SDISTANT;
120 <                VCOPY(src->sloc, so->oargs.farg);
121 <                if (normalize(src->sloc) == 0.0)
122 <                        objerror(so, USER, "zero direction");
123 <                theta = PI/180.0/2.0 * so->oargs.farg[3];
124 <                if (theta <= FTINY)
125 <                        objerror(so, USER, "zero size");
126 <                src->ss = theta >= PI/4 ? 1.0 : tan(theta);
127 <                src->ss2 = 2.0*PI * (1.0 - cos(theta));
128 <                break;
129 <        case OBJ_SPHERE:
130 <                VCOPY(src->sloc, so->oargs.farg);
131 <                src->ss = so->oargs.farg[3];
132 <                src->ss2 = PI * src->ss * src->ss;
133 <                break;
134 <        case OBJ_FACE:
135 <                                                /* get the face */
136 <                f = getface(so);
137 <                                                /* find the center */
138 <                for (j = 0; j < 3; j++) {
139 <                        src->sloc[j] = 0.0;
140 <                        for (i = 0; i < f->nv; i++)
141 <                                src->sloc[j] += VERTEX(f,i)[j];
142 <                        src->sloc[j] /= f->nv;
143 <                }
144 <                if (!inface(src->sloc, f))
145 <                        objerror(so, USER, "cannot hit center");
146 <                src->ss = sqrt(f->area / PI);
147 <                src->ss2 = f->area;
148 <                break;
149 <        case OBJ_RING:
150 <                                                /* get the ring */
151 <                co = getcone(so, 0);
152 <                VCOPY(src->sloc, CO_P0(co));
153 <                if (CO_R0(co) > 0.0)
154 <                        objerror(so, USER, "cannot hit center");
155 <                src->ss = CO_R1(co);
156 <                src->ss2 = PI * src->ss * src->ss;
157 <                break;
158 <        default:
159 <                objerror(so, USER, "illegal material");
160 <        }
161 < }
162 <
163 <
164 < SPOT *
165 < makespot(m)                     /* make a spotlight */
166 < register OBJREC  *m;
167 < {
168 <        extern double  cos();
169 <        register SPOT  *ns;
170 <
171 <        if ((ns = (SPOT *)malloc(sizeof(SPOT))) == NULL)
172 <                error(SYSTEM, "out of memory in makespot");
173 <        ns->siz = 2.0*PI * (1.0 - cos(PI/180.0/2.0 * m->oargs.farg[3]));
174 <        VCOPY(ns->aim, m->oargs.farg+4);
175 <        if ((ns->flen = normalize(ns->aim)) == 0.0)
176 <                objerror(m, USER, "zero focus vector");
177 <        return(ns);
178 < }
179 <
180 <
181 < double
182 < srcray(sr, r, sn)               /* send a ray to a source, return domega */
117 > srcray(sr, r, si)               /* send a ray to a source, return domega */
118   register RAY  *sr;              /* returned source ray */
119   RAY  *r;                        /* ray which hit object */
120 < register int  sn;               /* source number */
120 > SRCINDEX  *si;                  /* source sample index */
121   {
122 <        register double  *norm = NULL;  /* plane normal */
123 <        double  ddot;                   /* (distance times) cosine */
124 <        FVECT  vd;
125 <        double  d;
191 <        register int  i;
122 >    double  d;                          /* distance to source */
123 >    FVECT  vd;
124 >    register SRCREC  *srcp;
125 >    register int  i;
126  
127 <        if (source[sn].sflags & SSKIP)
194 <                return(0.0);                    /* skip this source */
127 >    rayorigin(sr, r, SHADOW, 1.0);              /* ignore limits */
128  
129 <        rayorigin(sr, r, SHADOW, 1.0);          /* ignore limits */
130 <
131 <        sr->rsrc = sn;                          /* remember source */
132 <                                                /* get source direction */
133 <        if (source[sn].sflags & SDISTANT)
201 <                                                /* constant direction */
202 <                VCOPY(sr->rdir, source[sn].sloc);
203 <        else {                                  /* compute direction */
204 <                for (i = 0; i < 3; i++)
205 <                        sr->rdir[i] = source[sn].sloc[i] - sr->rorg[i];
206 <
207 <                if (source[sn].so->otype == OBJ_FACE)
208 <                        norm = getface(source[sn].so)->norm;
209 <                else if (source[sn].so->otype == OBJ_RING)
210 <                        norm = getcone(source[sn].so,0)->ad;
211 <
212 <                if (norm != NULL && (ddot = -DOT(sr->rdir, norm)) <= FTINY)
213 <                        return(0.0);            /* behind surface! */
214 <        }
215 <        if (dstrsrc > FTINY) {
216 <                                        /* distribute source direction */
217 <                for (i = 0; i < 3; i++)
218 <                        vd[i] = dstrsrc * source[sn].ss * (1.0 - 2.0*frandom());
219 <
220 <                if (norm != NULL) {             /* project offset */
221 <                        d = DOT(vd, norm);
129 >    while ((d = nextssamp(sr, si)) != 0.0) {
130 >        sr->rsrc = si->sn;                      /* remember source */
131 >        srcp = source + si->sn;
132 >        if (srcp->sflags & SDISTANT) {
133 >                if (srcp->sflags & SSPOT) {     /* check location */
134                          for (i = 0; i < 3; i++)
135 <                                vd[i] -= d * norm[i];
135 >                            vd[i] = srcp->sl.s->aim[i] - sr->rorg[i];
136 >                        d = DOT(sr->rdir,vd);
137 >                        if (d <= FTINY)
138 >                                continue;
139 >                        d = DOT(vd,vd) - d*d;
140 >                        if (PI*d > srcp->sl.s->siz)
141 >                                continue;
142                  }
143 <                for (i = 0; i < 3; i++)         /* offset source direction */
144 <                        sr->rdir[i] += vd[i];
145 <
228 <        } else if (source[sn].sflags & SDISTANT)
229 <                                                /* already normalized */
230 <                return(source[sn].ss2);
231 <
232 <        if ((d = normalize(sr->rdir)) == 0.0)
233 <                                                /* at source! */
234 <                return(0.0);
235 <        
236 <        if (source[sn].sflags & SDISTANT)
237 <                                                /* domega constant */
238 <                return(source[sn].ss2);
239 <
240 <        else {
143 >                return(1);              /* sample OK */
144 >        }
145 >                                /* local source */
146                                                  /* check proximity */
147 <                if (source[sn].sflags & SPROX &&
148 <                                d > source[sn].sl.prox)
244 <                        return(0.0);
245 <
246 <                if (norm != NULL)
247 <                        ddot /= d;
248 <                else
249 <                        ddot = 1.0;
147 >        if (srcp->sflags & SPROX && d > srcp->sl.prox)
148 >                continue;
149                                                  /* check angle */
150 <                if (source[sn].sflags & SSPOT) {
151 <                        if (source[sn].sl.s->siz < 2.0*PI *
152 <                                (1.0 + DOT(source[sn].sl.s->aim,sr->rdir)))
153 <                                return(0.0);
154 <                        d += source[sn].sl.s->flen;
155 <                }
156 <                                                /* return domega */
157 <                return(ddot*source[sn].ss2/(d*d));
150 >        if (srcp->sflags & SSPOT) {
151 >                if (srcp->sl.s->siz < 2.0*PI *
152 >                                (1.0 + DOT(srcp->sl.s->aim,sr->rdir)))
153 >                        continue;
154 >                                        /* adjust solid angle */
155 >                si->dom *= d*d;
156 >                d += srcp->sl.s->flen;
157 >                si->dom /= d*d;
158          }
159 +        return(1);                      /* sample OK */
160 +    }
161 +    return(0);                  /* no more samples */
162   }
163  
164  
165 < sourcehit(r)                    /* check to see if ray hit distant source */
166 < register RAY  *r;
165 > srcvalue(r)                     /* punch ray to source and compute value */
166 > RAY  *r;
167   {
168 <        int  first, last;
267 <        register int  i;
168 >        register SRCREC  *sp;
169  
170 <        if (r->rsrc >= 0) {             /* check only one if aimed */
171 <                first = last = r->rsrc;
172 <        } else {                        /* otherwise check all */
173 <                first = 0; last = nsources-1;
170 >        sp = &source[r->rsrc];
171 >        if (sp->sflags & SVIRTUAL) {    /* virtual source */
172 >                                        /* check intersection */
173 >                if (!(*ofun[sp->so->otype].funp)(sp->so, r))
174 >                        return;
175 >                raycont(r);             /* compute contribution */
176 >                return;
177          }
178 <        for (i = first; i <= last; i++)
179 <                if (source[i].sflags & SDISTANT)
180 <                        /*
181 <                         * Check to see if ray is within
182 <                         * solid angle of source.
183 <                         */
184 <                        if (2.0*PI * (1.0 - DOT(source[i].sloc,r->rdir))
281 <                                        <= source[i].ss2) {
282 <                                r->ro = source[i].so;
283 <                                if (!(source[i].sflags & SSKIP))
284 <                                        break;
285 <                        }
286 <
287 <        if (r->ro != NULL) {
288 <                for (i = 0; i < 3; i++)
289 <                        r->ron[i] = -r->rdir[i];
290 <                r->rod = 1.0;
291 <                r->rox = NULL;
292 <                return(1);
178 >                                        /* compute intersection */
179 >        if (sp->sflags & SDISTANT ? sourcehit(r) :
180 >                        (*ofun[sp->so->otype].funp)(sp->so, r)) {
181 >                if (sp->sa.success >= 0)
182 >                        sp->sa.success++;
183 >                raycont(r);             /* compute contribution */
184 >                return;
185          }
186 <        return(0);
186 >        if (sp->sa.success < 0)
187 >                return;                 /* bitched already */
188 >        sp->sa.success -= AIMREQT;
189 >        if (sp->sa.success >= 0)
190 >                return;                 /* leniency */
191 >        sprintf(errmsg, "aiming failure for light source \"%s\"",
192 >                        sp->so->oname);
193 >        error(WARNING, errmsg);         /* issue warning */
194   }
195  
196  
# Line 312 | Line 211 | RAY  *r;                       /* ray that hit surface */
211   int  (*f)();                    /* direct component coefficient function */
212   char  *p;                       /* data for f */
213   {
214 +        extern int  (*trace)();
215          extern double  pow();
216          register int  sn;
217 +        SRCINDEX  si;
218          int  nshadcheck, ncnts;
219 <        double  prob, ourthresh, hwt, test2, hit2;
219 >        int  nhits;
220 >        double  prob, ourthresh, hwt;
221          RAY  sr;
222                          /* NOTE: srccnt and cntord global so no recursion */
223          if (nsources <= 0)
224                  return;         /* no sources?! */
323                                                /* compute number to check */
324        nshadcheck = pow((double)nsources, shadcert) + .5;
325                                                /* modify threshold */
326        ourthresh = shadthresh / r->rweight;
225                                                  /* potential contributions */
226 <        for (sn = 0; sn < nsources; sn++) {
227 <                cntord[sn].sno = sn;
228 <                cntord[sn].brt = 0.0;
229 <                                                /* get source ray */
230 <                if ((srccnt[sn].dom = srcray(&sr, r, sn)) == 0.0)
231 <                        continue;
232 <                VCOPY(srccnt[sn].dir, sr.rdir);
226 >        initsrcindex(&si);
227 >        for (sn = 0; srcray(&sr, r, &si); sn++) {
228 >                if (sn >= maxcntr) {
229 >                        maxcntr = sn + MAXSPART;
230 >                        srccnt = (CONTRIB *)realloc((char *)srccnt,
231 >                                        maxcntr*sizeof(CONTRIB));
232 >                        cntord = (CNTPTR *)realloc((char *)cntord,
233 >                                        maxcntr*sizeof(CNTPTR));
234 >                        if (srccnt == NULL | cntord == NULL)
235 >                                error(SYSTEM, "out of memory in direct");
236 >                }
237 >                cntord[sn].sndx = sn;
238 >                srccnt[sn].sno = sr.rsrc;
239                                                  /* compute coefficient */
240 <                (*f)(srccnt[sn].val, p, srccnt[sn].dir, srccnt[sn].dom);
241 <                cntord[sn].brt = bright(srccnt[sn].val);
240 >                (*f)(srccnt[sn].coef, p, sr.rdir, si.dom);
241 >                cntord[sn].brt = bright(srccnt[sn].coef);
242                  if (cntord[sn].brt <= 0.0)
243                          continue;
244 <                                                /* compute intersection */
245 <                if (!( source[sn].sflags & SDISTANT ?
246 <                                sourcehit(&sr) :
247 <                                (*ofun[source[sn].so->otype].funp)
248 <                                (source[sn].so, &sr) )) {
249 <                        sprintf(errmsg,
346 <                                "aiming failure for light source \"%s\"",
347 <                                        source[sn].so->oname);
348 <                        error(WARNING, errmsg);
349 <                        continue;
350 <                }
351 <                                                /* compute contribution */
352 <                raycont(&sr);
353 <                multcolor(srccnt[sn].val, sr.rcol);
244 >                VCOPY(srccnt[sn].dir, sr.rdir);
245 >                                                /* compute potential */
246 >                sr.revf = srcvalue;
247 >                rayvalue(&sr);
248 >                copycolor(srccnt[sn].val, sr.rcol);
249 >                multcolor(srccnt[sn].val, srccnt[sn].coef);
250                  cntord[sn].brt = bright(srccnt[sn].val);
251          }
252                                                  /* sort contributions */
253 <        qsort(cntord, nsources, sizeof(CNTPTR), cntcmp);
253 >        qsort(cntord, sn, sizeof(CNTPTR), cntcmp);
254          {                                       /* find last */
255                  register int  l, m;
256  
257 <                sn = 0; ncnts = l = nsources;
257 >                ncnts = l = sn;
258 >                sn = 0;
259                  while ((m = (sn + ncnts) >> 1) != l) {
260                          if (cntord[m].brt > 0.0)
261                                  sn = m;
# Line 367 | Line 264 | char  *p;                      /* data for f */
264                          l = m;
265                  }
266          }
267 +        if (ncnts == 0)
268 +                return;         /* no contributions! */
269                                                  /* accumulate tail */
270          for (sn = ncnts-1; sn > 0; sn--)
271                  cntord[sn-1].brt += cntord[sn].brt;
272 <                                                /* start with prob=.5 */
273 <        hit2 = 0.5; test2 = 1.0;
272 >                                                /* compute number to check */
273 >        nshadcheck = pow((double)ncnts, shadcert) + .5;
274 >                                                /* modify threshold */
275 >        ourthresh = shadthresh / r->rweight;
276                                                  /* test for shadows */
277 +        nhits = 0;
278          for (sn = 0; sn < ncnts; sn++) {
279                                                  /* check threshold */
280                  if ((sn+nshadcheck>=ncnts ? cntord[sn].brt :
281 <                                cntord[sn].brt-cntord[sn+nshadcheck].brt) <
282 <                                ourthresh*bright(r->rcol))
281 >                                cntord[sn].brt-cntord[sn+nshadcheck].brt)
282 >                                < ourthresh*bright(r->rcol))
283                          break;
382                                                /* get statistics */
383                hwt = (double)source[cntord[sn].sno].nhits /
384                                (double)source[cntord[sn].sno].ntests;
385                test2 += hwt;
386                source[cntord[sn].sno].ntests++;
284                                                  /* test for hit */
285                  rayorigin(&sr, r, SHADOW, 1.0);
286 <                VCOPY(sr.rdir, srccnt[cntord[sn].sno].dir);
287 <                sr.rsrc = cntord[sn].sno;
286 >                VCOPY(sr.rdir, srccnt[cntord[sn].sndx].dir);
287 >                sr.rsrc = srccnt[cntord[sn].sndx].sno;
288 >                source[sr.rsrc].ntests++;       /* keep statistics */
289                  if (localhit(&sr, &thescene) &&
290 <                                sr.ro != source[cntord[sn].sno].so) {
291 <                                                /* check for transmission */
290 >                                ( sr.ro != source[sr.rsrc].so ||
291 >                                source[sr.rsrc].sflags & SFOLLOW )) {
292 >                                                /* follow entire path */
293                          raycont(&sr);
294 +                        if (trace != NULL)
295 +                                (*trace)(&sr);  /* trace execution */
296                          if (bright(sr.rcol) <= FTINY)
297                                  continue;       /* missed! */
298 <                        (*f)(srccnt[cntord[sn].sno].val, p,
299 <                                        srccnt[cntord[sn].sno].dir,
300 <                                        srccnt[cntord[sn].sno].dom);
400 <                        multcolor(srccnt[cntord[sn].sno].val, sr.rcol);
298 >                        copycolor(srccnt[cntord[sn].sndx].val, sr.rcol);
299 >                        multcolor(srccnt[cntord[sn].sndx].val,
300 >                                        srccnt[cntord[sn].sndx].coef);
301                  }
302                                                  /* add contribution if hit */
303 <                addcolor(r->rcol, srccnt[cntord[sn].sno].val);
304 <                hit2 += hwt;
305 <                source[cntord[sn].sno].nhits++;
303 >                addcolor(r->rcol, srccnt[cntord[sn].sndx].val);
304 >                nhits++;
305 >                source[sr.rsrc].nhits++;
306          }
307 <                                        /* weighted hit rate */
308 <        hwt = hit2 / test2;
307 >                                        /* surface hit rate */
308 >        if (sn > 0)
309 >                hwt = (double)nhits / (double)sn;
310 >        else
311 >                hwt = 0.5;
312   #ifdef DEBUG
313          sprintf(errmsg, "%d tested, %d untested, %f hit rate\n",
314                          sn, ncnts-sn, hwt);
# Line 413 | Line 316 | char  *p;                      /* data for f */
316   #endif
317                                          /* add in untested sources */
318          for ( ; sn < ncnts; sn++) {
319 <                prob = hwt * (double)source[cntord[sn].sno].nhits /
320 <                                (double)source[cntord[sn].sno].ntests;
321 <                scalecolor(srccnt[cntord[sn].sno].val, prob);
322 <                addcolor(r->rcol, srccnt[cntord[sn].sno].val);
323 <        }
421 < }
422 <
423 <
424 < #define  wrongsource(m, r)      (m->otype!=MAT_ILLUM && \
425 <                                r->rsrc>=0 && \
426 <                                source[r->rsrc].so!=r->ro)
427 <
428 < #define  badambient(m, r)       ((r->crtype&(AMBIENT|SHADOW))==AMBIENT && \
429 <                                !(r->rtype&REFLECTED) &&        /* hack! */\
430 <                                !(m->otype==MAT_GLOW&&r->rot>m->oargs.farg[3]))
431 <
432 < #define  passillum(m, r)        (m->otype==MAT_ILLUM && \
433 <                                !(r->rsrc>=0&&source[r->rsrc].so==r->ro))
434 <
435 <
436 < m_light(m, r)                   /* ray hit a light source */
437 < register OBJREC  *m;
438 < register RAY  *r;
439 < {
440 <                                                /* check for over-counting */
441 <        if (wrongsource(m, r) || badambient(m, r))
442 <                return;
443 <                                                /* check for passed illum */
444 <        if (passillum(m, r)) {
445 <
446 <                if (m->oargs.nsargs < 1 || !strcmp(m->oargs.sarg[0], VOIDID))
447 <                        raytrans(r);
448 <                else
449 <                        rayshade(r, modifier(m->oargs.sarg[0]));
450 <
451 <                                                /* otherwise treat as source */
452 <        } else {
453 <                                                /* check for behind */
454 <                if (r->rod < 0.0)
455 <                        return;
456 <                                                /* get distribution pattern */
457 <                raytexture(r, m->omod);
458 <                                                /* get source color */
459 <                setcolor(r->rcol, m->oargs.farg[0],
460 <                                  m->oargs.farg[1],
461 <                                  m->oargs.farg[2]);
462 <                                                /* modify value */
463 <                multcolor(r->rcol, r->pcol);
464 <                                                /* assign distance */
465 <                r->rt = r->rot;
319 >                sr.rsrc = srccnt[cntord[sn].sndx].sno;
320 >                prob = hwt * (double)source[sr.rsrc].nhits /
321 >                                (double)source[sr.rsrc].ntests;
322 >                scalecolor(srccnt[cntord[sn].sndx].val, prob);
323 >                addcolor(r->rcol, srccnt[cntord[sn].sndx].val);
324          }
325   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines