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

Comparing ray/src/gen/mkillum2.c (file contents):
Revision 2.28 by greg, Thu Dec 13 07:03:37 2007 UTC vs.
Revision 2.29 by greg, Wed Mar 4 00:12:25 2009 UTC

# Line 15 | Line 15 | static const char      RCSid[] = "$Id$";
15  
16   COLORV *        distarr = NULL;         /* distribution array */
17   int             distsiz = 0;
18 + COLORV *        direct_discount = NULL; /* amount to take off direct */
19  
19
20   void
21   newdist(                        /* allocate & clear distribution array */
22          int siz
# Line 41 | Line 41 | newdist(                       /* allocate & clear distribution array */
41   }
42  
43  
44 + static void
45 + new_discount()                  /* allocate space for direct contrib. record */
46 + {
47 +        if (distsiz <= 0)
48 +                return;
49 +        direct_discount = (COLORV *)calloc(distsiz, sizeof(COLOR));
50 +        if (direct_discount == NULL)
51 +                error(SYSTEM, "out of memory in new_discount");
52 + }
53 +
54 +
55 + static void
56 + done_discount()                 /* clear off direct contrib. record */
57 + {
58 +        if (direct_discount == NULL)
59 +                return;
60 +        free((void *)direct_discount);
61 +        direct_discount = NULL;
62 + }
63 +
64 +
65   int
66   process_ray(                    /* process a ray result or report error */
67          RAY *r,
# Line 58 | Line 79 | process_ray(                   /* process a ray result or report error
79          multcolor(r->rcol, r->rcoef);   /* in case it's a source ray */
80          colp = &distarr[r->rno * 3];
81          addcolor(colp, r->rcol);
82 +        if (r->rsrc >= 0 &&             /* remember source contrib. */
83 +                        direct_discount != NULL) {
84 +                colp = &direct_discount[r->rno * 3];
85 +                addcolor(colp, r->rcol);
86 +        }
87          return(1);
88   }
89  
# Line 143 | Line 169 | srcsamps(                      /* sample sources from this surface positi
169                  } else {
170                          if (v[2] >= -FTINY)
171                                  continue;       /* only sample transmission */
172 <                        d = 1.0 - v[2]*v[2];
173 <                        i = d*nalt;
174 <                        d = atan2(-v[1], -v[0])/(2.*PI);
149 <                        if (d < 0.0) d += 1.0;
150 <                        j = d*nazi + 0.5;
151 <                        if (j >= nazi) j = 0;
152 <                        sr.rno = i*nazi + j;
153 <                        d = nalt*nazi/PI * -v[2];
172 >                        v[0] = -v[0]; v[1] = -v[1]; v[2] = -v[2];
173 >                        sr.rno = flatindex(v, nalt, nazi);
174 >                        d = nalt*nazi*(1./PI) * v[2];
175                  }
176                  d *= si.dom;                    /* solid angle correction */
177                  scalecolor(sr.rcoef, d);
# Line 222 | Line 243 | flatdir(               /* compute uniform hemispherical direction *
243          dv[2] = sqrt(1. - alt);
244   }
245  
246 + int
247 + flatindex(              /* compute index for hemispherical direction */
248 +        FVECT   dv,
249 +        int     nalt,
250 +        int     nazi
251 + )
252 + {
253 +        double  d;
254 +        int     i, j;
255 +        
256 +        d = 1.0 - dv[2]*dv[2];
257 +        i = d*nalt;
258 +        d = atan2(dv[1], dv[0]) * (0.5/PI);
259 +        if (d < 0.0) d += 1.0;
260 +        j = d*nazi + 0.5;
261 +        if (j >= nazi) j = 0;
262 +        return(i*nazi + j);
263 + }
264  
265 +
266   int
267   my_default(     /* default illum action */
268          OBJREC  *ob,
# Line 350 | Line 390 | my_face(               /* make an illum face */
390                      raysamp(dim[1], org, dir);
391                  }
392                                  /* add in direct component? */
393 <        if (!directvis && il->flags & IL_LIGHT) {
393 >        if (!directvis && (il->flags & IL_LIGHT || il->sd != NULL)) {
394                  MAT4    ixfm;
395                  if (il->sd == NULL) {
396                          for (i = 3; i--; ) {
# Line 361 | Line 401 | my_face(               /* make an illum face */
401                          }
402                          ixfm[3][0] = ixfm[3][1] = ixfm[3][2] = 0.;
403                          ixfm[3][3] = 1.;
404 <                } else if (!invmat4(ixfm, xfm))
405 <                        objerror(ob, INTERNAL, "cannot invert BSDF transform");
404 >                } else {
405 >                        if (!invmat4(ixfm, xfm))
406 >                                objerror(ob, INTERNAL,
407 >                                        "cannot invert BSDF transform");
408 >                        if (!(il->flags & IL_LIGHT))
409 >                                new_discount();
410 >                }
411                  dim[0] = random();
412                  nallow = 10*il->nsamps;
413                  for (i = 0; i < il->nsamps; i++) {
# Line 392 | Line 437 | my_face(               /* make an illum face */
437                  nalt = sqrt(il->sd->nout/PI) + .5;
438                  nazi = PI*nalt + .5;
439                  redistribute(il->sd, nalt, nazi, u, v, fa->norm, xfm);
440 +                done_discount();
441                  if (!il->sampdens)
442                          il->sampdens = nalt*nazi/PI + .999;
443          }
# Line 552 | Line 598 | my_ring(               /* make an illum ring */
598                      raysamp(dim[1], org, dir);
599                  }
600                                  /* add in direct component? */
601 <        if (!directvis && il->flags & IL_LIGHT) {
601 >        if (!directvis && (il->flags & IL_LIGHT || il->sd != NULL)) {
602                  MAT4    ixfm;
603                  if (il->sd == NULL) {
604                          for (i = 3; i--; ) {
# Line 563 | Line 609 | my_ring(               /* make an illum ring */
609                          }
610                          ixfm[3][0] = ixfm[3][1] = ixfm[3][2] = 0.;
611                          ixfm[3][3] = 1.;
612 <                } else if (!invmat4(ixfm, xfm))
613 <                        objerror(ob, INTERNAL, "cannot invert BSDF transform");
612 >                } else {
613 >                        if (!invmat4(ixfm, xfm))
614 >                                objerror(ob, INTERNAL,
615 >                                        "cannot invert BSDF transform");
616 >                        if (!(il->flags & IL_LIGHT))
617 >                                new_discount();
618 >                }
619                  dim[0] = random();
620                  for (i = 0; i < il->nsamps; i++) {
621                                          /* randomize location */
# Line 587 | Line 638 | my_ring(               /* make an illum ring */
638                  nalt = sqrt(il->sd->nout/PI) + .5;
639                  nazi = PI*nalt + .5;
640                  redistribute(il->sd, nalt, nazi, u, v, co->ad, xfm);
641 +                done_discount();
642                  if (!il->sampdens)
643                          il->sampdens = nalt*nazi/PI + .999;
644          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines