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 2.32 by greg, Tue Oct 17 18:22:47 1995 UTC vs.
Revision 2.34 by greg, Mon Nov 6 12:03:13 1995 UTC

# Line 109 | Line 109 | int  ar;
109   setambacc(newa)                         /* set ambient accuracy */
110   double  newa;
111   {
112 <        static double  oldambacc = -1.0;
112 >        double  ambdiff;
113  
114 <        ambacc = newa < 0.0 ? 0.0 : newa;       /* may be done already */
115 <        if (oldambacc < -FTINY)
116 <                oldambacc = ambacc;     /* do nothing first call */
117 <        if (fabs(newa - oldambacc) < 0.01)
118 <                return;                 /* insignificant -- don't bother */
119 <        if (ambacc <= FTINY)
120 <                return;                 /* cannot build new tree */
121 <                                        /* else need to rebuild tree */
122 <        sortambvals(1);
123 <        oldambacc = ambacc;             /* remeber setting for next call */
114 >        if (newa < 0.0)
115 >                newa = 0.0;
116 >        ambdiff = fabs(newa - ambacc);
117 >        if (ambdiff >= .01 && (ambacc = newa) > FTINY && nambvals > 0)
118 >                sortambvals(1);                 /* rebuild tree */
119   }
120  
121  
# Line 181 | Line 176 | OBJECT obj;
176   }
177  
178  
179 < ambient(acol, r)                /* compute ambient component for ray */
179 > ambient(acol, r, nrm)           /* compute ambient component for ray */
180   COLOR  acol;
181   register RAY  *r;
182 + FVECT  nrm;
183   {
184          static int  rdepth = 0;                 /* ambient recursion */
185          double  d;
# Line 210 | Line 206 | register RAY  *r;
206          sortambvals(0);
207                                                  /* get ambient value */
208          setcolor(acol, 0.0, 0.0, 0.0);
209 <        d = sumambient(acol, r, rdepth,
209 >        d = sumambient(acol, r, nrm, rdepth,
210                          &atrunk, thescene.cuorg, thescene.cusize);
211          if (d > FTINY) {
212                  scalecolor(acol, 1.0/d);
213                  return;
214          }
215 <        rdepth++;
216 <        d = makeambient(acol, r, rdepth-1);
215 >        rdepth++;                               /* need to cache new value */
216 >        d = makeambient(acol, r, nrm, rdepth-1);
217          rdepth--;
218          if (d > FTINY)
219                  return;
# Line 235 | Line 231 | dumbamb:                                       /* return global value */
231  
232  
233   double
234 < sumambient(acol, r, al, at, c0, s)      /* get interpolated ambient value */
234 > sumambient(acol, r, rn, al, at, c0, s)  /* get interpolated ambient value */
235   COLOR  acol;
236   register RAY  *r;
237 + FVECT  rn;
238   int  al;
239   AMBTREE  *at;
240   FVECT  c0;
# Line 301 | Line 298 | double s;
298                  else
299                          wt = 1.0 / wt;
300                  wsum += wt;
301 <                extambient(ct, av, r->rop, r->ron);
301 >                extambient(ct, av, r->rop, rn);
302                  scalecolor(ct, wt);
303                  addcolor(acol, ct);
304          }
# Line 320 | Line 317 | double s;
317                                  break;
318                  }
319                  if (j == 3)
320 <                        wsum += sumambient(acol, r, al, at->kid+i, ck0, s);
320 >                        wsum += sumambient(acol, r, rn, al, at->kid+i, ck0, s);
321          }
322          return(wsum);
323   }
324  
325  
326   double
327 < makeambient(acol, r, al)        /* make a new ambient value */
327 > makeambient(acol, r, rn, al)    /* make a new ambient value */
328   COLOR  acol;
329   register RAY  *r;
330 + FVECT  rn;
331   int  al;
332   {
333          AMBVAL  amb;
334          FVECT   gp, gd;
335                                                  /* compute weight */
336          amb.weight = pow(AVGREFL, (double)al);
337 <        if (r->rweight < 0.2*amb.weight)        /* heuristic */
337 >        if (r->rweight < 0.1*amb.weight)        /* heuristic */
338                  amb.weight = r->rweight;
339                                                  /* compute ambient */
340          amb.rad = doambient(acol, r, amb.weight, gp, gd);
341 <        if (amb.rad == 0.0)
341 >        if (amb.rad <= FTINY)
342                  return(0.0);
343                                                  /* store it */
344          VCOPY(amb.pos, r->rop);
# Line 351 | Line 349 | int  al;
349          VCOPY(amb.gdir, gd);
350                                                  /* insert into tree */
351          avsave(&amb);                           /* and save to file */
352 +        if (rn != r->ron)
353 +                extambient(acol, &amb, r->rop, rn);     /* texture */
354          return(amb.rad);
355   }
356  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines