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.1 by greg, Thu Feb 2 10:41:17 1989 UTC vs.
Revision 1.9 by greg, Fri Jan 19 00:00:05 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;
79          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 +        register OBJREC  *o = objptr(obj);
106 +        register char  **amblp;
107 +
108 +        if (!ismodifier(o->otype))
109 +                return;
110 +        for (amblp = amblist; *amblp != NULL; amblp++)
111 +                if (!strcmp(o->oname, *amblp)) {
112 +                        insertelem(ambset, obj);
113 +                        return;
114 +                }
115 + }
116 +
117 +
118   ambient(acol, r)                /* compute ambient component for ray */
119   COLOR  acol;
120   register RAY  *r;
# Line 203 | Line 209 | double  s;
209                   *  Jittering final test reduces image artifacts.
210                   */
211                  wt = sqrt(e1) + sqrt(e2);
212 <                if (wt > ambacc*(0.9 + 0.2*frandom()))
212 >                wt *= .9 + .2*frandom();
213 >                if (wt > ambacc)
214                          continue;
215                  if (wt <= 1e-3)
216                          wt = 1e3;
# Line 221 | Line 228 | double  s;
228          for (i = 0; i < 8; i++) {
229                  for (j = 0; j < 3; j++) {
230                          ck0[j] = c0[j];
231 <                        if (1<<j & i) {
231 >                        if (1<<j & i)
232                                  ck0[j] += s;
233 <                                if (r->rop[j] < ck0[j] - OCTSCALE*s)
234 <                                        break;
235 <                        } else
236 <                                if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s)
230 <                                        break;
233 >                        if (r->rop[j] < ck0[j] - OCTSCALE*s)
234 >                                break;
235 >                        if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s)
236 >                                break;
237                  }
238                  if (j == 3)
239                          wsum += sumambient(acol, r, at->kid+i, ck0, s);
# Line 267 | Line 273 | register RAY  *r;
273          extern int  ambcmp();
274          extern double  sin(), cos(), sqrt();
275          double  phi, xd, yd, zd;
276 +        double  b, b2;
277          register AMBSAMP  *div;
278          AMBSAMP  dnew;
279          RAY  ar;
# Line 321 | Line 328 | register RAY  *r;
328                                  div[ne].n = 0;
329                                  div[ne].t = i; div[ne].p = j;
330                                                          /* sum errors */
331 <                                xd = bright(ar.rcol);
331 >                                b = bright(ar.rcol);
332                                  if (i > 0) {            /* from above */
333 <                                        yd = bright(div[ne-np].v) - xd;
334 <                                        yd *= yd * 0.25;
335 <                                        div[ne].k += yd;
333 >                                        b2 = bright(div[ne-np].v) - b;
334 >                                        b2 *= b2 * 0.25;
335 >                                        div[ne].k += b2;
336                                          div[ne].n++;
337 <                                        div[ne-np].k += yd;
337 >                                        div[ne-np].k += b2;
338                                          div[ne-np].n++;
339                                  }
340                                  if (j > 0) {            /* from behind */
341 <                                        yd = bright(div[ne-1].v) - xd;
342 <                                        yd *= yd * 0.25;
343 <                                        div[ne].k += yd;
341 >                                        b2 = bright(div[ne-1].v) - b;
342 >                                        b2 *= b2 * 0.25;
343 >                                        div[ne].k += b2;
344                                          div[ne].n++;
345 <                                        div[ne-1].k += yd;
345 >                                        div[ne-1].k += b2;
346                                          div[ne-1].n++;
347                                  }
348                                  if (j == np-1) {        /* around */
349 <                                        yd = bright(div[ne-(np-1)].v) - xd;
350 <                                        yd *= yd * 0.25;
351 <                                        div[ne].k += yd;
349 >                                        b2 = bright(div[ne-(np-1)].v) - b;
350 >                                        b2 *= b2 * 0.25;
351 >                                        div[ne].k += b2;
352                                          div[ne].n++;
353 <                                        div[ne-(np-1)].k += yd;
353 >                                        div[ne-(np-1)].k += b2;
354                                          div[ne-(np-1)].n++;
355                                  }
356                                  ne++;
# Line 380 | Line 387 | register RAY  *r;
387                  addcolor(dnew.v, ar.rcol);
388                  dnew.n = div[0].n + 1;
389                  dnew.t = div[0].t; dnew.p = div[0].p;
390 <                yd = bright(dnew.v)/dnew.n - bright(ar.rcol);
391 <                yd = yd*yd + div[0].k*(div[0].n*div[0].n);
392 <                dnew.k = yd/(dnew.n*dnew.n);
390 >                b2 = bright(dnew.v)/dnew.n - bright(ar.rcol);
391 >                b2 = b2*b2 + div[0].k*(div[0].n*div[0].n);
392 >                dnew.k = b2/(dnew.n*dnew.n);
393                                                  /* reinsert */
394                  for (k = 0; k < ne-1 && dnew.k < div[k+1].k; k++)
395 <                        bcopy(&div[k+1], &div[k], sizeof(AMBSAMP));
396 <                bcopy(&dnew, &div[k], sizeof(AMBSAMP));
395 >                        copystruct(&div[k], &div[k+1]);
396 >                copystruct(&div[k], &dnew);
397  
398                  if (ne >= i) {          /* extract darkest division */
399                          ne--;
# Line 431 | Line 438 | AMBVAL  *av;
438   #endif
439          if (ambfp == NULL)
440                  return;
441 <        if (fwrite(av, sizeof(AMBVAL), 1, ambfp) != 1)
441 >        if (fwrite((char *)av, sizeof(AMBVAL), 1, ambfp) != 1)
442                  goto writerr;
443   #ifdef  AMBFLUSH
444          if (++nunflshed >= AMBFLUSH) {
# Line 460 | Line 467 | double  s;
467  
468          if ((av = newambval()) == NULL)
469                  goto memerr;
470 <        bcopy(aval, av, sizeof(AMBVAL));
470 >        copystruct(av, aval);
471          VCOPY(ck0, c0);
472          while (s*(OCTSCALE/2) > av->rad*ambacc) {
473                  if (at->kid == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines