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.5 by greg, Tue Jan 14 16:16:45 1992 UTC vs.
Revision 2.10 by greg, Thu Jan 30 11:37:00 1992 UTC

# Line 128 | Line 128 | double  omega;                 /* light source size */
128                   *  is always modified by material color.
129                   */
130                                                  /* roughness + source */
131 <                dtmp = np->alpha2 + omega/(2.0*PI);
131 >                dtmp = np->alpha2/2.0 + omega/(2.0*PI);
132                                                  /* gaussian */
133                  dtmp = exp((DOT(np->prdir,ldir)-1.)/dtmp)/(2.*PI)/dtmp;
134                                                  /* worth using? */
# Line 192 | Line 192 | register RAY  *r;
192                          colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp;
193                  nd.rspec += (1.0-nd.rspec)*dtmp;
194                                                  /* check threshold */
195 <                if (nd.rspec <= specthresh+FTINY)
195 >                if (specthresh > FTINY &&
196 >                                ((specthresh >= 1.-FTINY ||
197 >                                specthresh + (.05 - .1*frandom()) > nd.rspec)))
198                          nd.specfl |= SP_RBLT;
199                                                  /* compute reflected ray */
200                  for (i = 0; i < 3; i++)
201                          nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
202 +                if (DOT(nd.vrefl, r->ron) <= FTINY)     /* penetration? */
203 +                        for (i = 0; i < 3; i++)         /* safety measure */
204 +                                nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
205  
206                  if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) {
207                          RAY  lr;
# Line 216 | Line 221 | register RAY  *r;
221                  if (nd.tspec > FTINY) {
222                          nd.specfl |= SP_TRAN;
223                                                          /* check threshold */
224 <                        if (nd.tspec <= specthresh+FTINY)
224 >                        if (specthresh > FTINY &&
225 >                                        ((specthresh >= 1.-FTINY ||
226 >                                        specthresh +
227 >                                            (.05 - .1*frandom()) > nd.tspec)))
228                                  nd.specfl |= SP_TBLT;
229                          if (r->crtype & SHADOW ||
230                                          DOT(r->pert,r->pert) <= FTINY*FTINY) {
# Line 225 | Line 233 | register RAY  *r;
233                          } else {
234                                  for (i = 0; i < 3; i++)         /* perturb */
235                                          nd.prdir[i] = r->rdir[i] -
236 <                                                        .75*r->pert[i];
237 <                                normalize(nd.prdir);
236 >                                                        0.5*r->pert[i];
237 >                                if (DOT(nd.prdir, r->ron) < -FTINY)
238 >                                        normalize(nd.prdir);    /* OK */
239 >                                else
240 >                                        VCOPY(nd.prdir, r->rdir);
241                          }
242                  }
243          } else
# Line 296 | Line 307 | register NORMDAT  *np;
307          FVECT  u, v, h;
308          double  rv[2];
309          double  d, sinp, cosp;
299        int  ntries;
310          register int  i;
311                                          /* set up sample coordinates */
312          v[0] = v[1] = v[2] = 0.0;
# Line 311 | Line 321 | register NORMDAT  *np;
321          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
322                          rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
323                  dimlist[ndims++] = (int)np->mp;
324 <                for (ntries = 0; ntries < 10; ntries++) {
325 <                        dimlist[ndims] = ntries * 8912;
326 <                        d = urand(ilhash(dimlist,ndims+1)+samplendx);
327 <                        multisamp(rv, 2, d);
328 <                        d = 2.0*PI * rv[0];
329 <                        cosp = cos(d);
330 <                        sinp = sin(d);
331 <                        rv[1] = 1.0 - specjitter*rv[1];
332 <                        if (rv[1] <= FTINY)
333 <                                d = 1.0;
334 <                        else
335 <                                d = sqrt( np->alpha2 * -log(rv[1]) );
336 <                        for (i = 0; i < 3; i++)
337 <                                h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
338 <                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
339 <                        for (i = 0; i < 3; i++)
340 <                                sr.rdir[i] = r->rdir[i] + d*h[i];
341 <                        if (DOT(sr.rdir, r->ron) > FTINY) {
342 <                                rayvalue(&sr);
343 <                                multcolor(sr.rcol, np->scolor);
334 <                                addcolor(r->rcol, sr.rcol);
335 <                                break;
336 <                        }
337 <                }
324 >                d = urand(ilhash(dimlist,ndims)+samplendx);
325 >                multisamp(rv, 2, d);
326 >                d = 2.0*PI * rv[0];
327 >                cosp = cos(d);
328 >                sinp = sin(d);
329 >                rv[1] = 1.0 - specjitter*rv[1];
330 >                if (rv[1] <= FTINY)
331 >                        d = 1.0;
332 >                else
333 >                        d = sqrt( np->alpha2 * -log(rv[1]) );
334 >                for (i = 0; i < 3; i++)
335 >                        h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
336 >                d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
337 >                for (i = 0; i < 3; i++)
338 >                        sr.rdir[i] = r->rdir[i] + d*h[i];
339 >                if (DOT(sr.rdir, r->ron) <= FTINY)
340 >                        VCOPY(sr.rdir, np->vrefl);      /* jitter no good */
341 >                rayvalue(&sr);
342 >                multcolor(sr.rcol, np->scolor);
343 >                addcolor(r->rcol, sr.rcol);
344                  ndims--;
345          }
346                                          /* compute transmission */
347 +        if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
348 +                        rayorigin(&sr, r, SPECULAR, np->tspec) == 0) {
349 +                dimlist[ndims++] = (int)np->mp;
350 +                d = urand(ilhash(dimlist,ndims)+1823+samplendx);
351 +                multisamp(rv, 2, d);
352 +                d = 2.0*PI * rv[0];
353 +                cosp = cos(d);
354 +                sinp = sin(d);
355 +                rv[1] = 1.0 - specjitter*rv[1];
356 +                if (rv[1] <= FTINY)
357 +                        d = 1.0;
358 +                else
359 +                        d = sqrt( np->alpha2/4.0 * -log(rv[1]) );
360 +                for (i = 0; i < 3; i++)
361 +                        sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]);
362 +                if (DOT(sr.rdir, r->ron) < -FTINY)
363 +                        normalize(sr.rdir);             /* OK, normalize */
364 +                else
365 +                        VCOPY(sr.rdir, np->prdir);      /* else no jitter */
366 +                rayvalue(&sr);
367 +                multcolor(sr.rcol, np->scolor);
368 +                addcolor(r->rcol, sr.rcol);
369 +                ndims--;
370 +        }
371   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines