ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ambcomp.c
(Generate patch)

Comparing ray/src/rt/ambcomp.c (file contents):
Revision 2.35 by greg, Fri Apr 25 18:39:22 2014 UTC vs.
Revision 2.40 by greg, Wed Apr 30 18:27:14 2014 UTC

# Line 70 | Line 70 | inithemi(                      /* initialize sampling hemisphere */
70          d = 1.0/(n*n);
71          scalecolor(hp->acoef, d);
72                                          /* make tangent plane axes */
73 <        hp->uy[0] = 0.1 - 0.2*frandom();
74 <        hp->uy[1] = 0.1 - 0.2*frandom();
75 <        hp->uy[2] = 0.1 - 0.2*frandom();
76 <        for (i = 0; i < 3; i++)
77 <                if (r->ron[i] < 0.6 && r->ron[i] > -0.6)
73 >        hp->uy[0] = 0.5 - frandom();
74 >        hp->uy[1] = 0.5 - frandom();
75 >        hp->uy[2] = 0.5 - frandom();
76 >        for (i = 3; i--; )
77 >                if ((-0.6 < r->ron[i]) & (r->ron[i] < 0.6))
78                          break;
79 <        if (i >= 3)
80 <                error(CONSISTENCY, "bad ray direction in inithemi()");
79 >        if (i < 0)
80 >                error(CONSISTENCY, "bad ray direction in inithemi");
81          hp->uy[i] = 1.0;
82          VCROSS(hp->ux, hp->uy, r->ron);
83          normalize(hp->ux);
# Line 319 | Line 319 | eigenvectors(FVECT uv[2], float ra[2], FVECT hessian[3
319          hess2[0][1] = DOT(uv[0], b);
320          hess2[1][0] = DOT(uv[1], a);
321          hess2[1][1] = DOT(uv[1], b);
322 <                                        /* compute eigenvalues */
323 <        if ( quadratic(evalue, 1.0, -hess2[0][0]-hess2[1][1],
324 <                        hess2[0][0]*hess2[1][1]-hess2[0][1]*hess2[1][0]) != 2 ||
325 <                        ((evalue[0] = fabs(evalue[0])) <= FTINY*FTINY) |
322 >                                        /* compute eigenvalue(s) */
323 >        i = quadratic(evalue, 1.0, -hess2[0][0]-hess2[1][1],
324 >                        hess2[0][0]*hess2[1][1]-hess2[0][1]*hess2[1][0]);
325 >        if (i == 1)                     /* double-root (circle) */
326 >                evalue[1] = evalue[0];
327 >        if (!i || ((evalue[0] = fabs(evalue[0])) <= FTINY*FTINY) |
328                          ((evalue[1] = fabs(evalue[1])) <= FTINY*FTINY) )
329                  error(INTERNAL, "bad eigenvalue calculation");
330  
# Line 414 | Line 416 | ambHessian(                            /* anisotropic radii & pos. gradient */
416                      rev_hessian(hesscol);
417                      add2hessian(hessian, hessrow[j], hessdia, hesscol, backg);
418                  }
419 <                if (gradient != NULL) {
419 >                if (gradrow != NULL) {
420                      comp_gradient(graddia, &fftr, hp->rp->ron);
421                      rev_gradient(gradcol);
422                      add2gradient(gradient, gradrow[j], graddia, gradcol, backg);
# Line 476 | Line 478 | ambdirgrad(AMBHEMI *hp, FVECT uv[2], float dg[2])
478                  VSUB(vd, ap->p, hp->rp->rop);
479                                          /* brightness over cosine factor */
480                  gfact = colval(ap->v,CIEY) / DOT(hp->rp->ron, vd);
481 <                                        /* -sine = -proj_radius/vd_length */
482 <                dgsum[0] += DOT(uv[1], vd) * gfact;
483 <                dgsum[1] -= DOT(uv[0], vd) * gfact;
481 >                                        /* sine = proj_radius/vd_length */
482 >                dgsum[0] -= DOT(uv[1], vd) * gfact;
483 >                dgsum[1] += DOT(uv[0], vd) * gfact;
484          }
485          dg[0] = dgsum[0] / (hp->ns*hp->ns);
486          dg[1] = dgsum[1] / (hp->ns*hp->ns);
# Line 499 | Line 501 | doambient(                             /* compute ambient component */
501          AMBHEMI                 *hp = inithemi(rcol, r, wt);
502          int                     cnt = 0;
503          FVECT                   my_uv[2];
504 <        double                  d, acol[3];
504 >        double                  d, K, acol[3];
505          struct s_ambsamp        *ap;
506          int                     i, j;
507                                          /* check/initialize */
# Line 532 | Line 534 | doambient(                             /* compute ambient component */
534                  free(hp);
535                  return(-1);             /* no radius or gradient calc. */
536          }
537 <        if (bright(acol) > FTINY)       /* normalize Y values */
538 <                d = cnt/bright(acol);
539 <        else
537 >        if (bright(acol) > FTINY) {     /* normalize Y values */
538 >                d = 0.99*cnt/bright(acol);
539 >                K = 0.01;
540 >        } else {                        /* geometric Hessian fall-back */
541                  d = 0.0;
542 +                K = 1.0;
543 +                pg = NULL;
544 +                dg = NULL;
545 +        }
546          ap = hp->sa;                    /* relative Y channel from here on... */
547          for (i = hp->ns*hp->ns; i--; ap++)
548 <                colval(ap->v,CIEY) = bright(ap->v)*d + 0.01;
548 >                colval(ap->v,CIEY) = bright(ap->v)*d + K;
549  
550          if (uv == NULL)                 /* make sure we have axis pointers */
551                  uv = my_uv;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines