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.6 by greg, Wed Jan 15 11:02:40 1992 UTC vs.
Revision 2.11 by greg, Fri Feb 21 14:53:16 1992 UTC

# Line 43 | Line 43 | extern double  specjitter;             /* specular sampling jitte
43                                  /* specularity flags */
44   #define  SP_REFL        01              /* has reflected specular component */
45   #define  SP_TRAN        02              /* has transmitted specular */
46 < #define  SP_PURE        010             /* purely specular (zero roughness) */
47 < #define  SP_FLAT        020             /* flat reflecting surface */
48 < #define  SP_RBLT        040             /* reflection below sample threshold */
49 < #define  SP_TBLT        0100            /* transmission below threshold */
46 > #define  SP_PURE        04              /* purely specular (zero roughness) */
47 > #define  SP_FLAT        010             /* flat reflecting surface */
48 > #define  SP_RBLT        020             /* reflection below sample threshold */
49 > #define  SP_TBLT        040             /* transmission below threshold */
50  
51   typedef struct {
52          OBJREC  *mp;            /* material pointer */
# 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 194 | Line 194 | register RAY  *r;
194                                                  /* check threshold */
195                  if (specthresh > FTINY &&
196                                  ((specthresh >= 1.-FTINY ||
197 <                                specthresh + (.1 - .2*urand(8199+samplendx))
198 <                                        > nd.rspec)))
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 222 | Line 224 | register RAY  *r;
224                          if (specthresh > FTINY &&
225                                          ((specthresh >= 1.-FTINY ||
226                                          specthresh +
227 <                                            (.1 - .2*urand(7241+samplendx))
226 <                                                > nd.tspec)))
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 232 | 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 250 | Line 254 | register RAY  *r;
254                          transtest *= bright(lr.rcol);
255                          transdist = r->rot + lr.rt;
256                  }
257 <        }
257 >        } else
258 >                transtest = 0;
259  
260          if (r->crtype & SHADOW)                 /* the rest is shadow */
261                  return;
# Line 303 | Line 308 | register NORMDAT  *np;
308          FVECT  u, v, h;
309          double  rv[2];
310          double  d, sinp, cosp;
306        int  ntries;
311          register int  i;
312                                          /* set up sample coordinates */
313          v[0] = v[1] = v[2] = 0.0;
# Line 318 | Line 322 | register NORMDAT  *np;
322          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
323                          rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
324                  dimlist[ndims++] = (int)np->mp;
325 <                for (ntries = 0; ntries < 10; ntries++) {
326 <                        dimlist[ndims] = ntries * 8912;
327 <                        d = urand(ilhash(dimlist,ndims+1)+samplendx);
328 <                        multisamp(rv, 2, d);
329 <                        d = 2.0*PI * rv[0];
330 <                        cosp = cos(d);
331 <                        sinp = sin(d);
332 <                        rv[1] = 1.0 - specjitter*rv[1];
333 <                        if (rv[1] <= FTINY)
334 <                                d = 1.0;
335 <                        else
336 <                                d = sqrt( np->alpha2 * -log(rv[1]) );
337 <                        for (i = 0; i < 3; i++)
338 <                                h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
339 <                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
340 <                        for (i = 0; i < 3; i++)
341 <                                sr.rdir[i] = r->rdir[i] + d*h[i];
342 <                        if (DOT(sr.rdir, r->ron) > FTINY) {
343 <                                rayvalue(&sr);
344 <                                multcolor(sr.rcol, np->scolor);
341 <                                addcolor(r->rcol, sr.rcol);
342 <                                break;
343 <                        }
344 <                }
325 >                d = urand(ilhash(dimlist,ndims)+samplendx);
326 >                multisamp(rv, 2, d);
327 >                d = 2.0*PI * rv[0];
328 >                cosp = cos(d);
329 >                sinp = sin(d);
330 >                rv[1] = 1.0 - specjitter*rv[1];
331 >                if (rv[1] <= FTINY)
332 >                        d = 1.0;
333 >                else
334 >                        d = sqrt( np->alpha2 * -log(rv[1]) );
335 >                for (i = 0; i < 3; i++)
336 >                        h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
337 >                d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
338 >                for (i = 0; i < 3; i++)
339 >                        sr.rdir[i] = r->rdir[i] + d*h[i];
340 >                if (DOT(sr.rdir, r->ron) <= FTINY)
341 >                        VCOPY(sr.rdir, np->vrefl);      /* jitter no good */
342 >                rayvalue(&sr);
343 >                multcolor(sr.rcol, np->scolor);
344 >                addcolor(r->rcol, sr.rcol);
345                  ndims--;
346          }
347                                          /* compute transmission */
348 +        if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
349 +                        rayorigin(&sr, r, SPECULAR, np->tspec) == 0) {
350 +                dimlist[ndims++] = (int)np->mp;
351 +                d = urand(ilhash(dimlist,ndims)+1823+samplendx);
352 +                multisamp(rv, 2, d);
353 +                d = 2.0*PI * rv[0];
354 +                cosp = cos(d);
355 +                sinp = sin(d);
356 +                rv[1] = 1.0 - specjitter*rv[1];
357 +                if (rv[1] <= FTINY)
358 +                        d = 1.0;
359 +                else
360 +                        d = sqrt( np->alpha2/4.0 * -log(rv[1]) );
361 +                for (i = 0; i < 3; i++)
362 +                        sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]);
363 +                if (DOT(sr.rdir, r->ron) < -FTINY)
364 +                        normalize(sr.rdir);             /* OK, normalize */
365 +                else
366 +                        VCOPY(sr.rdir, np->prdir);      /* else no jitter */
367 +                rayvalue(&sr);
368 +                scalecolor(sr.rcol, np->tspec);
369 +                multcolor(sr.rcol, np->mcolor);         /* modified by color */
370 +                addcolor(r->rcol, sr.rcol);
371 +                ndims--;
372 +        }
373   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines