1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* dielectric.c - shading function for transparent materials. |
9 |
– |
* |
10 |
– |
* 9/6/85 |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "ray.h" |
11 |
|
|
12 |
|
#include "otypes.h" |
47 |
|
|
48 |
|
#define MINCOS 0.997 /* minimum dot product for dispersion */ |
49 |
|
|
53 |
– |
extern COLOR cextinction; /* global coefficient of extinction */ |
54 |
– |
extern COLOR salbedo; /* global scattering albedo */ |
50 |
|
|
56 |
– |
|
51 |
|
static double |
52 |
|
mylog(x) /* special log for extinction coefficients */ |
53 |
|
double x; |
67 |
|
double cos1, cos2, nratio; |
68 |
|
COLOR ctrans; |
69 |
|
COLOR talb; |
70 |
+ |
int hastexture; |
71 |
|
double refl, trans; |
72 |
|
FVECT dnorm; |
73 |
|
double d1, d2; |
79 |
|
|
80 |
|
raytexture(r, m->omod); /* get modifiers */ |
81 |
|
|
82 |
< |
cos1 = raynormal(dnorm, r); /* cosine of theta1 */ |
82 |
> |
if (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY) |
83 |
> |
cos1 = raynormal(dnorm, r); /* perturb normal */ |
84 |
> |
else { |
85 |
> |
VCOPY(dnorm, r->ron); |
86 |
> |
cos1 = r->rod; |
87 |
> |
} |
88 |
|
/* index of refraction */ |
89 |
|
if (m->otype == MAT_DIELECTRIC) |
90 |
|
nratio = m->oargs.farg[3] + m->oargs.farg[4]/MLAMBDA; |
92 |
|
nratio = m->oargs.farg[3] / m->oargs.farg[7]; |
93 |
|
|
94 |
|
if (cos1 < 0.0) { /* inside */ |
95 |
+ |
hastexture = -hastexture; |
96 |
|
cos1 = -cos1; |
97 |
|
dnorm[0] = -dnorm[0]; |
98 |
|
dnorm[1] = -dnorm[1]; |
151 |
|
refl *= 0.5; |
152 |
|
trans = 1.0 - refl; |
153 |
|
|
154 |
+ |
trans *= nratio*nratio; /* solid angle ratio */ |
155 |
+ |
|
156 |
|
if (rayorigin(&p, r, REFRACTED, trans) == 0) { |
157 |
|
|
158 |
|
/* compute refracted ray */ |
159 |
|
d1 = nratio*cos1 - cos2; |
160 |
|
for (i = 0; i < 3; i++) |
161 |
|
p.rdir[i] = nratio*r->rdir[i] + d1*dnorm[i]; |
162 |
< |
|
162 |
> |
/* accidental reflection? */ |
163 |
> |
if (hastexture && |
164 |
> |
DOT(p.rdir,r->ron)*hastexture >= -FTINY) { |
165 |
> |
d1 *= (double)hastexture; |
166 |
> |
for (i = 0; i < 3; i++) /* ignore texture */ |
167 |
> |
p.rdir[i] = nratio*r->rdir[i] + |
168 |
> |
d1*r->ron[i]; |
169 |
> |
normalize(p.rdir); /* not exact */ |
170 |
> |
} |
171 |
|
#ifdef DISPERSE |
172 |
|
if (m->otype != MAT_DIELECTRIC |
173 |
|
|| r->rod > 0.0 |
195 |
|
/* compute reflected ray */ |
196 |
|
for (i = 0; i < 3; i++) |
197 |
|
p.rdir[i] = r->rdir[i] + 2.0*cos1*dnorm[i]; |
198 |
+ |
/* accidental penetration? */ |
199 |
+ |
if (hastexture && DOT(p.rdir,r->ron)*hastexture <= FTINY) |
200 |
+ |
for (i = 0; i < 3; i++) /* ignore texture */ |
201 |
+ |
p.rdir[i] = r->rdir[i] + 2.0*r->rod*r->ron[i]; |
202 |
|
|
203 |
|
rayvalue(&p); /* reflected ray value */ |
204 |
|
|