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.5 by greg, Tue May 30 20:06:09 1989 UTC vs.
Revision 1.12 by greg, Wed May 22 12:44:39 1991 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 265 | Line 278 | register RAY  *r;
278   {
279          extern int  ambcmp();
280          extern double  sin(), cos(), sqrt();
281 +        int  hlist[4];
282          double  phi, xd, yd, zd;
283          double  b, b2;
284          register AMBSAMP  *div;
# Line 299 | Line 313 | register RAY  *r;
313          fcross(ux, r->ron, uy);
314          normalize(ux);
315          fcross(uy, ux, r->ron);
316 +                                        /* set up urand */
317 +        hlist[0] = r->rno;
318                                                  /* sample divisions */
319          arad = 0.0;
320          ne = 0;
321 <        for (i = 0; i < nt; i++)
321 >        for (i = 0; i < nt; i++) {
322 >                hlist[1] = i;
323                  for (j = 0; j < np; j++) {
324                          rayorigin(&ar, r, AMBIENT, 0.5);        /* pretested */
325 <                        zd = sqrt((i+frandom())/nt);
326 <                        phi = 2.0*PI * (j+frandom())/np;
325 >                        hlist[2] = j;
326 >                        hlist[3] = 0;
327 >                        zd = sqrt((i+urand(ilhash(hlist,4)))/nt);
328 >                        hlist[3] = 1;
329 >                        phi = 2.0*PI * (j+urand(ilhash(hlist,4)))/np;
330                          xd = cos(phi) * zd;
331                          yd = sin(phi) * zd;
332                          zd = sqrt(1.0 - zd*zd);
333                          for (k = 0; k < 3; k++)
334                                  ar.rdir[k] = xd*ux[k]+yd*uy[k]+zd*r->ron[k];
335 +                        dimlist[ndims++] = i*np + j + 38813;
336                          rayvalue(&ar);
337 +                        ndims--;
338                          if (ar.rot < FHUGE)
339                                  arad += 1.0 / ar.rot;
340                          if (ns > 0) {                   /* save division */
# Line 350 | Line 372 | register RAY  *r;
372                          } else
373                                  addcolor(acol, ar.rcol);
374                  }
375 +        }
376          for (k = 0; k < ne; k++) {              /* compute errors */
377                  if (div[k].n > 1)
378                          div[k].k /= div[k].n;
# Line 365 | Line 388 | register RAY  *r;
388                                                  /* super-sample */
389          for (i = ns; i > 0; i--) {
390                  rayorigin(&ar, r, AMBIENT, 0.5);        /* pretested */
391 <                zd = sqrt((div[0].t+frandom())/nt);
392 <                phi = 2.0*PI * (div[0].p+frandom())/np;
391 >                hlist[1] = div[0].t;
392 >                hlist[2] = div[0].p;
393 >                hlist[3] = 0;
394 >                zd = sqrt((div[0].t+urand(ilhash(hlist,4)+div[0].n))/nt);
395 >                hlist[3] = 1;
396 >                phi = 2.0*PI * (div[0].p+urand(ilhash(hlist,4)+div[0].n))/np;
397                  xd = cos(phi) * zd;
398                  yd = sin(phi) * zd;
399                  zd = sqrt(1.0 - zd*zd);
400                  for (k = 0; k < 3; k++)
401                          ar.rdir[k] = xd*ux[k]+yd*uy[k]+zd*r->ron[k];
402 +                dimlist[ndims++] = div[0].t*np + div[0].p + 38813;
403                  rayvalue(&ar);
404 +                ndims--;
405 +                rayvalue(&ar);
406                  if (ar.rot < FHUGE)
407                          arad += 1.0 / ar.rot;
408                                                  /* recompute error */
# Line 385 | Line 415 | register RAY  *r;
415                  dnew.k = b2/(dnew.n*dnew.n);
416                                                  /* reinsert */
417                  for (k = 0; k < ne-1 && dnew.k < div[k+1].k; k++)
418 <                        bcopy(&div[k+1], &div[k], sizeof(AMBSAMP));
419 <                bcopy(&dnew, &div[k], sizeof(AMBSAMP));
418 >                        copystruct(&div[k], &div[k+1]);
419 >                copystruct(&div[k], &dnew);
420  
421                  if (ne >= i) {          /* extract darkest division */
422                          ne--;
# Line 431 | Line 461 | AMBVAL  *av;
461   #endif
462          if (ambfp == NULL)
463                  return;
464 <        if (fwrite(av, sizeof(AMBVAL), 1, ambfp) != 1)
464 >        if (fwrite((char *)av, sizeof(AMBVAL), 1, ambfp) != 1)
465                  goto writerr;
466   #ifdef  AMBFLUSH
467          if (++nunflshed >= AMBFLUSH) {
# Line 460 | Line 490 | double  s;
490  
491          if ((av = newambval()) == NULL)
492                  goto memerr;
493 <        bcopy(aval, av, sizeof(AMBVAL));
493 >        copystruct(av, aval);
494          VCOPY(ck0, c0);
495          while (s*(OCTSCALE/2) > av->rad*ambacc) {
496                  if (at->kid == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines