106 |
|
{ |
107 |
|
rayorigin(rayOut, rayOutType, rayIn, NULL); |
108 |
|
|
109 |
< |
/* Transfer flux */ |
110 |
< |
copycolor(rayOut -> rcol, rayIn -> rcol); |
111 |
< |
|
112 |
< |
/* Copy caustic flag & direction for transferred rays */ |
113 |
< |
if (rayOutType == PMAP_XFER) { |
114 |
< |
/* rayOut -> rtype |= rayIn -> rtype & SPECULAR; */ |
115 |
< |
rayOut -> rtype |= rayIn -> rtype; |
116 |
< |
VCOPY(rayOut -> rdir, rayIn -> rdir); |
117 |
< |
} |
118 |
< |
else if (fluxAtten) { |
119 |
< |
/* Attenuate and normalise flux for scattered rays */ |
120 |
< |
multcolor(rayOut -> rcol, fluxAtten); |
121 |
< |
colorNorm(rayOut -> rcol); |
122 |
< |
} |
109 |
> |
if (rayIn) { |
110 |
> |
/* Transfer flux */ |
111 |
> |
copycolor(rayOut -> rcol, rayIn -> rcol); |
112 |
> |
|
113 |
> |
/* Copy caustic flag & direction for transferred rays */ |
114 |
> |
if (rayOutType == PMAP_XFER) { |
115 |
> |
/* rayOut -> rtype |= rayIn -> rtype & SPECULAR; */ |
116 |
> |
rayOut -> rtype |= rayIn -> rtype; |
117 |
> |
VCOPY(rayOut -> rdir, rayIn -> rdir); |
118 |
> |
} |
119 |
> |
else if (fluxAtten) { |
120 |
> |
/* Attenuate and normalise flux for scattered rays */ |
121 |
> |
multcolor(rayOut -> rcol, fluxAtten); |
122 |
> |
colorNorm(rayOut -> rcol); |
123 |
> |
} |
124 |
|
|
125 |
< |
/* Propagate index of emitting light source */ |
126 |
< |
rayOut -> rsrc = rayIn -> rsrc; |
125 |
> |
/* Propagate index of emitting light source */ |
126 |
> |
rayOut -> rsrc = rayIn -> rsrc; |
127 |
> |
|
128 |
> |
/* Update maximum photon path distance */ |
129 |
> |
rayOut -> rmax = rayIn -> rmax - rayIn -> rot; |
130 |
> |
} |
131 |
|
} |
132 |
|
|
133 |
|
|
137 |
|
{ |
138 |
|
if (!r -> rlvl) |
139 |
|
/* Add direct photon map at primary hitpoint */ |
140 |
< |
addPhoton(directPmap, r); |
140 |
> |
newPhoton(directPmap, r); |
141 |
|
else { |
142 |
|
/* Add global or precomputed photon map at indirect hitpoint */ |
143 |
< |
addPhoton(preCompPmap ? preCompPmap : globalPmap, r); |
143 |
> |
newPhoton(preCompPmap ? preCompPmap : globalPmap, r); |
144 |
|
|
145 |
|
/* Store caustic photon if specular flag set */ |
146 |
|
if (PMAP_CAUSTICRAY(r)) |
147 |
< |
addPhoton(causticPmap, r); |
147 |
> |
newPhoton(causticPmap, r); |
148 |
|
|
149 |
|
/* Store in contribution photon map */ |
150 |
< |
addPhoton(contribPmap, r); |
150 |
> |
newPhoton(contribPmap, r); |
151 |
|
} |
152 |
|
} |
153 |
|
|
984 |
|
/* Straight replacement? */ |
985 |
|
if (!mat -> oargs.nsargs) { |
986 |
|
/* Skip void modifier! */ |
987 |
< |
if (mat -> omod != OVOID) { |
987 |
> |
if (mat -> omod != OVOID) { |
988 |
|
mat = objptr(mat -> omod); |
989 |
|
photonScatter [mat -> otype] (mat, rayIn); |
990 |
|
} |
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) */ |
1583 |
– |
flipsurface(rayIn); |
1584 |
– |
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); |
1613 |
– |
flipsurface(rayIn); /* Necessary? */ |
1614 |
– |
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); |
1638 |
– |
flipsurface(rayIn); /* Necessary? */ |
1639 |
– |
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 |
|
|
1665 |
|
|
1666 |
|
|
1667 |
|
static int lightPhotonScatter (OBJREC* mat, RAY* ray) |
1668 |
< |
/* Light sources doan' reflect */ |
1668 |
> |
/* Light sources doan' reflect, mang */ |
1669 |
|
{ |
1670 |
|
return 0; |
1671 |
|
} |
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 |
|
} |