| 401 |
|
int |
| 402 |
|
m_bsdf(OBJREC *m, RAY *r) |
| 403 |
|
{ |
| 404 |
+ |
int hitfront; |
| 405 |
|
COLOR ctmp; |
| 406 |
|
SDError ec; |
| 407 |
|
FVECT upvec, vtmp; |
| 411 |
|
if ((m->oargs.nsargs < 6) | (m->oargs.nfargs > 9) | |
| 412 |
|
(m->oargs.nfargs % 3)) |
| 413 |
|
objerror(m, USER, "bad # arguments"); |
| 414 |
< |
|
| 414 |
> |
/* record surface struck */ |
| 415 |
> |
hitfront = (r->rod > .0); |
| 416 |
|
/* load cal file */ |
| 417 |
|
mf = getfunc(m, 5, 0x1d, 1); |
| 418 |
|
/* get thickness */ |
| 427 |
|
} |
| 428 |
|
/* check other rays to pass */ |
| 429 |
|
if (nd.thick != 0 && (!(r->crtype & (SPECULAR|AMBIENT)) || |
| 430 |
< |
nd.thick > .0 ^ r->rod > .0)) { |
| 430 |
> |
nd.thick > .0 ^ hitfront)) { |
| 431 |
|
raytrans(r); /* hide our proxy */ |
| 432 |
|
return(1); |
| 433 |
|
} |
| 434 |
|
/* get BSDF data */ |
| 435 |
|
nd.sd = loadBSDF(m->oargs.sarg[1]); |
| 436 |
|
/* diffuse reflectance */ |
| 437 |
< |
if (r->rod > .0) { |
| 437 |
> |
if (hitfront) { |
| 438 |
|
if (m->oargs.nfargs < 3) |
| 439 |
|
setcolor(nd.rdiff, .0, .0, .0); |
| 440 |
|
else |
| 499 |
|
SDfreeCache(nd.sd); |
| 500 |
|
return(1); |
| 501 |
|
} |
| 502 |
< |
if (r->rod < .0) { /* perturb normal towards hit */ |
| 502 |
> |
if (!hitfront) { /* perturb normal towards hit */ |
| 503 |
|
nd.pnorm[0] = -nd.pnorm[0]; |
| 504 |
|
nd.pnorm[1] = -nd.pnorm[1]; |
| 505 |
|
nd.pnorm[2] = -nd.pnorm[2]; |
| 512 |
|
copycolor(ctmp, nd.rdiff); |
| 513 |
|
addcolor(ctmp, nd.runsamp); |
| 514 |
|
if (bright(ctmp) > FTINY) { /* ambient from reflection */ |
| 515 |
< |
if (r->rod < .0) |
| 515 |
> |
if (!hitfront) |
| 516 |
|
flipsurface(r); |
| 517 |
|
multambient(ctmp, r, nd.pnorm); |
| 518 |
|
addcolor(r->rcol, ctmp); |
| 519 |
< |
if (r->rod < .0) |
| 519 |
> |
if (!hitfront) |
| 520 |
|
flipsurface(r); |
| 521 |
|
} |
| 522 |
|
copycolor(ctmp, nd.tdiff); |
| 523 |
|
addcolor(ctmp, nd.tunsamp); |
| 524 |
|
if (bright(ctmp) > FTINY) { /* ambient from other side */ |
| 525 |
|
FVECT bnorm; |
| 526 |
< |
if (r->rod > .0) |
| 526 |
> |
if (hitfront) |
| 527 |
|
flipsurface(r); |
| 528 |
|
bnorm[0] = -nd.pnorm[0]; |
| 529 |
|
bnorm[1] = -nd.pnorm[1]; |
| 536 |
|
} else |
| 537 |
|
multambient(ctmp, r, bnorm); |
| 538 |
|
addcolor(r->rcol, ctmp); |
| 539 |
< |
if (r->rod > .0) |
| 539 |
> |
if (hitfront) |
| 540 |
|
flipsurface(r); |
| 541 |
|
} |
| 542 |
|
/* add direct component */ |
| 548 |
|
direct(r, dir_brdf, &nd); /* reflection first */ |
| 549 |
|
VCOPY(vtmp, r->rop); /* offset for transmitted */ |
| 550 |
|
VSUM(r->rop, vtmp, r->ron, -nd.thick); |
| 551 |
< |
direct(r, dir_btdf, &nd); |
| 551 |
> |
direct(r, dir_btdf, &nd); /* separate transmission */ |
| 552 |
|
VCOPY(r->rop, vtmp); |
| 553 |
|
} |
| 554 |
|
/* clean up */ |