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.4 by greg, Tue May 30 11:06:29 1989 UTC vs.
Revision 1.10 by greg, Tue Jun 26 09:00:07 1990 UTC

# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17  
18   #include  "octree.h"
19  
20 + #include  "otypes.h"
21 +
22   #include  "random.h"
23  
24   #define  OCTSCALE       0.5     /* ceil((valid rad.)/(cube size)) */
# Line 32 | Line 34 | extern int  ambounce;          /* number of ambient bounces */
34   extern char  *amblist[];        /* ambient include/exclude list */
35   extern int  ambincl;            /* include == 1, exclude == 0 */
36  
37 < OBJECT  ambset[128];            /* ambient include/exclude set */
37 > OBJECT  ambset[256]={0};        /* ambient include/exclude set */
38  
39   double  maxarad;                /* maximum ambient radius */
40   double  minarad;                /* minimum ambient radius */
# Line 74 | Line 76 | setambient(afile)                      /* initialize calculation */
76   char  *afile;
77   {
78          long  ftell();
77        char  **amblp;
78        OBJECT  obj;
79          AMBVAL  amb;
80 <                                        /* set up ambient set */
81 <        ambset[0] = 0;
82 <        for (amblp = amblist; *amblp != NULL; amblp++) {
83 <                if ((obj = modifier(*amblp)) == OVOID) {
84 <                        sprintf(errmsg, "unknown %s modifier \"%s\"",
85 <                                ambincl ? "include" : "exclude", *amblp);
86 <                        error(WARNING, errmsg);
87 <                        continue;
88 <                }
89 <                if (!inset(ambset, obj))
90 <                        insertelem(ambset, obj);
91 <        }
80 >
81          maxarad = thescene.cusize / 2.0;                /* maximum radius */
82                                                          /* minimum radius */
83          minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
# Line 96 | Line 85 | char  *afile;
85                                          /* open ambient file */
86          if (afile != NULL)
87                  if ((ambfp = fopen(afile, "r+")) != NULL) {
88 <                        while (fread(&amb, sizeof(AMBVAL), 1, ambfp) == 1)
88 >                        while (fread((char *)&amb,sizeof(AMBVAL),1,ambfp) == 1)
89                                  avinsert(&amb, &atrunk, thescene.cuorg,
90                                                  thescene.cusize);
91                                                          /* align */
# Line 109 | Line 98 | char  *afile;
98   }
99  
100  
101 + ambnotify(obj)                  /* record new modifier */
102 + OBJECT  obj;
103 + {
104 +        register OBJREC  *o = objptr(obj);
105 +        register char  **amblp;
106 +
107 +        if (!ismodifier(o->otype))
108 +                return;
109 +        for (amblp = amblist; *amblp != NULL; amblp++)
110 +                if (!strcmp(o->oname, *amblp)) {
111 +                        insertelem(ambset, obj);
112 +                        return;
113 +                }
114 + }
115 +
116 +
117   ambient(acol, r)                /* compute ambient component for ray */
118   COLOR  acol;
119   register RAY  *r;
# Line 203 | Line 208 | double  s;
208                   *  Jittering final test reduces image artifacts.
209                   */
210                  wt = sqrt(e1) + sqrt(e2);
211 <                if (wt > ambacc*(0.9 + 0.2*frandom()))
211 >                wt *= .9 + .2*frandom();
212 >                if (wt > ambacc)
213                          continue;
214                  if (wt <= 1e-3)
215                          wt = 1e3;
# Line 381 | Line 387 | register RAY  *r;
387                  dnew.n = div[0].n + 1;
388                  dnew.t = div[0].t; dnew.p = div[0].p;
389                  b2 = bright(dnew.v)/dnew.n - bright(ar.rcol);
390 <                b2 = b2*b2 + div[0].k*div[0].n;
391 <                dnew.k = b2/dnew.n;
390 >                b2 = b2*b2 + div[0].k*(div[0].n*div[0].n);
391 >                dnew.k = b2/(dnew.n*dnew.n);
392                                                  /* reinsert */
393                  for (k = 0; k < ne-1 && dnew.k < div[k+1].k; k++)
394 <                        bcopy(&div[k+1], &div[k], sizeof(AMBSAMP));
395 <                bcopy(&dnew, &div[k], sizeof(AMBSAMP));
394 >                        copystruct(&div[k], &div[k+1]);
395 >                copystruct(&div[k], &dnew);
396  
397                  if (ne >= i) {          /* extract darkest division */
398                          ne--;
# Line 431 | Line 437 | AMBVAL  *av;
437   #endif
438          if (ambfp == NULL)
439                  return;
440 <        if (fwrite(av, sizeof(AMBVAL), 1, ambfp) != 1)
440 >        if (fwrite((char *)av, sizeof(AMBVAL), 1, ambfp) != 1)
441                  goto writerr;
442   #ifdef  AMBFLUSH
443          if (++nunflshed >= AMBFLUSH) {
# Line 460 | Line 466 | double  s;
466  
467          if ((av = newambval()) == NULL)
468                  goto memerr;
469 <        bcopy(aval, av, sizeof(AMBVAL));
469 >        copystruct(av, aval);
470          VCOPY(ck0, c0);
471          while (s*(OCTSCALE/2) > av->rad*ambacc) {
472                  if (at->kid == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines