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

Comparing ray/src/rt/normal.c (file contents):
Revision 2.62 by greg, Sun Jul 29 19:01:39 2012 UTC vs.
Revision 2.68 by greg, Thu Dec 4 05:26:28 2014 UTC

# Line 65 | Line 65 | typedef struct {
65          double  pdot;           /* perturbed dot product */
66   }  NORMDAT;             /* normal material data */
67  
68 < static void gaussamp(RAY  *r, NORMDAT  *np);
68 > static void gaussamp(NORMDAT  *np);
69  
70  
71   static void
# Line 188 | Line 188 | m_normal(                      /* color a ray that hit something normal *
188                  objerror(m, USER, "bad number of arguments");
189                                                  /* check for back side */
190          if (r->rod < 0.0) {
191 <                if (!backvis && m->otype != MAT_TRANS) {
191 >                if (!backvis) {
192                          raytrans(r);
193                          return(1);
194                  }
# Line 239 | Line 239 | m_normal(                      /* color a ray that hit something normal *
239                          if (!(nd.specfl & SP_PURE) &&
240                                          specthresh >= nd.tspec-FTINY)
241                                  nd.specfl |= SP_TBLT;
242 <                        if (!hastexture || r->crtype & SHADOW) {
242 >                        if (!hastexture || r->crtype & (SHADOW|AMBIENT)) {
243                                  VCOPY(nd.prdir, r->rdir);
244                                  transtest = 2;
245                          } else {
# Line 280 | Line 280 | m_normal(                      /* color a ray that hit something normal *
280                  if (m->otype != MAT_METAL) {
281                          setcolor(nd.scolor, nd.rspec, nd.rspec, nd.rspec);
282                  } else if (fest > FTINY) {
283 <                        d = nd.rspec*(1. - fest);
283 >                        d = m->oargs.farg[3]*(1. - fest);
284                          for (i = 0; i < 3; i++)
285 <                                nd.scolor[i] = fest + nd.mcolor[i]*d;
285 >                                colval(nd.scolor,i) = fest +
286 >                                                colval(nd.mcolor,i)*d;
287                  } else {
288                          copycolor(nd.scolor, nd.mcolor);
289                          scalecolor(nd.scolor, nd.rspec);
# Line 305 | Line 306 | m_normal(                      /* color a ray that hit something normal *
306                          rayvalue(&lr);
307                          multcolor(lr.rcol, lr.rcoef);
308                          addcolor(r->rcol, lr.rcol);
309 <                        if (!hastexture && nd.specfl & SP_FLAT) {
309 >                        if (nd.specfl & SP_FLAT &&
310 >                                        !hastexture | (r->crtype & AMBIENT)) {
311                                  mirtest = 2.*bright(lr.rcol);
312                                  mirdist = r->rot + lr.rt;
313                          }
# Line 318 | Line 320 | m_normal(                      /* color a ray that hit something normal *
320                  return(1);                      /* 100% pure specular */
321  
322          if (!(nd.specfl & SP_PURE))
323 <                gaussamp(r, &nd);               /* checks *BLT flags */
323 >                gaussamp(&nd);          /* checks *BLT flags */
324  
325          if (nd.rdiff > FTINY) {         /* ambient from this side */
326                  copycolor(ctmp, nd.mcolor);     /* modified by material color */
# Line 361 | Line 363 | m_normal(                      /* color a ray that hit something normal *
363  
364   static void
365   gaussamp(                       /* sample Gaussian specular */
364        RAY  *r,
366          NORMDAT  *np
367   )
368   {
# Line 377 | Line 378 | gaussamp(                      /* sample Gaussian specular */
378                          (np->specfl & (SP_TRAN|SP_TBLT)) != SP_TRAN)
379                  return;
380                                          /* set up sample coordinates */
381 <        v[0] = v[1] = v[2] = 0.0;
381 <        for (i = 0; i < 3; i++)
382 <                if (np->pnorm[i] < 0.6 && np->pnorm[i] > -0.6)
383 <                        break;
384 <        v[i] = 1.0;
385 <        fcross(u, v, np->pnorm);
386 <        normalize(u);
381 >        getperpendicular(u, np->pnorm);
382          fcross(v, np->pnorm, u);
383                                          /* compute reflection */
384          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
385 <                        rayorigin(&sr, SPECULAR, r, np->scolor) == 0) {
385 >                        rayorigin(&sr, SPECULAR, np->rp, np->scolor) == 0) {
386                  nstarget = 1;
387                  if (specjitter > 1.5) { /* multiple samples? */
388 <                        nstarget = specjitter*r->rweight + .5;
388 >                        nstarget = specjitter*np->rp->rweight + .5;
389                          if (sr.rweight <= minweight*nstarget)
390                                  nstarget = sr.rweight/minweight;
391                          if (nstarget > 1) {
# Line 421 | Line 416 | gaussamp(                      /* sample Gaussian specular */
416                                  d = sqrt( np->alpha2 * -log(rv[1]) );
417                          for (i = 0; i < 3; i++)
418                                  h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
419 <                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
420 <                        VSUM(sr.rdir, r->rdir, h, d);
419 >                        d = -2.0 * DOT(h, np->rp->rdir) / (1.0 + d*d);
420 >                        VSUM(sr.rdir, np->rp->rdir, h, d);
421                                                  /* sample rejection test */
422 <                        if ((d = DOT(sr.rdir, r->ron)) <= FTINY)
422 >                        if ((d = DOT(sr.rdir, np->rp->ron)) <= FTINY)
423                                  continue;
424                          checknorm(sr.rdir);
425                          if (nstarget > 1) {     /* W-G-M-D adjustment */
426                                  if (nstaken) rayclear(&sr);
427                                  rayvalue(&sr);
428 <                                d = 2./(1. + r->rod/d);
428 >                                d = 2./(1. + np->rp->rod/d);
429                                  scalecolor(sr.rcol, d);
430                                  addcolor(scol, sr.rcol);
431                          } else {
432                                  rayvalue(&sr);
433                                  multcolor(sr.rcol, sr.rcoef);
434 <                                addcolor(r->rcol, sr.rcol);
434 >                                addcolor(np->rp->rcol, sr.rcol);
435                          }
436                          ++nstaken;
437                  }
# Line 444 | Line 439 | gaussamp(                      /* sample Gaussian specular */
439                          multcolor(scol, sr.rcoef);
440                          d = (double)nstarget/ntrials;
441                          scalecolor(scol, d);
442 <                        addcolor(r->rcol, scol);
442 >                        addcolor(np->rp->rcol, scol);
443                  }
444                  ndims--;
445          }
# Line 452 | Line 447 | gaussamp(                      /* sample Gaussian specular */
447          copycolor(sr.rcoef, np->mcolor);        /* modified by color */
448          scalecolor(sr.rcoef, np->tspec);
449          if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
450 <                        rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) {
450 >                        rayorigin(&sr, SPECULAR, np->rp, sr.rcoef) == 0) {
451                  nstarget = 1;
452                  if (specjitter > 1.5) { /* multiple samples? */
453 <                        nstarget = specjitter*r->rweight + .5;
453 >                        nstarget = specjitter*np->rp->rweight + .5;
454                          if (sr.rweight <= minweight*nstarget)
455                                  nstarget = sr.rweight/minweight;
456                          if (nstarget > 1) {
# Line 486 | Line 481 | gaussamp(                      /* sample Gaussian specular */
481                          for (i = 0; i < 3; i++)
482                                  sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]);
483                                                  /* sample rejection test */
484 <                        if (DOT(sr.rdir, r->ron) >= -FTINY)
484 >                        if (DOT(sr.rdir, np->rp->ron) >= -FTINY)
485                                  continue;
486                          normalize(sr.rdir);     /* OK, normalize */
487                          if (nstaken)            /* multi-sampling */
488                                  rayclear(&sr);
489                          rayvalue(&sr);
490                          multcolor(sr.rcol, sr.rcoef);
491 <                        addcolor(r->rcol, sr.rcol);
491 >                        addcolor(np->rp->rcol, sr.rcol);
492                          ++nstaken;
493                  }
494                  ndims--;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines