ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/glass.c
Revision: 2.5
Committed: Mon Nov 30 12:02:54 1992 UTC (31 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +2 -2 lines
Log Message:
fixed comment terminology

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 greg 2.5 * To compute transmissivity (tn) from transmittance (Tn) use:
31 greg 1.1 *
32     * tn = (sqrt(.8402528435+.0072522239*Tn*Tn)-.9166530661)/.0036261119/Tn
33     *
34 greg 2.5 * The transmissivity of standard 88% transmittance glass is 0.96.
35 greg 1.12 * A refractive index other than the default can be used by giving
36     * it as the fourth real argument. The above formula no longer applies.
37     *
38 greg 1.1 * If we appear to hit the back side of the surface, then we
39     * turn the normal around.
40     */
41    
42     #define RINDEX 1.52 /* refractive index of glass */
43    
44    
45     m_glass(m, r) /* color a ray which hit a thin glass surface */
46     OBJREC *m;
47     register RAY *r;
48     {
49     COLOR mcolor;
50     double pdot;
51     FVECT pnorm;
52 greg 1.12 double rindex, cos2;
53 greg 1.1 COLOR trans, refl;
54 greg 1.11 double d, r1e, r1m;
55 greg 1.7 double transtest, transdist;
56 greg 1.1 RAY p;
57     register int i;
58 greg 1.12 /* check arguments */
59     if (m->oargs.nfargs == 3)
60     rindex = RINDEX; /* default value of n */
61     else if (m->oargs.nfargs == 4)
62     rindex = m->oargs.farg[3]; /* use their value */
63     else
64 greg 1.1 objerror(m, USER, "bad arguments");
65    
66     setcolor(mcolor, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]);
67    
68     if (r->rod < 0.0) /* reorient if necessary */
69     flipsurface(r);
70 greg 1.7 transtest = 0;
71 greg 1.1 /* get modifiers */
72     raytexture(r, m->omod);
73     pdot = raynormal(pnorm, r);
74     /* angular transmission */
75 greg 1.12 cos2 = sqrt( (1.0-1.0/(rindex*rindex)) +
76     pdot*pdot/(rindex*rindex) );
77 greg 1.1 setcolor(mcolor, pow(colval(mcolor,RED), 1.0/cos2),
78     pow(colval(mcolor,GRN), 1.0/cos2),
79     pow(colval(mcolor,BLU), 1.0/cos2));
80    
81     /* compute reflection */
82 greg 1.12 r1e = (pdot - rindex*cos2) / (pdot + rindex*cos2);
83 greg 1.11 r1e *= r1e;
84 greg 1.12 r1m = (1.0/pdot - rindex/cos2) / (1.0/pdot + rindex/cos2);
85 greg 1.11 r1m *= r1m;
86 greg 1.1 /* compute transmittance */
87     for (i = 0; i < 3; i++) {
88     d = colval(mcolor, i);
89 greg 1.11 colval(trans,i) = .5*(1.0-r1e)*(1.0-r1e)*d/(1.0-r1e*r1e*d*d);
90     colval(trans,i) += .5*(1.0-r1m)*(1.0-r1m)*d/(1.0-r1m*r1m*d*d);
91 greg 1.1 }
92     /* transmitted ray */
93 greg 1.2 if (rayorigin(&p, r, TRANS, bright(trans)) == 0) {
94 greg 1.10 if (!(r->crtype & SHADOW) &&
95     DOT(r->pert,r->pert) > FTINY*FTINY) {
96 greg 1.7 for (i = 0; i < 3; i++) /* perturb direction */
97 greg 2.2 p.rdir[i] = r->rdir[i] +
98     2.*(1.-rindex)*r->pert[i];
99 greg 2.4 if (normalize(p.rdir) == 0.0) {
100     objerror(m, WARNING, "bad perturbation");
101     VCOPY(p.rdir, r->rdir);
102     }
103 greg 1.8 } else {
104     VCOPY(p.rdir, r->rdir);
105 greg 1.7 transtest = 2;
106 greg 1.8 }
107 greg 1.1 rayvalue(&p);
108     multcolor(p.rcol, r->pcol); /* modify */
109     multcolor(p.rcol, trans);
110     addcolor(r->rcol, p.rcol);
111 greg 1.7 transtest *= bright(p.rcol);
112     transdist = r->rot + p.rt;
113 greg 1.1 }
114 greg 1.3
115 greg 1.1 if (r->crtype & SHADOW) /* skip reflected ray */
116     return;
117     /* compute reflectance */
118     for (i = 0; i < 3; i++) {
119     d = colval(mcolor, i);
120     d *= d;
121 greg 1.11 colval(refl,i) = .5*r1e*(1.0+(1.0-2.0*r1e)*d)/(1.0-r1e*r1e*d);
122     colval(refl,i) += .5*r1m*(1.0+(1.0-2.0*r1m)*d)/(1.0-r1m*r1m*d);
123 greg 1.1 }
124     /* reflected ray */
125 greg 1.2 if (rayorigin(&p, r, REFLECTED, bright(refl)) == 0) {
126 greg 1.1 for (i = 0; i < 3; i++)
127     p.rdir[i] = r->rdir[i] + 2.0*pdot*pnorm[i];
128     rayvalue(&p);
129     multcolor(p.rcol, refl);
130     addcolor(r->rcol, p.rcol);
131     }
132 greg 1.7 if (transtest > bright(r->rcol))
133     r->rt = transdist;
134 greg 1.1 }