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.6 by greg, Tue Aug 8 17:31:23 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)) */
25  
24 #define  WDONE          4       /* stop if wsum/wmin is at or above */
25
26   extern CUBE  thescene;          /* contains space boundaries */
27  
28   extern COLOR  ambval;           /* global ambient component */
# Line 34 | 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 76 | Line 76 | setambient(afile)                      /* initialize calculation */
76   char  *afile;
77   {
78          long  ftell();
79        char  **amblp;
80        OBJECT  obj;
79          AMBVAL  amb;
80 <                                        /* set up ambient set */
83 <        ambset[0] = 0;
84 <        for (amblp = amblist; *amblp != NULL; amblp++) {
85 <                if ((obj = modifier(*amblp)) == OVOID) {
86 <                        sprintf(errmsg, "unknown %s modifier \"%s\"",
87 <                                ambincl ? "include" : "exclude", *amblp);
88 <                        error(WARNING, errmsg);
89 <                        continue;
90 <                }
91 <                if (!inset(ambset, obj))
92 <                        insertelem(ambset, obj);
93 <        }
80 >
81          maxarad = thescene.cusize / 2.0;                /* maximum radius */
82                                                          /* minimum radius */
83          minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
# Line 98 | 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 111 | 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 166 | Line 169 | double  s;
169          int  i;
170          register int  j;
171          register AMBVAL  *av;
172 <
172 >                                        /* do this node */
173          wsum = 0.0;
171                                        /* check children first */
172        if (at->kid != NULL) {
173                s *= 0.5;
174                for (i = 0; i < 8; i++) {
175                        for (j = 0; j < 3; j++) {
176                                ck0[j] = c0[j];
177                                if (1<<j & i)
178                                        ck0[j] += s;
179                                if (r->rop[j] < ck0[j] - OCTSCALE*s)
180                                        break;
181                                if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s)
182                                        break;
183                        }
184                        if (j == 3)
185                                wsum += sumambient(acol, r, at->kid+i, ck0, s);
186                }
187                if (wsum*ambacc >= WDONE)
188                        return(wsum);           /* close enough */
189        }
190                                        /* check this node */
174          for (av = at->alist; av != NULL; av = av->next) {
175                  /*
176                   *  Ray strength test.
# Line 225 | Line 208 | double  s;
208                   *  Jittering final test reduces image artifacts.
209                   */
210                  wt = sqrt(e1) + sqrt(e2);
211 <                wt *= 0.9 + 0.2*frandom();
211 >                wt *= .9 + .2*frandom();
212                  if (wt > ambacc)
213                          continue;
214                  if (wt <= 1e-3)
# Line 237 | Line 220 | double  s;
220                  scalecolor(ct, wt);
221                  addcolor(acol, ct);
222          }
223 +        if (at->kid == NULL)
224 +                return(wsum);
225 +                                        /* do children */
226 +        s *= 0.5;
227 +        for (i = 0; i < 8; i++) {
228 +                for (j = 0; j < 3; j++) {
229 +                        ck0[j] = c0[j];
230 +                        if (1<<j & i)
231 +                                ck0[j] += s;
232 +                        if (r->rop[j] < ck0[j] - OCTSCALE*s)
233 +                                break;
234 +                        if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s)
235 +                                break;
236 +                }
237 +                if (j == 3)
238 +                        wsum += sumambient(acol, r, at->kid+i, ck0, s);
239 +        }
240          return(wsum);
241   }
242  
# Line 391 | Line 391 | register RAY  *r;
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 437 | 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 466 | 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