10 |
|
#include "ray.h" |
11 |
|
#include "otypes.h" |
12 |
|
#include "rtotypes.h" |
13 |
+ |
#include "pmapmat.h" |
14 |
|
|
15 |
|
/* |
16 |
|
* This definition of glass provides for a quick calculation |
42 |
|
#define RINDEX 1.52 /* refractive index of glass */ |
43 |
|
|
44 |
|
|
45 |
< |
extern int |
45 |
> |
int |
46 |
|
m_glass( /* color a ray which hit a thin glass surface */ |
47 |
|
OBJREC *m, |
48 |
< |
register RAY *r |
48 |
> |
RAY *r |
49 |
|
) |
50 |
|
{ |
51 |
|
COLOR mcolor; |
52 |
|
double pdot; |
53 |
|
FVECT pnorm; |
54 |
< |
double rindex, cos2; |
54 |
> |
double rindex=0, cos2; |
55 |
|
COLOR trans, refl; |
56 |
|
int hastexture, hastrans; |
57 |
|
double d, r1e, r1m; |
57 |
– |
double transtest, transdist; |
58 |
– |
double mirtest, mirdist; |
58 |
|
RAY p; |
59 |
< |
register int i; |
59 |
> |
int i; |
60 |
> |
|
61 |
> |
/* PMAP: skip refracted shadow or ambient ray if accounted for in |
62 |
> |
photon map */ |
63 |
> |
if (shadowRayInPmap(r) || ambRayInPmap(r)) |
64 |
> |
return(1); |
65 |
|
/* check arguments */ |
66 |
|
if (m->oargs.nfargs == 3) |
67 |
|
rindex = RINDEX; /* default value of n */ |
69 |
|
rindex = m->oargs.farg[3]; /* use their value */ |
70 |
|
else |
71 |
|
objerror(m, USER, "bad arguments"); |
72 |
+ |
/* check back face visibility */ |
73 |
+ |
if (!backvis && r->rod <= 0.0) { |
74 |
+ |
raytrans(r); |
75 |
+ |
return(1); |
76 |
+ |
} |
77 |
|
/* check transmission */ |
78 |
|
setcolor(mcolor, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]); |
79 |
|
if ((hastrans = (intens(mcolor) > 1e-15))) { |
86 |
|
raytexture(r, m->omod); |
87 |
|
if (r->rod < 0.0) /* reorient if necessary */ |
88 |
|
flipsurface(r); |
80 |
– |
mirtest = transtest = 0; |
81 |
– |
mirdist = transdist = r->rot; |
89 |
|
/* perturb normal */ |
90 |
|
if ( (hastexture = (DOT(r->pert,r->pert) > FTINY*FTINY)) ) { |
91 |
|
pdot = raynormal(pnorm, r); |
118 |
|
multcolor(trans, r->pcol); /* modify by pattern */ |
119 |
|
/* transmitted ray */ |
120 |
|
if (rayorigin(&p, TRANS, r, trans) == 0) { |
121 |
< |
if (!(r->crtype & SHADOW) && hastexture) { |
122 |
< |
for (i = 0; i < 3; i++) /* perturb direction */ |
116 |
< |
p.rdir[i] = r->rdir[i] + |
117 |
< |
2.*(1.-rindex)*r->pert[i]; |
121 |
> |
if (!(r->crtype & (SHADOW|AMBIENT)) && hastexture) { |
122 |
> |
VSUM(p.rdir, r->rdir, r->pert, 2.*(1.-rindex)); |
123 |
|
if (normalize(p.rdir) == 0.0) { |
124 |
|
objerror(m, WARNING, "bad perturbation"); |
125 |
|
VCOPY(p.rdir, r->rdir); |
126 |
|
} |
127 |
|
} else { |
128 |
|
VCOPY(p.rdir, r->rdir); |
124 |
– |
transtest = 2; |
129 |
|
} |
130 |
|
rayvalue(&p); |
131 |
|
multcolor(p.rcol, p.rcoef); |
132 |
|
addcolor(r->rcol, p.rcol); |
133 |
< |
transtest *= bright(p.rcol); |
134 |
< |
transdist = r->rot + p.rt; |
133 |
> |
if (!hastexture || r->crtype & (SHADOW|AMBIENT)) |
134 |
> |
r->rxt = r->rot + raydistance(&p); |
135 |
|
} |
136 |
|
} |
137 |
< |
if (r->crtype & SHADOW) { /* skip reflected ray */ |
134 |
< |
r->rt = transdist; |
137 |
> |
if (r->crtype & SHADOW) /* skip reflected ray */ |
138 |
|
return(1); |
136 |
– |
} |
139 |
|
/* compute reflectance */ |
140 |
|
for (i = 0; i < 3; i++) { |
141 |
|
d = colval(mcolor, i); |
145 |
|
} |
146 |
|
/* reflected ray */ |
147 |
|
if (rayorigin(&p, REFLECTED, r, refl) == 0) { |
148 |
< |
for (i = 0; i < 3; i++) |
147 |
< |
p.rdir[i] = r->rdir[i] + 2.0*pdot*pnorm[i]; |
148 |
> |
VSUM(p.rdir, r->rdir, pnorm, 2.*pdot); |
149 |
|
checknorm(p.rdir); |
150 |
|
rayvalue(&p); |
151 |
|
multcolor(p.rcol, p.rcoef); |
152 |
+ |
copycolor(r->mcol, p.rcol); |
153 |
|
addcolor(r->rcol, p.rcol); |
154 |
< |
if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) { |
155 |
< |
mirtest = 2.0*bright(p.rcol); |
156 |
< |
mirdist = r->rot + p.rt; |
155 |
< |
} |
154 |
> |
if (r->ro != NULL && isflat(r->ro->otype) && |
155 |
> |
!hastexture | (r->crtype & AMBIENT)) |
156 |
> |
r->rmt = r->rot + raydistance(&p); |
157 |
|
} |
157 |
– |
/* check distance */ |
158 |
– |
d = bright(r->rcol); |
159 |
– |
if (transtest > d) |
160 |
– |
r->rt = transdist; |
161 |
– |
else if (mirtest > d) |
162 |
– |
r->rt = mirdist; |
158 |
|
return(1); |
159 |
|
} |