--- ray/src/rt/normal.c 1992/01/04 23:36:42 2.3 +++ ray/src/rt/normal.c 1992/01/14 15:33:08 2.4 @@ -279,7 +279,7 @@ register NORMDAT *np; FVECT u, v, h; double rv[2]; double d, sinp, cosp; - int confuse; + int ntries; register int i; /* set up sample coordinates */ v[0] = v[1] = v[2] = 0.0; @@ -293,29 +293,30 @@ register NORMDAT *np; /* compute reflection */ if (np->specfl & SP_REFL && rayorigin(&sr, r, SPECULAR, np->rspec) == 0) { - confuse = 0; dimlist[ndims++] = (int)np->mp; - refagain: - dimlist[ndims] = confuse += 3601; - d = urand(ilhash(dimlist,ndims+1)+samplendx); - multisamp(rv, 2, d); - d = 2.0*PI * rv[0]; - cosp = cos(d); - sinp = sin(d); - if (rv[1] <= FTINY) - d = 1.0; - else - d = sqrt( np->alpha2 * -log(rv[1]) ); - for (i = 0; i < 3; i++) - h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]); - d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d); - for (i = 0; i < 3; i++) - sr.rdir[i] = r->rdir[i] + d*h[i]; - if (DOT(sr.rdir, r->ron) <= FTINY) /* oops! */ - goto refagain; - rayvalue(&sr); - multcolor(sr.rcol, np->scolor); - addcolor(r->rcol, sr.rcol); + for (ntries = 0; ntries < 10; ntries++) { + dimlist[ndims] = ntries * 8912; + d = urand(ilhash(dimlist,ndims+1)+samplendx); + multisamp(rv, 2, d); + d = 2.0*PI * rv[0]; + cosp = cos(d); + sinp = sin(d); + if (rv[1] <= FTINY) + d = 1.0; + else + d = sqrt( np->alpha2 * -log(rv[1]) ); + for (i = 0; i < 3; i++) + h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]); + d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d); + for (i = 0; i < 3; i++) + sr.rdir[i] = r->rdir[i] + d*h[i]; + if (DOT(sr.rdir, r->ron) > FTINY) { + rayvalue(&sr); + multcolor(sr.rcol, np->scolor); + addcolor(r->rcol, sr.rcol); + break; + } + } ndims--; } /* compute transmission */