| 1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 201 |
|
multcolor(nd.mcolor, r->pcol); /* modify material color */ |
| 202 |
|
mirtest = transtest = 0; |
| 203 |
|
mirdist = transdist = r->rot; |
| 204 |
< |
/* get specular component */ |
| 205 |
< |
if ((nd.rspec = m->oargs.farg[3]) > FTINY) { |
| 206 |
< |
nd.specfl |= SP_REFL; |
| 207 |
< |
/* compute specular color */ |
| 208 |
< |
if (m->otype == MAT_METAL) |
| 209 |
< |
copycolor(nd.scolor, nd.mcolor); |
| 210 |
< |
else |
| 211 |
< |
setcolor(nd.scolor, 1.0, 1.0, 1.0); |
| 212 |
< |
scalecolor(nd.scolor, nd.rspec); |
| 213 |
< |
/* check threshold */ |
| 214 |
< |
if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY) |
| 215 |
< |
nd.specfl |= SP_RBLT; |
| 216 |
< |
/* compute reflected ray */ |
| 217 |
< |
for (i = 0; i < 3; i++) |
| 218 |
< |
nd.vrefl[i] = r->rdir[i] + 2.*nd.pdot*nd.pnorm[i]; |
| 219 |
< |
/* penetration? */ |
| 220 |
< |
if (hastexture && DOT(nd.vrefl, r->ron) <= FTINY) |
| 221 |
< |
for (i = 0; i < 3; i++) /* safety measure */ |
| 222 |
< |
nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; |
| 223 |
< |
|
| 224 |
< |
if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) { |
| 225 |
< |
RAY lr; |
| 226 |
< |
if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) { |
| 227 |
< |
VCOPY(lr.rdir, nd.vrefl); |
| 228 |
< |
rayvalue(&lr); |
| 229 |
< |
multcolor(lr.rcol, nd.scolor); |
| 230 |
< |
addcolor(r->rcol, lr.rcol); |
| 231 |
< |
if (!hastexture && nd.specfl & SP_FLAT) { |
| 232 |
< |
mirtest = 2.*bright(lr.rcol); |
| 233 |
< |
mirdist = r->rot + lr.rt; |
| 234 |
< |
} |
| 235 |
< |
} |
| 236 |
< |
} |
| 237 |
< |
} |
| 204 |
> |
nd.rspec = m->oargs.farg[3]; |
| 205 |
|
/* compute transmission */ |
| 206 |
|
if (m->otype == MAT_TRANS) { |
| 207 |
|
nd.trans = m->oargs.farg[5]*(1.0 - nd.rspec); |
| 246 |
|
r->rt = transdist; |
| 247 |
|
return(1); |
| 248 |
|
} |
| 249 |
+ |
/* get specular reflection */ |
| 250 |
+ |
if (nd.rspec > FTINY) { |
| 251 |
+ |
nd.specfl |= SP_REFL; |
| 252 |
+ |
/* compute specular color */ |
| 253 |
+ |
if (m->otype == MAT_METAL) |
| 254 |
+ |
copycolor(nd.scolor, nd.mcolor); |
| 255 |
+ |
else |
| 256 |
+ |
setcolor(nd.scolor, 1.0, 1.0, 1.0); |
| 257 |
+ |
scalecolor(nd.scolor, nd.rspec); |
| 258 |
+ |
/* check threshold */ |
| 259 |
+ |
if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY) |
| 260 |
+ |
nd.specfl |= SP_RBLT; |
| 261 |
+ |
/* compute reflected ray */ |
| 262 |
+ |
for (i = 0; i < 3; i++) |
| 263 |
+ |
nd.vrefl[i] = r->rdir[i] + 2.*nd.pdot*nd.pnorm[i]; |
| 264 |
+ |
/* penetration? */ |
| 265 |
+ |
if (hastexture && DOT(nd.vrefl, r->ron) <= FTINY) |
| 266 |
+ |
for (i = 0; i < 3; i++) /* safety measure */ |
| 267 |
+ |
nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; |
| 268 |
+ |
|
| 269 |
+ |
if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) { |
| 270 |
+ |
RAY lr; |
| 271 |
+ |
if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) { |
| 272 |
+ |
VCOPY(lr.rdir, nd.vrefl); |
| 273 |
+ |
rayvalue(&lr); |
| 274 |
+ |
multcolor(lr.rcol, nd.scolor); |
| 275 |
+ |
addcolor(r->rcol, lr.rcol); |
| 276 |
+ |
if (!hastexture && nd.specfl & SP_FLAT) { |
| 277 |
+ |
mirtest = 2.*bright(lr.rcol); |
| 278 |
+ |
mirdist = r->rot + lr.rt; |
| 279 |
+ |
} |
| 280 |
+ |
} |
| 281 |
+ |
} |
| 282 |
+ |
} |
| 283 |
|
/* diffuse reflection */ |
| 284 |
|
nd.rdiff = 1.0 - nd.trans - nd.rspec; |
| 285 |
|
|
| 290 |
|
gaussamp(r, &nd); |
| 291 |
|
|
| 292 |
|
if (nd.rdiff > FTINY) { /* ambient from this side */ |
| 293 |
< |
ambient(ctmp, r); |
| 293 |
> |
ambient(ctmp, r, hastexture?nd.pnorm:r->ron); |
| 294 |
|
if (nd.specfl & SP_RBLT) |
| 295 |
|
scalecolor(ctmp, 1.0-nd.trans); |
| 296 |
|
else |
| 300 |
|
} |
| 301 |
|
if (nd.tdiff > FTINY) { /* ambient from other side */ |
| 302 |
|
flipsurface(r); |
| 303 |
< |
ambient(ctmp, r); |
| 303 |
> |
ambient(ctmp, r, hastexture?nd.pnorm:r->ron); |
| 304 |
|
if (nd.specfl & SP_TBLT) |
| 305 |
|
scalecolor(ctmp, nd.trans); |
| 306 |
|
else |