1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
38 |
|
|
39 |
|
typedef struct { |
40 |
|
OBJREC *mp; /* material pointer */ |
41 |
– |
RAY *pr; /* intersected ray */ |
41 |
|
COLOR mcolor; /* color of this material */ |
42 |
|
COLOR scolor; /* color of specular component */ |
43 |
|
FVECT vrefl; /* vector in direction of reflected ray */ |
44 |
+ |
FVECT prdir; /* vector in transmitted direction */ |
45 |
|
double alpha2; /* roughness squared times 2 */ |
46 |
|
double rdiff, rspec; /* reflected specular, diffuse */ |
47 |
|
double trans; /* transmissivity */ |
91 |
|
/* worth using? */ |
92 |
|
if (dtmp > FTINY) { |
93 |
|
copycolor(ctmp, np->scolor); |
94 |
< |
dtmp *= omega; |
94 |
> |
dtmp *= omega / np->pdot; |
95 |
|
scalecolor(ctmp, dtmp); |
96 |
|
addcolor(cval, ctmp); |
97 |
|
} |
108 |
|
if (ldot < -FTINY && np->tspec > FTINY && np->alpha2 > FTINY) { |
109 |
|
/* |
110 |
|
* Compute specular transmission. Specular transmission |
111 |
< |
* is unaffected by material color. |
111 |
> |
* is always modified by material color. |
112 |
|
*/ |
113 |
|
/* roughness + source */ |
114 |
|
dtmp = np->alpha2 + omega/(2.0*PI); |
115 |
|
/* gaussian */ |
116 |
< |
dtmp = exp((DOT(np->pr->rdir,ldir)-1.)/dtmp)/(2.*PI)/dtmp; |
116 |
> |
dtmp = exp((DOT(np->prdir,ldir)-1.)/dtmp)/(2.*PI)/dtmp; |
117 |
|
/* worth using? */ |
118 |
|
if (dtmp > FTINY) { |
119 |
< |
dtmp *= np->tspec * omega; |
120 |
< |
setcolor(ctmp, dtmp, dtmp, dtmp); |
119 |
> |
copycolor(ctmp, np->mcolor); |
120 |
> |
dtmp *= np->tspec * omega / np->pdot; |
121 |
> |
scalecolor(ctmp, dtmp); |
122 |
|
addcolor(cval, ctmp); |
123 |
|
} |
124 |
|
} |
130 |
|
register RAY *r; |
131 |
|
{ |
132 |
|
NORMDAT nd; |
133 |
+ |
double transtest, transdist; |
134 |
|
double dtmp; |
135 |
|
COLOR ctmp; |
136 |
|
register int i; |
141 |
|
if (r->crtype & SHADOW && m->otype != MAT_TRANS) |
142 |
|
return; |
143 |
|
nd.mp = m; |
142 |
– |
nd.pr = r; |
144 |
|
/* get material color */ |
145 |
|
setcolor(nd.mcolor, m->oargs.farg[0], |
146 |
|
m->oargs.farg[1], |
154 |
|
/* get modifiers */ |
155 |
|
raytexture(r, m->omod); |
156 |
|
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
157 |
+ |
if (nd.pdot < .001) |
158 |
+ |
nd.pdot = .001; /* non-zero for dirnorm() */ |
159 |
|
multcolor(nd.mcolor, r->pcol); /* modify material color */ |
160 |
< |
r->rt = r->rot; /* default ray length */ |
160 |
> |
transtest = 0; |
161 |
|
/* get specular component */ |
162 |
|
nd.rspec = m->oargs.farg[3]; |
163 |
|
|
184 |
|
rayvalue(&lr); |
185 |
|
multcolor(lr.rcol, nd.scolor); |
186 |
|
addcolor(r->rcol, lr.rcol); |
184 |
– |
if (nd.rspec > 0.5 && m->omod == OVOID) |
185 |
– |
r->rt = r->rot + lr.rt; |
187 |
|
} |
188 |
|
} |
189 |
|
} |
192 |
|
nd.trans = m->oargs.farg[5]*(1.0 - nd.rspec); |
193 |
|
nd.tspec = nd.trans * m->oargs.farg[6]; |
194 |
|
nd.tdiff = nd.trans - nd.tspec; |
195 |
+ |
if (r->crtype & SHADOW || DOT(r->pert,r->pert) <= FTINY*FTINY) { |
196 |
+ |
VCOPY(nd.prdir, r->rdir); |
197 |
+ |
transtest = 2; |
198 |
+ |
} else { |
199 |
+ |
for (i = 0; i < 3; i++) /* perturb direction */ |
200 |
+ |
nd.prdir[i] = r->rdir[i] - .75*r->pert[i]; |
201 |
+ |
normalize(nd.prdir); |
202 |
+ |
} |
203 |
|
} else |
204 |
|
nd.tdiff = nd.tspec = nd.trans = 0.0; |
205 |
|
/* transmitted ray */ |
206 |
|
if (nd.tspec > FTINY && nd.alpha2 <= FTINY) { |
207 |
|
RAY lr; |
208 |
|
if (rayorigin(&lr, r, TRANS, nd.tspec) == 0) { |
209 |
< |
VCOPY(lr.rdir, r->rdir); |
209 |
> |
VCOPY(lr.rdir, nd.prdir); |
210 |
|
rayvalue(&lr); |
211 |
|
scalecolor(lr.rcol, nd.tspec); |
212 |
+ |
multcolor(lr.rcol, nd.mcolor); /* modified by color */ |
213 |
|
addcolor(r->rcol, lr.rcol); |
214 |
< |
if (nd.tspec > .5) |
215 |
< |
r->rt = r->rot + lr.rt; |
214 |
> |
transtest *= bright(lr.rcol); |
215 |
> |
transdist = r->rot + lr.rt; |
216 |
|
} |
217 |
|
} |
218 |
|
if (r->crtype & SHADOW) /* the rest is shadow */ |
239 |
|
scalecolor(ctmp, nd.tdiff); |
240 |
|
else |
241 |
|
scalecolor(ctmp, nd.trans); |
242 |
< |
multcolor(ctmp, nd.mcolor); |
242 |
> |
multcolor(ctmp, nd.mcolor); /* modified by color */ |
243 |
|
addcolor(r->rcol, ctmp); |
244 |
|
flipsurface(r); |
245 |
|
} |
246 |
|
/* add direct component */ |
247 |
|
direct(r, dirnorm, &nd); |
248 |
+ |
/* check distance */ |
249 |
+ |
if (transtest > bright(r->rcol)) |
250 |
+ |
r->rt = transdist; |
251 |
|
} |