1428 |
|
static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) |
1429 |
|
/* Generate new photon ray for BSDF modifier and recurse. */ |
1430 |
|
{ |
1431 |
+ |
int hasthick = (mat->otype == MAT_BSDF); |
1432 |
|
int hitFront; |
1433 |
|
SDError err; |
1434 |
|
SDValue bsdfVal; |
1444 |
|
|
1445 |
|
/* Following code adapted from m_bsdf() */ |
1446 |
|
/* Check arguments */ |
1447 |
< |
if (mat -> oargs.nsargs < 6 || mat -> oargs.nfargs > 9 || |
1447 |
> |
if (mat -> oargs.nsargs < hasthick+5 || mat -> oargs.nfargs > 9 || |
1448 |
|
mat -> oargs.nfargs % 3) |
1449 |
|
objerror(mat, USER, "bad # arguments"); |
1450 |
|
|
1451 |
< |
hitFront = (rayIn -> rod > 0); |
1451 |
> |
hitFront = (rayIn -> rod > 0); |
1452 |
|
|
1453 |
< |
/* Load cal file */ |
1454 |
< |
mf = getfunc(mat, 5, 0x1d, 1); |
1455 |
< |
|
1456 |
< |
/* Get thickness */ |
1453 |
> |
/* Load cal file */ |
1454 |
> |
mf = hasthick ? getfunc(mat, 5, 0x1d, 1) : getfunc(mat, 4, 0xe, 1); |
1455 |
> |
|
1456 |
> |
/* Get thickness */ |
1457 |
> |
nd.thick = 0; |
1458 |
> |
if (hasthick) { |
1459 |
|
nd.thick = evalue(mf -> ep [0]); |
1460 |
|
if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) |
1461 |
|
nd.thick = .0; |
1462 |
+ |
} |
1463 |
|
|
1464 |
|
/* Get BSDF data */ |
1465 |
< |
nd.sd = loadBSDF(mat -> oargs.sarg [1]); |
1465 |
> |
nd.sd = loadBSDF(mat -> oargs.sarg [hasthick]); |
1466 |
|
|
1467 |
|
/* Extra diffuse reflectance from material def */ |
1468 |
|
if (hitFront) { |
1483 |
|
else setcolor(nd.rdiff, mat -> oargs.farg [3], mat -> oargs.farg [4], |
1484 |
|
mat -> oargs.farg [5]); |
1485 |
|
|
1486 |
< |
/* Extra diffuse transmittance from material def */ |
1487 |
< |
if (mat -> oargs.nfargs < 9) |
1488 |
< |
setcolor(nd.tdiff, .0, .0, .0); |
1486 |
> |
/* Extra diffuse transmittance from material def */ |
1487 |
> |
if (mat -> oargs.nfargs < 9) |
1488 |
> |
setcolor(nd.tdiff, .0, .0, .0); |
1489 |
|
else setcolor(nd.tdiff, mat -> oargs.farg [6], mat -> oargs.farg [7], |
1490 |
|
mat -> oargs.farg [8]); |
1491 |
|
|
1492 |
|
nd.mp = mat; |
1493 |
|
nd.pr = rayIn; |
1494 |
< |
|
1494 |
> |
|
1495 |
|
/* Get modifiers */ |
1496 |
|
raytexture(rayIn, mat -> omod); |
1497 |
|
|
1498 |
|
/* Modify diffuse values */ |
1499 |
|
multcolor(nd.rdiff, rayIn -> pcol); |
1500 |
|
multcolor(nd.tdiff, rayIn -> pcol); |
1501 |
< |
|
1501 |
> |
|
1502 |
|
/* Get up vector & xform to world coords */ |
1503 |
< |
upvec [0] = evalue(mf -> ep [1]); |
1504 |
< |
upvec [1] = evalue(mf -> ep [2]); |
1505 |
< |
upvec [2] = evalue(mf -> ep [3]); |
1503 |
> |
upvec [0] = evalue(mf -> ep [hasthick+0]); |
1504 |
> |
upvec [1] = evalue(mf -> ep [hasthick+1]); |
1505 |
> |
upvec [2] = evalue(mf -> ep [hasthick+2]); |
1506 |
|
|
1507 |
|
if (mf -> fxp != &unitxf) { |
1508 |
|
multv3(upvec, upvec, mf -> fxp -> xfm); |
1545 |
|
nd.sr_vpsa [1] = sqrt(nd.sr_vpsa [1]); |
1546 |
|
|
1547 |
|
/* Orient perturbed normal towards incident side */ |
1548 |
< |
if (!hitFront) { |
1548 |
> |
if (!hitFront) { |
1549 |
|
nd.pnorm [0] = -nd.pnorm [0]; |
1550 |
|
nd.pnorm [1] = -nd.pnorm [1]; |
1551 |
|
nd.pnorm [2] = -nd.pnorm [2]; |
1589 |
|
|
1590 |
|
else if ((xi -= ptDiff) <= 0) { |
1591 |
|
/* Diffuse transmission (extra component in material def) */ |
1588 |
– |
flipsurface(rayIn); |
1589 |
– |
nd.thick = -nd.thick; |
1592 |
|
photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.tdiff); |
1593 |
|
diffPhotonScatter(nd.pnorm, &rayOut); |
1594 |
|
transmitted = 1; |
1617 |
|
ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB); |
1618 |
|
multcolor(bsdfRGB, rayIn -> pcol); |
1619 |
|
addcolor(bsdfRGB, nd.tdiff); |
1618 |
– |
flipsurface(rayIn); /* Necessary? */ |
1619 |
– |
nd.thick = -nd.thick; |
1620 |
|
photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, bsdfRGB); |
1621 |
|
transmitted = 1; |
1622 |
|
} |
1640 |
|
/* Apply pattern to spectral component */ |
1641 |
|
ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB); |
1642 |
|
multcolor(bsdfRGB, rayIn -> pcol); |
1643 |
– |
flipsurface(rayIn); /* Necessary? */ |
1644 |
– |
nd.thick = -nd.thick; |
1643 |
|
photonRay(rayIn, &rayOut, PMAP_SPECTRANS, bsdfRGB); |
1644 |
|
transmitted = 1; |
1645 |
|
} |
1654 |
|
/* Clean up */ |
1655 |
|
SDfreeCache(nd.sd); |
1656 |
|
|
1657 |
< |
/* Need to offset ray origin to get past detail geometry? */ |
1657 |
> |
/* Offset outgoing photon origin by thickness to bypass proxy geometry */ |
1658 |
|
if (transmitted && nd.thick != 0) |
1659 |
|
VSUM(rayOut.rorg, rayOut.rorg, rayIn -> ron, -nd.thick); |
1660 |
|
|
1707 |
|
photonScatter [TEX_DATA] = pattexPhotonScatter; |
1708 |
|
|
1709 |
|
photonScatter [MOD_ALIAS] = aliasPhotonScatter; |
1710 |
< |
photonScatter [MAT_BSDF] = bsdfPhotonScatter; |
1710 |
> |
photonScatter [MAT_BSDF] = |
1711 |
> |
photonScatter [MAT_ABSDF] = bsdfPhotonScatter; |
1712 |
|
} |