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

Comparing ray/src/rt/ambient.c (file contents):
Revision 1.15 by greg, Thu Jun 13 09:41:15 1991 UTC vs.
Revision 1.16 by greg, Tue Aug 20 10:05:18 1991 UTC

# Line 100 | Line 100 | COLOR  acol;
100   register RAY  *r;
101   {
102          static int  rdepth = 0;                 /* ambient recursion */
103 <        double  wsum;
103 >        double  d;
104  
105        rdepth++;                               /* increment level */
106
105          if (ambdiv <= 0)                        /* no ambient calculation */
106                  goto dumbamb;
107                                                  /* check number of bounces */
108 <        if (rdepth > ambounce)
108 >        if (rdepth >= ambounce)
109                  goto dumbamb;
110                                                  /* check ambient list */
111          if (ambincl != -1 && r->ro != NULL &&
# Line 115 | Line 113 | register RAY  *r;
113                  goto dumbamb;
114  
115          if (ambacc <= FTINY) {                  /* no ambient storage */
116 <                if (doambient(acol, r, NULL, NULL) == 0.0)
116 >                rdepth++;
117 >                d = doambient(acol, r, r->rweight, NULL, NULL);
118 >                rdepth--;
119 >                if (d == 0.0)
120                          goto dumbamb;
121 <                goto done;
121 >                return;
122          }
123                                                  /* get ambient value */
124          setcolor(acol, 0.0, 0.0, 0.0);
125 <        wsum = sumambient(acol, r, &atrunk, thescene.cuorg, thescene.cusize);
126 <        if (wsum > FTINY)
127 <                scalecolor(acol, 1.0/wsum);
128 <        else if (makeambient(acol, r) == 0.0)
129 <                goto dumbamb;
130 <        goto done;
131 <
125 >        d = sumambient(acol, r, rdepth,
126 >                        &atrunk, thescene.cuorg, thescene.cusize);
127 >        if (d > FTINY)
128 >                scalecolor(acol, 1.0/d);
129 >        else {
130 >                d = makeambient(acol, r, rdepth++);
131 >                rdepth--;
132 >        }
133 >        if (d > FTINY)
134 >                return;
135   dumbamb:                                        /* return global value */
136          copycolor(acol, ambval);
133 done:                                           /* must finish here! */
134        rdepth--;
137   }
138  
139  
140   double
141 < sumambient(acol, r, at, c0, s)          /* get interpolated ambient value */
141 > sumambient(acol, r, al, at, c0, s)      /* get interpolated ambient value */
142   COLOR  acol;
143   register RAY  *r;
144 + int  al;
145   AMBTREE  *at;
146   FVECT  c0;
147   double  s;
# Line 154 | Line 157 | double  s;
157          wsum = 0.0;
158          for (av = at->alist; av != NULL; av = av->next) {
159                  /*
160 <                 *  Ray strength test.
160 >                 *  Ambient level test.
161                   */
162 <                if (av->lvl > r->rlvl || av->weight < r->rweight-FTINY)
162 >                if (av->lvl > al || av->weight < r->rweight-FTINY)
163                          continue;
164                  /*
165                   *  Ambient radius test.
# Line 216 | Line 219 | double  s;
219                                  break;
220                  }
221                  if (j == 3)
222 <                        wsum += sumambient(acol, r, at->kid+i, ck0, s);
222 >                        wsum += sumambient(acol, r, al, at->kid+i, ck0, s);
223          }
224          return(wsum);
225   }
226  
227  
228   double
229 < makeambient(acol, r)            /* make a new ambient value */
229 > makeambient(acol, r, al)        /* make a new ambient value */
230   COLOR  acol;
231   register RAY  *r;
232 + int  al;
233   {
234          AMBVAL  amb;
235          FVECT   gp, gd;
236 <
237 <        amb.rad = doambient(acol, r, gp, gd);   /* compute ambient */
236 >                                                /* compute weight */
237 >        amb.weight = pow(AVGREFL, (double)al);
238 >        if (r->rweight < 0.1*amb.weight)        /* heuristic */
239 >                amb.weight = r->rweight;
240 >                                                /* compute ambient */
241 >        amb.rad = doambient(acol, r, amb.weight, gp, gd);
242          if (amb.rad == 0.0)
243                  return(0.0);
244                                                  /* store it */
245          VCOPY(amb.pos, r->rop);
246          VCOPY(amb.dir, r->ron);
247 <        amb.lvl = r->rlvl;
240 <        amb.weight = r->rweight;
247 >        amb.lvl = al;
248          copycolor(amb.val, acol);
249          VCOPY(amb.gpos, gp);
250          VCOPY(amb.gdir, gd);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines