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

Comparing ray/src/rt/glass.c (file contents):
Revision 1.4 by greg, Wed May 30 19:57:01 1990 UTC vs.
Revision 1.11 by greg, Tue Oct 29 16:30:46 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 49 | Line 49 | register RAY  *r;
49          FVECT  pnorm;
50          double  cos2;
51          COLOR  trans, refl;
52 <        double  transbright;
53 <        double  d, r1;
52 >        double  d, r1e, r1m;
53 >        double  transtest, transdist;
54          RAY  p;
55          register int  i;
56  
# Line 61 | Line 61 | register RAY  *r;
61  
62          if (r->rod < 0.0)                       /* reorient if necessary */
63                  flipsurface(r);
64 +        transtest = 0;
65                                                  /* get modifiers */
66          raytexture(r, m->omod);
67          pdot = raynormal(pnorm, r);
# Line 72 | Line 73 | register RAY  *r;
73                           pow(colval(mcolor,BLU), 1.0/cos2));
74  
75                                                  /* compute reflection */
76 <        r1 = (pdot - RINDEX*cos2) / (pdot + RINDEX*cos2);
77 <        d = (1.0/pdot - RINDEX/cos2) / (1.0/pdot + RINDEX/cos2);
78 <        r1 = (r1*r1 + d*d) / 2.0;
76 >        r1e = (pdot - RINDEX*cos2) / (pdot + RINDEX*cos2);
77 >        r1e *= r1e;
78 >        r1m = (1.0/pdot - RINDEX/cos2) / (1.0/pdot + RINDEX/cos2);
79 >        r1m *= r1m;
80                                                  /* compute transmittance */
81          for (i = 0; i < 3; i++) {
82                  d = colval(mcolor, i);
83 <                colval(trans,i) = (1.0-r1)*(1.0-r1)*d / (1.0 - r1*r1*d*d);
83 >                colval(trans,i) = .5*(1.0-r1e)*(1.0-r1e)*d/(1.0-r1e*r1e*d*d);
84 >                colval(trans,i) += .5*(1.0-r1m)*(1.0-r1m)*d/(1.0-r1m*r1m*d*d);
85          }
83        transbright = -FTINY;
86                                                  /* transmitted ray */
87          if (rayorigin(&p, r, TRANS, bright(trans)) == 0) {
88 <                VCOPY(p.rdir, r->rdir);
88 >                if (!(r->crtype & SHADOW) &&
89 >                                DOT(r->pert,r->pert) > FTINY*FTINY) {
90 >                        for (i = 0; i < 3; i++)         /* perturb direction */
91 >                                p.rdir[i] = r->rdir[i] - r->pert[i]/RINDEX;
92 >                        normalize(p.rdir);
93 >                } else {
94 >                        VCOPY(p.rdir, r->rdir);
95 >                        transtest = 2;
96 >                }
97                  rayvalue(&p);
98                  multcolor(p.rcol, r->pcol);     /* modify */
99                  multcolor(p.rcol, trans);
100                  addcolor(r->rcol, p.rcol);
101 <                transbright = bright(p.rcol);
102 <                r->rt = r->rot + p.rt;
101 >                transtest *= bright(p.rcol);
102 >                transdist = r->rot + p.rt;
103          }
104  
105          if (r->crtype & SHADOW)                 /* skip reflected ray */
# Line 98 | Line 108 | register RAY  *r;
108          for (i = 0; i < 3; i++) {
109                  d = colval(mcolor, i);
110                  d *= d;
111 <                colval(refl,i) = r1 * (1.0 + (1.0-2.0*r1)*d) / (1.0 - r1*r1*d);
111 >                colval(refl,i) = .5*r1e*(1.0+(1.0-2.0*r1e)*d)/(1.0-r1e*r1e*d);
112 >                colval(refl,i) += .5*r1m*(1.0+(1.0-2.0*r1m)*d)/(1.0-r1m*r1m*d);
113          }
114                                                  /* reflected ray */
115          if (rayorigin(&p, r, REFLECTED, bright(refl)) == 0) {
# Line 107 | Line 118 | register RAY  *r;
118                  rayvalue(&p);
119                  multcolor(p.rcol, refl);
120                  addcolor(r->rcol, p.rcol);
110                if (bright(p.rcol) > transbright)
111                        r->rt = r->rot + p.rt;
121          }
122 +        if (transtest > bright(r->rcol))
123 +                r->rt = transdist;
124   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines