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

Comparing ray/src/rt/ambcomp.c (file contents):
Revision 2.2 by greg, Wed Feb 19 12:00:04 1992 UTC vs.
Revision 2.8 by gwlarson, Wed Dec 16 18:14:57 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4 < static char SCCSid[] = "$SunId$ LBL";
4 > static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
# Line 27 | Line 27 | typedef struct {
27          short  nt, np;          /* number of theta and phi directions */
28   }  AMBHEMI;             /* ambient sample hemisphere */
29  
30 extern double  sin(), cos(), sqrt();
30  
32
31   static int
32   ambcmp(d1, d2)                          /* decreasing order */
33   AMBSAMP  *d1, *d2;
# Line 75 | Line 73 | RAY  *r;
73          multisamp(spt, 2, urand(ilhash(hlist,3)+dp->n));
74          zd = sqrt((dp->t + spt[0])/h->nt);
75          phi = 2.0*PI * (dp->p + spt[1])/h->np;
76 <        xd = cos(phi) * zd;
77 <        yd = sin(phi) * zd;
76 >        xd = tcos(phi) * zd;
77 >        yd = tsin(phi) * zd;
78          zd = sqrt(1.0 - zd*zd);
79          for (i = 0; i < 3; i++)
80                  ar.rdir[i] =    xd*h->ux[i] +
# Line 86 | Line 84 | RAY  *r;
84          rayvalue(&ar);
85          ndims--;
86          addcolor(dp->v, ar.rcol);
87 <        if (ar.rt > FTINY && ar.rt < FHUGE)
88 <                dp->r += 1.0/ar.rt;
87 >                                        /* be conservative and use rot */
88 >        if (ar.rot > FTINY && ar.rot < FHUGE)
89 >                dp->r += 1.0/ar.rot;
90                                          /* (re)initialize error */
91          if (dp->n++) {
92                  b2 = bright(dp->v)/dp->n - bright(ar.rcol);
# Line 141 | Line 140 | FVECT  pg, dg;
140                          dp->n = 0;
141                          if (divsample(dp, &hemi, r) < 0)
142                                  goto oopsy;
143 +                        arad += dp->r;
144                          if (div != NULL)
145                                  dp++;
146 <                        else {
146 >                        else
147                                  addcolor(acol, dp->v);
148                                arad += dp->r;
149                        }
148                  }
149 <        if (ns > 0) {                   /* perform super-sampling */
149 >        if (ns > 0 && arad > FTINY && ndivs/arad < minarad)
150 >                ns = 0;                 /* close enough */
151 >        else if (ns > 0) {              /* else perform super-sampling */
152                  comperrs(div, &hemi);                   /* compute errors */
153                  qsort(div, ndivs, sizeof(AMBSAMP), ambcmp);     /* sort divs */
154                                                  /* super-sample */
# Line 170 | Line 170 | FVECT  pg, dg;
170          }
171                                          /* compute returned values */
172          if (div != NULL) {
173 +                arad = 0.0;
174                  for (i = ndivs, dp = div; i-- > 0; dp++) {
175                          arad += dp->r;
176                          if (dp->n > 1) {
# Line 207 | Line 208 | FVECT  pg, dg;
208          scalecolor(acol, b);
209          if (arad <= FTINY)
210                  arad = maxarad;
211 <        else {
211 >        else
212                  arad = (ndivs+ns)/arad;
212                if (arad > maxarad)
213                        arad = maxarad;
214        }
213          if (pg != NULL) {               /* reduce radius if gradient large */
214                  d = DOT(pg,pg);
215                  if (d*arad*arad > 1.0)
# Line 225 | Line 223 | FVECT  pg, dg;
223                                  pg[i] *= d;
224                  }
225          }
226 <        return(arad/sqrt(wt));
226 >        if ((arad /= sqrt(wt)) > maxarad)
227 >                arad = maxarad;
228 >        return(arad);
229   oopsy:
230          if (div != NULL)
231                  free((char *)div);
# Line 358 | Line 358 | register AMBHEMI  *hp;
358                  }
359                  mag0 *= 2.0*PI / hp->np;
360                  phi = 2.0*PI * (double)j/hp->np;
361 <                cosp = cos(phi); sinp = sin(phi);
361 >                cosp = tcos(phi); sinp = tsin(phi);
362                  xd += mag0*cosp - mag1*sinp;
363                  yd += mag0*sinp + mag1*cosp;
364          }
# Line 392 | Line 392 | register AMBHEMI  *hp;
392                          dp += hp->np;
393                  }
394                  phi = 2.0*PI * (j+.5)/hp->np + PI/2.0;
395 <                xd += mag * cos(phi);
396 <                yd += mag * sin(phi);
395 >                xd += mag * tcos(phi);
396 >                yd += mag * tsin(phi);
397          }
398          for (i = 0; i < 3; i++)
399                  gv[i] = (xd*hp->ux[i] + yd*hp->uy[i])/(hp->nt*hp->np);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines