ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/glass.c
Revision: 1.11
Committed: Tue Oct 29 16:30:46 1991 UTC (32 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.10: +9 -6 lines
Log Message:
improved accuracy through separate treatment of polarizations

File Contents

# User Rev Content
1 greg 1.7 /* Copyright (c) 1991 Regents of the University of California */
2 greg 1.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * glass.c - simpler shading function for thin glass surfaces.
9     *
10     * 11/14/86
11     */
12    
13     #include "ray.h"
14    
15     /*
16     * This definition of glass provides for a quick calculation
17     * using a single surface where two closely spaced parallel
18     * dielectric surfaces would otherwise be used. The chief
19     * advantage to using this material is speed, since internal
20     * reflections are avoided.
21     *
22     * The specification for glass is as follows:
23     *
24     * modifier glass id
25     * 0
26     * 0
27     * 3 red grn blu
28     *
29     * The color is used for the transmission at normal incidence.
30     * To compute transmission (tn) from transmissivity (Tn) use:
31     *
32     * tn = (sqrt(.8402528435+.0072522239*Tn*Tn)-.9166530661)/.0036261119/Tn
33     *
34     * The transmission of standard 88% transmissivity glass is 0.96.
35     * If we appear to hit the back side of the surface, then we
36     * turn the normal around.
37     */
38    
39     #define RINDEX 1.52 /* refractive index of glass */
40    
41    
42     m_glass(m, r) /* color a ray which hit a thin glass surface */
43     OBJREC *m;
44     register RAY *r;
45     {
46     double sqrt(), pow();
47     COLOR mcolor;
48     double pdot;
49     FVECT pnorm;
50     double cos2;
51     COLOR trans, refl;
52 greg 1.11 double d, r1e, r1m;
53 greg 1.7 double transtest, transdist;
54 greg 1.1 RAY p;
55     register int i;
56    
57     if (m->oargs.nfargs != 3)
58     objerror(m, USER, "bad arguments");
59    
60     setcolor(mcolor, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]);
61    
62     if (r->rod < 0.0) /* reorient if necessary */
63     flipsurface(r);
64 greg 1.7 transtest = 0;
65 greg 1.1 /* get modifiers */
66     raytexture(r, m->omod);
67     pdot = raynormal(pnorm, r);
68     /* angular transmission */
69     cos2 = sqrt( (1.0-1.0/RINDEX/RINDEX) +
70     pdot*pdot/(RINDEX*RINDEX) );
71     setcolor(mcolor, pow(colval(mcolor,RED), 1.0/cos2),
72     pow(colval(mcolor,GRN), 1.0/cos2),
73     pow(colval(mcolor,BLU), 1.0/cos2));
74    
75     /* compute reflection */
76 greg 1.11 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 greg 1.1 /* compute transmittance */
81     for (i = 0; i < 3; i++) {
82     d = colval(mcolor, i);
83 greg 1.11 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 greg 1.1 }
86     /* transmitted ray */
87 greg 1.2 if (rayorigin(&p, r, TRANS, bright(trans)) == 0) {
88 greg 1.10 if (!(r->crtype & SHADOW) &&
89     DOT(r->pert,r->pert) > FTINY*FTINY) {
90 greg 1.7 for (i = 0; i < 3; i++) /* perturb direction */
91     p.rdir[i] = r->rdir[i] - r->pert[i]/RINDEX;
92     normalize(p.rdir);
93 greg 1.8 } else {
94     VCOPY(p.rdir, r->rdir);
95 greg 1.7 transtest = 2;
96 greg 1.8 }
97 greg 1.1 rayvalue(&p);
98     multcolor(p.rcol, r->pcol); /* modify */
99     multcolor(p.rcol, trans);
100     addcolor(r->rcol, p.rcol);
101 greg 1.7 transtest *= bright(p.rcol);
102     transdist = r->rot + p.rt;
103 greg 1.1 }
104 greg 1.3
105 greg 1.1 if (r->crtype & SHADOW) /* skip reflected ray */
106     return;
107     /* compute reflectance */
108     for (i = 0; i < 3; i++) {
109     d = colval(mcolor, i);
110     d *= d;
111 greg 1.11 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 greg 1.1 }
114     /* reflected ray */
115 greg 1.2 if (rayorigin(&p, r, REFLECTED, bright(refl)) == 0) {
116 greg 1.1 for (i = 0; i < 3; i++)
117     p.rdir[i] = r->rdir[i] + 2.0*pdot*pnorm[i];
118     rayvalue(&p);
119     multcolor(p.rcol, refl);
120     addcolor(r->rcol, p.rcol);
121     }
122 greg 1.7 if (transtest > bright(r->rcol))
123     r->rt = transdist;
124 greg 1.1 }