32 |
|
* tn = (sqrt(.8402528435+.0072522239*Tn*Tn)-.9166530661)/.0036261119/Tn |
33 |
|
* |
34 |
|
* The transmission of standard 88% transmissivity glass is 0.96. |
35 |
+ |
* 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 |
|
* If we appear to hit the back side of the surface, then we |
39 |
|
* turn the normal around. |
40 |
|
*/ |
50 |
|
COLOR mcolor; |
51 |
|
double pdot; |
52 |
|
FVECT pnorm; |
53 |
< |
double cos2; |
53 |
> |
double rindex, cos2; |
54 |
|
COLOR trans, refl; |
55 |
< |
double d, r1; |
55 |
> |
double d, r1e, r1m; |
56 |
|
double transtest, transdist; |
57 |
|
RAY p; |
58 |
|
register int i; |
59 |
< |
|
60 |
< |
if (m->oargs.nfargs != 3) |
59 |
> |
/* check arguments */ |
60 |
> |
if (m->oargs.nfargs == 3) |
61 |
> |
rindex = RINDEX; /* default value of n */ |
62 |
> |
else if (m->oargs.nfargs == 4) |
63 |
> |
rindex = m->oargs.farg[3]; /* use their value */ |
64 |
> |
else |
65 |
|
objerror(m, USER, "bad arguments"); |
66 |
|
|
67 |
|
setcolor(mcolor, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]); |
73 |
|
raytexture(r, m->omod); |
74 |
|
pdot = raynormal(pnorm, r); |
75 |
|
/* angular transmission */ |
76 |
< |
cos2 = sqrt( (1.0-1.0/RINDEX/RINDEX) + |
77 |
< |
pdot*pdot/(RINDEX*RINDEX) ); |
76 |
> |
cos2 = sqrt( (1.0-1.0/(rindex*rindex)) + |
77 |
> |
pdot*pdot/(rindex*rindex) ); |
78 |
|
setcolor(mcolor, pow(colval(mcolor,RED), 1.0/cos2), |
79 |
|
pow(colval(mcolor,GRN), 1.0/cos2), |
80 |
|
pow(colval(mcolor,BLU), 1.0/cos2)); |
81 |
|
|
82 |
|
/* compute reflection */ |
83 |
< |
r1 = (pdot - RINDEX*cos2) / (pdot + RINDEX*cos2); |
84 |
< |
d = (1.0/pdot - RINDEX/cos2) / (1.0/pdot + RINDEX/cos2); |
85 |
< |
r1 = (r1*r1 + d*d) / 2.0; |
83 |
> |
r1e = (pdot - rindex*cos2) / (pdot + rindex*cos2); |
84 |
> |
r1e *= r1e; |
85 |
> |
r1m = (1.0/pdot - rindex/cos2) / (1.0/pdot + rindex/cos2); |
86 |
> |
r1m *= r1m; |
87 |
|
/* compute transmittance */ |
88 |
|
for (i = 0; i < 3; i++) { |
89 |
|
d = colval(mcolor, i); |
90 |
< |
colval(trans,i) = (1.0-r1)*(1.0-r1)*d / (1.0 - r1*r1*d*d); |
90 |
> |
colval(trans,i) = .5*(1.0-r1e)*(1.0-r1e)*d/(1.0-r1e*r1e*d*d); |
91 |
> |
colval(trans,i) += .5*(1.0-r1m)*(1.0-r1m)*d/(1.0-r1m*r1m*d*d); |
92 |
|
} |
93 |
|
/* transmitted ray */ |
94 |
|
if (rayorigin(&p, r, TRANS, bright(trans)) == 0) { |
95 |
|
if (!(r->crtype & SHADOW) && |
96 |
|
DOT(r->pert,r->pert) > FTINY*FTINY) { |
97 |
|
for (i = 0; i < 3; i++) /* perturb direction */ |
98 |
< |
p.rdir[i] = r->rdir[i] - r->pert[i]/RINDEX; |
98 |
> |
p.rdir[i] = r->rdir[i] - r->pert[i]/rindex; |
99 |
|
normalize(p.rdir); |
100 |
|
} else { |
101 |
|
VCOPY(p.rdir, r->rdir); |
115 |
|
for (i = 0; i < 3; i++) { |
116 |
|
d = colval(mcolor, i); |
117 |
|
d *= d; |
118 |
< |
colval(refl,i) = r1 * (1.0 + (1.0-2.0*r1)*d) / (1.0 - r1*r1*d); |
118 |
> |
colval(refl,i) = .5*r1e*(1.0+(1.0-2.0*r1e)*d)/(1.0-r1e*r1e*d); |
119 |
> |
colval(refl,i) += .5*r1m*(1.0+(1.0-2.0*r1m)*d)/(1.0-r1m*r1m*d); |
120 |
|
} |
121 |
|
/* reflected ray */ |
122 |
|
if (rayorigin(&p, r, REFLECTED, bright(refl)) == 0) { |