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.3 by greg, Fri May 26 17:58:01 1989 UTC vs.
Revision 1.11 by greg, Fri Sep 7 08:17:42 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 > #define  MAXASET        511     /* maximum number of elements in ambient set */
38 > OBJECT  ambset[MAXASET+1]={0};  /* ambient include/exclude set */
39  
40   double  maxarad;                /* maximum ambient radius */
41   double  minarad;                /* minimum ambient radius */
# Line 74 | Line 77 | setambient(afile)                      /* initialize calculation */
77   char  *afile;
78   {
79          long  ftell();
77        char  **amblp;
78        OBJECT  obj;
80          AMBVAL  amb;
81 <                                        /* 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 <        }
81 >
82          maxarad = thescene.cusize / 2.0;                /* maximum radius */
83                                                          /* minimum radius */
84          minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
# Line 96 | Line 86 | char  *afile;
86                                          /* open ambient file */
87          if (afile != NULL)
88                  if ((ambfp = fopen(afile, "r+")) != NULL) {
89 <                        while (fread(&amb, sizeof(AMBVAL), 1, ambfp) == 1)
89 >                        while (fread((char *)&amb,sizeof(AMBVAL),1,ambfp) == 1)
90                                  avinsert(&amb, &atrunk, thescene.cuorg,
91                                                  thescene.cusize);
92                                                          /* align */
# Line 109 | Line 99 | char  *afile;
99   }
100  
101  
102 + ambnotify(obj)                  /* record new modifier */
103 + OBJECT  obj;
104 + {
105 +        static int  hitlimit = 0;
106 +        register OBJREC  *o = objptr(obj);
107 +        register char  **amblp;
108 +
109 +        if (hitlimit || !ismodifier(o->otype))
110 +                return;
111 +        for (amblp = amblist; *amblp != NULL; amblp++)
112 +                if (!strcmp(o->oname, *amblp)) {
113 +                        if (ambset[0] >= MAXASET) {
114 +                                error(WARNING, "too many modifiers in ambient list");
115 +                                hitlimit++;
116 +                                return;         /* should this be fatal? */
117 +                        }
118 +                        insertelem(ambset, obj);
119 +                        return;
120 +                }
121 + }
122 +
123 +
124   ambient(acol, r)                /* compute ambient component for ray */
125   COLOR  acol;
126   register RAY  *r;
# Line 203 | Line 215 | double  s;
215                   *  Jittering final test reduces image artifacts.
216                   */
217                  wt = sqrt(e1) + sqrt(e2);
218 <                if (wt > ambacc*(0.9 + 0.2*frandom()))
218 >                wt *= .9 + .2*frandom();
219 >                if (wt > ambacc)
220                          continue;
221                  if (wt <= 1e-3)
222                          wt = 1e3;
# Line 385 | Line 398 | register RAY  *r;
398                  dnew.k = b2/(dnew.n*dnew.n);
399                                                  /* reinsert */
400                  for (k = 0; k < ne-1 && dnew.k < div[k+1].k; k++)
401 <                        bcopy(&div[k+1], &div[k], sizeof(AMBSAMP));
402 <                bcopy(&dnew, &div[k], sizeof(AMBSAMP));
401 >                        copystruct(&div[k], &div[k+1]);
402 >                copystruct(&div[k], &dnew);
403  
404                  if (ne >= i) {          /* extract darkest division */
405                          ne--;
# Line 431 | Line 444 | AMBVAL  *av;
444   #endif
445          if (ambfp == NULL)
446                  return;
447 <        if (fwrite(av, sizeof(AMBVAL), 1, ambfp) != 1)
447 >        if (fwrite((char *)av, sizeof(AMBVAL), 1, ambfp) != 1)
448                  goto writerr;
449   #ifdef  AMBFLUSH
450          if (++nunflshed >= AMBFLUSH) {
# Line 460 | Line 473 | double  s;
473  
474          if ((av = newambval()) == NULL)
475                  goto memerr;
476 <        bcopy(aval, av, sizeof(AMBVAL));
476 >        copystruct(av, aval);
477          VCOPY(ck0, c0);
478          while (s*(OCTSCALE/2) > av->rad*ambacc) {
479                  if (at->kid == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines