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.6 by greg, Tue Aug 8 17:31:23 1989 UTC

# Line 21 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21  
22   #define  OCTSCALE       0.5     /* ceil((valid rad.)/(cube size)) */
23  
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 164 | Line 166 | double  s;
166          int  i;
167          register int  j;
168          register AMBVAL  *av;
169 <                                        /* do this node */
169 >
170          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 */
191          for (av = at->alist; av != NULL; av = av->next) {
192                  /*
193                   *  Ray strength test.
# Line 203 | Line 225 | double  s;
225                   *  Jittering final test reduces image artifacts.
226                   */
227                  wt = sqrt(e1) + sqrt(e2);
228 <                if (wt > ambacc*(0.9 + 0.2*frandom()))
228 >                wt *= 0.9 + 0.2*frandom();
229 >                if (wt > ambacc)
230                          continue;
231                  if (wt <= 1e-3)
232                          wt = 1e3;
# Line 214 | Line 237 | double  s;
237                  scalecolor(ct, wt);
238                  addcolor(acol, ct);
239          }
217        if (at->kid == NULL)
218                return(wsum);
219                                        /* do children */
220        s *= 0.5;
221        for (i = 0; i < 8; i++) {
222                for (j = 0; j < 3; j++) {
223                        ck0[j] = c0[j];
224                        if (1<<j & i) {
225                                ck0[j] += s;
226                                if (r->rop[j] < ck0[j] - OCTSCALE*s)
227                                        break;
228                        } else
229                                if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s)
230                                        break;
231                }
232                if (j == 3)
233                        wsum += sumambient(acol, r, at->kid+i, ck0, s);
234        }
240          return(wsum);
241   }
242  
# Line 267 | Line 272 | register RAY  *r;
272          extern int  ambcmp();
273          extern double  sin(), cos(), sqrt();
274          double  phi, xd, yd, zd;
275 +        double  b, b2;
276          register AMBSAMP  *div;
277          AMBSAMP  dnew;
278          RAY  ar;
# Line 321 | Line 327 | register RAY  *r;
327                                  div[ne].n = 0;
328                                  div[ne].t = i; div[ne].p = j;
329                                                          /* sum errors */
330 <                                xd = bright(ar.rcol);
330 >                                b = bright(ar.rcol);
331                                  if (i > 0) {            /* from above */
332 <                                        yd = bright(div[ne-np].v) - xd;
333 <                                        yd *= yd * 0.25;
334 <                                        div[ne].k += yd;
332 >                                        b2 = bright(div[ne-np].v) - b;
333 >                                        b2 *= b2 * 0.25;
334 >                                        div[ne].k += b2;
335                                          div[ne].n++;
336 <                                        div[ne-np].k += yd;
336 >                                        div[ne-np].k += b2;
337                                          div[ne-np].n++;
338                                  }
339                                  if (j > 0) {            /* from behind */
340 <                                        yd = bright(div[ne-1].v) - xd;
341 <                                        yd *= yd * 0.25;
342 <                                        div[ne].k += yd;
340 >                                        b2 = bright(div[ne-1].v) - b;
341 >                                        b2 *= b2 * 0.25;
342 >                                        div[ne].k += b2;
343                                          div[ne].n++;
344 <                                        div[ne-1].k += yd;
344 >                                        div[ne-1].k += b2;
345                                          div[ne-1].n++;
346                                  }
347                                  if (j == np-1) {        /* around */
348 <                                        yd = bright(div[ne-(np-1)].v) - xd;
349 <                                        yd *= yd * 0.25;
350 <                                        div[ne].k += yd;
348 >                                        b2 = bright(div[ne-(np-1)].v) - b;
349 >                                        b2 *= b2 * 0.25;
350 >                                        div[ne].k += b2;
351                                          div[ne].n++;
352 <                                        div[ne-(np-1)].k += yd;
352 >                                        div[ne-(np-1)].k += b2;
353                                          div[ne-(np-1)].n++;
354                                  }
355                                  ne++;
# Line 380 | Line 386 | register RAY  *r;
386                  addcolor(dnew.v, ar.rcol);
387                  dnew.n = div[0].n + 1;
388                  dnew.t = div[0].t; dnew.p = div[0].p;
389 <                yd = bright(dnew.v)/dnew.n - bright(ar.rcol);
390 <                yd = yd*yd + div[0].k*(div[0].n*div[0].n);
391 <                dnew.k = yd/(dnew.n*dnew.n);
389 >                b2 = bright(dnew.v)/dnew.n - bright(ar.rcol);
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));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines