--- ray/src/rt/pmapmat.c 2015/05/20 15:59:44 2.4 +++ ray/src/rt/pmapmat.c 2021/01/20 19:44:15 2.23 @@ -1,3 +1,6 @@ +#ifndef lint +static const char RCSid[] = "$Id: pmapmat.c,v 2.23 2021/01/20 19:44:15 rschregle Exp $"; +#endif /* ================================================================== Photon map support routines for scattering by materials. @@ -8,7 +11,6 @@ supported by the Swiss National Science Foundation (SNSF, #147053) ================================================================== - $Id: pmapmat.c,v 2.4 2015/05/20 15:59:44 greg Exp $ */ @@ -32,7 +34,7 @@ #define SP_FLAT 010 #define SP_BADU 040 #define MLAMBDA 500 -#define RINDEX 1.52 +#define RINDEX 1.52 #define FRESNE(ci) (exp(-5.85*(ci)) - 0.00287989916) @@ -44,7 +46,7 @@ typedef struct { COLOR mcolor, scolor; FVECT vrefl, prdir, pnorm; double alpha2, rdiff, rspec, trans, tdiff, tspec, pdot; -} NORMDAT; +} NORMDAT; typedef struct { OBJREC *mp; @@ -53,17 +55,31 @@ typedef struct { COLOR mcolor, scolor; FVECT vrefl, prdir, u, v, pnorm; double u_alpha, v_alpha, rdiff, rspec, trans, tdiff, tspec, pdot; -} ANISODAT; +} ANISODAT; typedef struct { OBJREC *mp; - RAY *pr; - FVECT pnorm; - FVECT vray; - double sr_vpsa [2]; - RREAL toloc [3][3]; - RREAL fromloc [3][3]; - double thick; + RAY *pr; + DATARRAY *dp; + COLOR mcolor; + COLOR rdiff; + COLOR tdiff; + double rspec; + double trans; + double tspec; + FVECT pnorm; + double pdot; +} BRDFDAT; + +typedef struct { + OBJREC *mp; + RAY *pr; + FVECT pnorm; + FVECT vray; + double sr_vpsa [2]; + RREAL toloc [3][3]; + RREAL fromloc [3][3]; + double thick; SDData *sd; COLOR runsamp; COLOR rdiff; @@ -104,43 +120,47 @@ void photonRay (const RAY *rayIn, RAY *rayOut, { rayorigin(rayOut, rayOutType, rayIn, NULL); - /* Transfer flux */ - copycolor(rayOut -> rcol, rayIn -> rcol); - - /* Copy caustic flag & direction for transferred rays */ - if (rayOutType == PMAP_XFER) { - /* rayOut -> rtype |= rayIn -> rtype & SPECULAR; */ - rayOut -> rtype |= rayIn -> rtype; - VCOPY(rayOut -> rdir, rayIn -> rdir); - } - else if (fluxAtten) { - /* Attenuate and normalise flux for scattered rays */ - multcolor(rayOut -> rcol, fluxAtten); - colorNorm(rayOut -> rcol); - } + if (rayIn) { + /* Transfer flux */ + copycolor(rayOut -> rcol, rayIn -> rcol); + + /* Copy caustic flag & direction for transferred rays */ + if (rayOutType == PMAP_XFER) { + /* rayOut -> rtype |= rayIn -> rtype & SPECULAR; */ + rayOut -> rtype |= rayIn -> rtype; + VCOPY(rayOut -> rdir, rayIn -> rdir); + } + else if (fluxAtten) { + /* Attenuate and normalise flux for scattered rays */ + multcolor(rayOut -> rcol, fluxAtten); + colorNorm(rayOut -> rcol); + } - /* Propagate index of emitting light source */ - rayOut -> rsrc = rayIn -> rsrc; + /* Propagate index of emitting light source */ + rayOut -> rsrc = rayIn -> rsrc; + + /* Update maximum photon path distance */ + rayOut -> rmax = rayIn -> rmax - rayIn -> rot; + } } - static void addPhotons (const RAY *r) /* Insert photon hits, where applicable */ { if (!r -> rlvl) - /* Add direct photon map at primary hitpoint */ - addPhoton(directPmap, r); + /* Add direct photon at primary hitpoint */ + newPhoton(directPmap, r); else { - /* Add global or precomputed photon map at indirect hitpoint */ - addPhoton(preCompPmap ? preCompPmap : globalPmap, r); + /* Add global or precomputed photon at indirect hitpoint */ + newPhoton(preCompPmap ? preCompPmap : globalPmap, r); /* Store caustic photon if specular flag set */ if (PMAP_CAUSTICRAY(r)) - addPhoton(causticPmap, r); + newPhoton(causticPmap, r); /* Store in contribution photon map */ - addPhoton(contribPmap, r); + newPhoton(contribPmap, r); } } @@ -199,7 +219,7 @@ static int isoSpecPhotonScatter (NORMDAT *nd, RAY *ray int niter, i = 0; /* Set up sample coordinates */ - getperpendicular(u, nd -> pnorm); + getperpendicular(u, nd -> pnorm, 1); fcross(v, nd -> pnorm, u); if (nd -> specfl & SP_REFL) { @@ -233,7 +253,7 @@ static int isoSpecPhotonScatter (NORMDAT *nd, RAY *ray cosp = cos(d); sinp = sin(d); d2 = pmapRandom(scatterState); - d = d2 <= FTINY ? 1 : sqrt(-log(d2) * nd -> alpha2); + d = d2 <= FTINY ? 1 : sqrt(-log(d2) * nd -> alpha2); for (i = 0; i < 3; i++) rayOut -> rdir [i] = nd -> prdir [i] + @@ -254,16 +274,16 @@ static int isoSpecPhotonScatter (NORMDAT *nd, RAY *ray static void diffPhotonScatter (FVECT normal, RAY* rayOut) /* Generate cosine-weighted direction for diffuse ray */ { - const RREAL cosThetaSqr = pmapRandom(scatterState), + const RREAL cosThetaSqr = pmapRandom(scatterState), cosTheta = sqrt(cosThetaSqr), - sinTheta = sqrt(1 - cosThetaSqr), - phi = 2 * PI * pmapRandom(scatterState), + sinTheta = sqrt(1 - cosThetaSqr), + phi = 2 * PI * pmapRandom(scatterState), du = cos(phi) * sinTheta, dv = sin(phi) * sinTheta; FVECT u, v; int i = 0; /* Set up sample coordinates */ - getperpendicular(u, normal); + getperpendicular(u, normal, 1); fcross(v, normal, u); /* Convert theta & phi to cartesian */ @@ -298,6 +318,7 @@ static int normalPhotonScatter (OBJREC *mat, RAY *rayI } else raytexture(rayIn, mat -> omod); + nd.mp = mat; nd.rp = rayIn; /* Get material color */ @@ -414,22 +435,22 @@ static int normalPhotonScatter (OBJREC *mat, RAY *rayI if (hastexture) { /* Perturb */ - for (i = 0; i < 3; i++) + for (i = 0; i < 3; i++) nd.prdir [i] = rayIn -> rdir [i] - rayIn -> pert [i]; - if (DOT(nd.prdir, rayIn -> ron) < -FTINY) + if (DOT(nd.prdir, rayIn -> ron) < -FTINY) normalize(nd.prdir); else VCOPY(nd.prdir, rayIn -> rdir); } else VCOPY(nd.prdir, rayIn -> rdir); if ((nd.specfl & (SP_TRAN | SP_PURE)) == (SP_TRAN | SP_PURE)) - /* Perfect specular transmission */ + /* Perfect specular transmission */ VCOPY(rayOut.rdir, nd.prdir); - else if (!isoSpecPhotonScatter(&nd, &rayOut)) + else if (!isoSpecPhotonScatter(&nd, &rayOut)) return 0; - photonRay(rayIn, &rayOut, PMAP_SPECTRANS, nd.mcolor); + photonRay(rayIn, &rayOut, PMAP_SPECTRANS, nd.mcolor); } else if (xi > (albedo -= prdiff)) { @@ -459,37 +480,36 @@ static int normalPhotonScatter (OBJREC *mat, RAY *rayI -static void getacoords (ANISODAT *np) +static void getacoords (ANISODAT *nd) /* Set up coordinate system for anisotropic sampling; cloned from aniso.c */ { - MFUNC *mf; - int i; + MFUNC *mf; + int i; - mf = getfunc(np->mp, 3, 0x7, 1); - setfunc(np->mp, np->rp); - errno = 0; - - for (i = 0; i < 3; i++) - np->u[i] = evalue(mf->ep[i]); - - if ((errno == EDOM) | (errno == ERANGE)) { - objerror(np->mp, WARNING, "compute error"); - np->specfl |= SP_BADU; - return; - } + mf = getfunc(nd -> mp, 3, 0x7, 1); + setfunc(nd -> mp, nd -> rp); + errno = 0; + + for (i = 0; i < 3; i++) + nd -> u [i] = evalue(mf -> ep [i]); - if (mf->fxp != &unitxf) - multv3(np->u, np->u, mf->fxp->xfm); + if (errno == EDOM || errno == ERANGE) + nd -> u [0] = nd -> u [1] = nd -> u [2] = 0.0; - fcross(np->v, np->pnorm, np->u); - - if (normalize(np->v) == 0.0) { - objerror(np->mp, WARNING, "illegal orientation vector"); - np->specfl |= SP_BADU; - return; - } + if (mf -> fxp != &unitxf) + multv3(nd -> u, nd -> u, mf -> fxp -> xfm); + + fcross(nd -> v, nd -> pnorm, nd -> u); - fcross(np->u, np->v, np->pnorm); + if (normalize(nd -> v) == 0.0) { + if (fabs(nd -> u_alpha - nd -> v_alpha) > 0.001) + objerror(nd -> mp, WARNING, "illegal orientation vector"); + getperpendicular(nd -> u, nd -> pnorm, 1); + fcross(nd -> v, nd -> pnorm, nd -> u); + nd -> u_alpha = nd -> v_alpha = + sqrt(0.5 * (sqr(nd -> u_alpha) + sqr(nd -> v_alpha))); + } + else fcross(nd -> u, nd -> v, nd -> pnorm); } @@ -512,7 +532,7 @@ static int anisoSpecPhotonScatter (ANISODAT *nd, RAY * if (rayOut -> rtype & TRANS) { /* Specular transmission */ - if (DOT(rayIn -> pert, rayIn -> pert) <= FTINY * FTINY) + if (DOT(rayIn -> pert, rayIn -> pert) <= sqr(FTINY)) VCOPY(nd -> prdir, rayIn -> rdir); else { /* perturb */ @@ -548,7 +568,7 @@ static int anisoSpecPhotonScatter (ANISODAT *nd, RAY * } } - return 0; + return 0; } else { @@ -566,7 +586,7 @@ static int anisoSpecPhotonScatter (ANISODAT *nd, RAY * d = d2 <= FTINY ? 1 : sqrt(-log(d2) / (sqr(cosp) / sqr(nd -> u_alpha) + - sqr(sinp) / (nd -> v_alpha * nd -> v_alpha))); + sqr(sinp) / (nd->v_alpha * nd->v_alpha))); for (i = 0; i < 3; i++) h [i] = nd -> pnorm [i] + @@ -595,8 +615,8 @@ static int anisoPhotonScatter (OBJREC *mat, RAY *rayIn if (mat -> oargs.nfargs != (mat -> otype == MAT_TRANS2 ? 8 : 6)) objerror(mat, USER, "bad number of real arguments"); + nd.mp = mat; nd.rp = rayIn; - nd.mp = objptr(rayIn -> ro -> omod); /* get material color */ copycolor(nd.mcolor, mat -> oargs.farg); @@ -640,7 +660,7 @@ static int anisoPhotonScatter (OBJREC *mat, RAY *rayIn if (nd.rspec > FTINY) { nd.specfl |= SP_REFL; - /* comput e specular color */ + /* compute specular color */ if (mat -> otype == MAT_METAL2) copycolor(nd.scolor, nd.mcolor); else setcolor(nd.scolor, 1, 1, 1); @@ -743,7 +763,7 @@ static int dielectricPhotonScatter (OBJREC *mat, RAY * /* get modifiers */ raytexture(rayIn, mat -> omod); - if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > FTINY * FTINY))) + if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > sqr(FTINY)))) /* Perturb normal */ cos1 = raynormal(dnorm, rayIn); else { @@ -753,8 +773,8 @@ static int dielectricPhotonScatter (OBJREC *mat, RAY * /* index of refraction */ nratio = mat -> otype == - MAT_DIELECTRIC ? mat -> oargs.farg [3] + mat -> oargs.farg [4] / MLAMBDA - : mat -> oargs.farg [3] / mat -> oargs.farg [7]; + MAT_DIELECTRIC ? mat->oargs.farg[3] + mat->oargs.farg[4] / MLAMBDA + : mat->oargs.farg[3] / mat->oargs.farg[7]; if (cos1 < 0) { /* inside */ @@ -831,7 +851,7 @@ static int dielectricPhotonScatter (OBJREC *mat, RAY * for (i = 0; i < 3; i++) rayOut.rdir [i] = nratio * rayIn -> rdir [i] + d1 * dnorm [i]; - if (hastexture && DOT(rayOut.rdir, rayIn -> ron) * hastexture >= -FTINY) { + if (hastexture && DOT(rayOut.rdir, rayIn->ron)*hastexture >= -FTINY) { d1 *= hastexture; for (i = 0; i < 3; i++) @@ -850,7 +870,7 @@ static int dielectricPhotonScatter (OBJREC *mat, RAY * photonRay(rayIn, &rayOut, PMAP_SPECREFL, NULL); VSUM(rayOut.rdir, rayIn -> rdir, dnorm, 2 * cos1); - if (hastexture && DOT(rayOut.rdir, rayIn -> ron) * hastexture <= FTINY) + if (hastexture && DOT(rayOut.rdir, rayIn->ron) * hastexture <= FTINY) for (i = 0; i < 3; i++) rayOut.rdir [i] = rayIn -> rdir [i] + 2 * rayIn -> rod * rayIn -> ron [i]; @@ -890,7 +910,7 @@ static int glassPhotonScatter (OBJREC *mat, RAY *rayIn /* reorient if necessary */ if (rayIn -> rod < 0) flipsurface(rayIn); - if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > FTINY * FTINY) )) + if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > sqr(FTINY)))) pdot = raynormal(pnorm, rayIn); else { VCOPY(pnorm, rayIn -> ron); @@ -972,12 +992,15 @@ static int aliasPhotonScatter (OBJREC *mat, RAY *rayIn /* Transfer photon scattering to alias target */ { OBJECT aliasObj; - OBJREC aliasRec; + OBJREC aliasRec, *aliasPtr; /* Straight replacement? */ if (!mat -> oargs.nsargs) { - mat = objptr(mat -> omod); - photonScatter [mat -> otype] (mat, rayIn); + /* Skip void modifier! */ + if (mat -> omod != OVOID) { + mat = objptr(mat -> omod); + photonScatter [mat -> otype] (mat, rayIn); + } return 0; } @@ -986,18 +1009,36 @@ static int aliasPhotonScatter (OBJREC *mat, RAY *rayIn if (mat -> oargs.nsargs != 1) objerror(mat, INTERNAL, "bad # string arguments"); - aliasObj = lastmod(objndx(mat), mat -> oargs.sarg [0]); - - if (aliasObj < 0) - objerror(mat, USER, "bad reference"); - - memcpy(&aliasRec, objptr(aliasObj), sizeof(OBJREC)); + aliasPtr = mat; + aliasObj = objndx(aliasPtr); + /* Follow alias trail */ + do { + aliasObj = aliasPtr -> oargs.nsargs == 1 + ? lastmod(aliasObj, aliasPtr -> oargs.sarg [0]) + : aliasPtr -> omod; + if (aliasObj < 0) + objerror(aliasPtr, USER, "bad reference"); + + aliasPtr = objptr(aliasObj); + } while (aliasPtr -> otype == MOD_ALIAS); + + /* Copy alias object */ + aliasRec = *aliasPtr; + /* Substitute modifier */ aliasRec.omod = mat -> omod; /* Replacement scattering routine */ photonScatter [aliasRec.otype] (&aliasRec, rayIn); + + /* Avoid potential memory leak? */ + if (aliasRec.os != aliasPtr -> os) { + if (aliasPtr -> os) + free_os(aliasPtr); + aliasPtr -> os = aliasRec.os; + } + return 0; } @@ -1026,7 +1067,7 @@ static int clipPhotonScatter (OBJREC *mat, RAY *rayIn) continue; if ((mod = lastmod(obj, mat -> oargs.sarg [i])) == OVOID) { - sprintf(errmsg, "unknown modifier \"%s\"", mat -> oargs.sarg [i]); + sprintf(errmsg, "unknown modifier \"%s\"", mat->oargs.sarg[i]); objerror(mat, WARNING, errmsg); continue; } @@ -1222,7 +1263,7 @@ static int mx_dataPhotonScatter (OBJREC *mat, RAY *ray if (!strcmp(mat -> oargs.sarg [i], VOIDID)) mod [i] = OVOID; else if ((mod [i] = lastmod(obj, mat -> oargs.sarg [i])) == OVOID) { - sprintf(errmsg, "undefined modifier \"%s\"", mat -> oargs.sarg [i]); + sprintf(errmsg, "undefined modifier \"%s\"", mat->oargs.sarg[i]); objerror(mat, USER, errmsg); } @@ -1248,8 +1289,19 @@ static int mx_dataPhotonScatter (OBJREC *mat, RAY *ray if (errno) objerror(mat, WARNING, "compute error"); else { - mat = objptr(mod [pmapRandom(rouletteState) < coef ? 0 : 1]); - photonScatter [mat -> otype] (mat, rayIn); + OBJECT mxMod = mod [pmapRandom(rouletteState) < coef ? 0 : 1]; + + if (mxMod != OVOID) { + mat = objptr(mxMod); + photonScatter [mat -> otype] (mat, rayIn); + } + else { + /* Transfer ray if no modifier */ + RAY rayOut; + + photonRay(rayIn, &rayOut, PMAP_XFER, NULL); + tracePhoton(&rayOut); + } } return 0; @@ -1276,7 +1328,7 @@ static int mx_pdataPhotonScatter (OBJREC *mat, RAY *ra if (!strcmp(mat -> oargs.sarg [i], VOIDID)) mod [i] = OVOID; else if ((mod [i] = lastmod(obj, mat -> oargs.sarg [i])) == OVOID) { - sprintf(errmsg, "undefined modifier \"%s\"", mat -> oargs.sarg [i]); + sprintf(errmsg, "undefined modifier \"%s\"", mat->oargs.sarg[i]); objerror(mat, USER, errmsg); } @@ -1301,8 +1353,19 @@ static int mx_pdataPhotonScatter (OBJREC *mat, RAY *ra if (errno) objerror(mat, WARNING, "compute error"); else { - mat = objptr(mod [pmapRandom(rouletteState) < coef ? 0 : 1]); - photonScatter [mat -> otype] (mat, rayIn); + OBJECT mxMod = mod [pmapRandom(rouletteState) < coef ? 0 : 1]; + + if (mxMod != OVOID) { + mat = objptr(mxMod); + photonScatter [mat -> otype] (mat, rayIn); + } + else { + /* Transfer ray if no modifier */ + RAY rayOut; + + photonRay(rayIn, &rayOut, PMAP_XFER, NULL); + tracePhoton(&rayOut); + } } return 0; @@ -1327,7 +1390,7 @@ static int mx_funcPhotonScatter (OBJREC *mat, RAY *ray if (!strcmp(mat -> oargs.sarg [i], VOIDID)) mod [i] = OVOID; else if ((mod [i] = lastmod(obj, mat -> oargs.sarg [i])) == OVOID) { - sprintf(errmsg, "undefined modifier \"%s\"", mat -> oargs.sarg [i]); + sprintf(errmsg, "undefined modifier \"%s\"", mat->oargs.sarg[i]); objerror(mat, USER, errmsg); } @@ -1341,8 +1404,19 @@ static int mx_funcPhotonScatter (OBJREC *mat, RAY *ray if (errno) objerror(mat, WARNING, "compute error"); else { - mat = objptr(mod [pmapRandom(rouletteState) < coef ? 0 : 1]); - photonScatter [mat -> otype] (mat, rayIn); + OBJECT mxMod = mod [pmapRandom(rouletteState) < coef ? 0 : 1]; + + if (mxMod != OVOID) { + mat = objptr(mxMod); + photonScatter [mat -> otype] (mat, rayIn); + } + else { + /* Transfer ray if no modifier */ + RAY rayOut; + + photonRay(rayIn, &rayOut, PMAP_XFER, NULL); + tracePhoton(&rayOut); + } } return 0; @@ -1374,291 +1448,280 @@ static int pattexPhotonScatter (OBJREC *mat, RAY *rayI -#if 0 - static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) - /* Generate new photon ray for BSDF modifier and recurse. */ - { - int hitFront; - SDError err; - FVECT upvec; - MFUNC *mf; - BSDFDAT nd; - RAY rayOut; +static int setbrdfunc(BRDFDAT *bd) +/* Set up brdf function and variables; ripped off from m_brdf.c */ +{ + FVECT v; + + if (setfunc(bd -> mp, bd -> pr) == 0) + return 0; - /* Following code adapted from m_bsdf() */ - /* Check arguments */ - if (mat -> oargs.nsargs < 6 || mat -> oargs.nfargs > 9 || - mat -> oargs.nfargs % 3) - objerror(mat, USER, "bad # arguments"); - - hitFront = (rayIn -> rod > 0); + /* (Re)Assign func variables */ + multv3(v, bd -> pnorm, funcxf.xfm); + varset("NxP", '=', v [0] / funcxf.sca); + varset("NyP", '=', v [1] / funcxf.sca); + varset("NzP", '=', v [2] / funcxf.sca); + varset("RdotP", '=', + bd -> pdot <= -1. ? -1. : bd -> pdot >= 1. ? 1. : bd -> pdot); + varset("CrP", '=', colval(bd -> mcolor, RED)); + varset("CgP", '=', colval(bd -> mcolor, GRN)); + varset("CbP", '=', colval(bd -> mcolor, BLU)); + + return 1; +} - /* Load cal file */ - mf = getfunc(mat, 5, 0x1d, 1); - - /* Get thickness */ - nd.thick = evalue(mf -> ep [0]); - if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) - nd.thick = .0; - - if (nd.thick != .0 || (!hitFront && !backvis)) { - /* Proxy geometry present, so use it instead and transfer ray */ - photonRay(rayIn, &rayOut, PMAP_XFER, NULL); - tracePhoton(&rayOut); - - return 0; - } - /* Get BSDF data */ - nd.sd = loadBSDF(mat -> oargs.sarg [1]); - - /* Diffuse reflectance */ - if (hitFront) { - if (mat -> oargs.nfargs < 3) - setcolor(nd.rdiff, .0, .0, .0); - else setcolor(nd.rdiff, mat -> oargs.farg [0], mat -> oargs.farg [1], - mat -> oargs.farg [2]); - } - else if (mat -> oargs.nfargs < 6) { - /* Check for absorbing backside */ - if (!backvis && !nd.sd -> rb && !nd.sd -> tf) { - SDfreeCache(nd.sd); - return 0; - } - - setcolor(nd.rdiff, .0, .0, .0); - } - else setcolor(nd.rdiff, mat -> oargs.farg [3], mat -> oargs.farg [4], - mat -> oargs.farg [5]); - /* Diffuse transmittance */ - if (mat -> oargs.nfargs < 9) - setcolor(nd.tdiff, .0, .0, .0); - else setcolor(nd.tdiff, mat -> oargs.farg [6], mat -> oargs.farg [7], - mat -> oargs.farg [8]); - - nd.mp = mat; - nd.pr = rayIn; +static int brdfPhotonScatter (OBJREC *mat, RAY *rayIn) +/* Generate new photon ray for BRTDfunc material and recurse. Only ideal + reflection and transmission are sampled for the specular componentent. */ +{ + int hitfront = 1, hastexture, i; + BRDFDAT nd; + RAY rayOut; + COLOR rspecCol, tspecCol; + double prDiff, ptDiff, prSpec, ptSpec, albedo, xi; + MFUNC *mf; + FVECT bnorm; + + /* Check argz */ + if (mat -> oargs.nsargs < 10 || mat -> oargs.nfargs < 9) + objerror(mat, USER, "bad # arguments"); - /* Get modifiers */ - raytexture(rayIn, mat -> omod); - - /* Modify diffuse values */ - multcolor(nd.rdiff, rayIn -> pcol); - multcolor(nd.tdiff, rayIn -> pcol); - - /* Get up vector & xform to world coords */ - upvec [0] = evalue(mf -> ep [1]); - upvec [1] = evalue(mf -> ep [2]); - upvec [2] = evalue(mf -> ep [3]); - - if (mf -> fxp != &unitxf) { - multv3(upvec, upvec, mf -> fxp -> xfm); - nd.thick *= mf -> fxp -> sca; + nd.mp = mat; + nd.pr = rayIn; + /* Dummiez */ + nd.rspec = nd.tspec = 1.0; + nd.trans = 0.5; + + /* Diffuz reflektanz */ + if (rayIn -> rod > 0.0) + setcolor(nd.rdiff, mat -> oargs.farg[0], mat -> oargs.farg [1], + mat -> oargs.farg [2]); + else + setcolor(nd.rdiff, mat-> oargs.farg [3], mat -> oargs.farg [4], + mat -> oargs.farg [5]); + /* Diffuz tranzmittanz */ + setcolor(nd.tdiff, mat -> oargs.farg [6], mat -> oargs.farg [7], + mat -> oargs.farg [8]); + + /* Get modz */ + raytexture(rayIn, mat -> omod); + hastexture = (DOT(rayIn -> pert, rayIn -> pert) > sqr(FTINY)); + if (hastexture) { + /* Perturb normal */ + nd.pdot = raynormal(nd.pnorm, rayIn); + } + else { + VCOPY(nd.pnorm, rayIn -> ron); + nd.pdot = rayIn -> rod; + } + + if (rayIn -> rod < 0.0) { + /* Orient perturbed valuz */ + nd.pdot = -nd.pdot; + for (i = 0; i < 3; i++) { + nd.pnorm [i] = -nd.pnorm [i]; + rayIn -> pert [i] = -rayIn -> pert [i]; } - if (rayIn -> rox) { - multv3(upvec, upvec, rayIn -> rox -> f.xfm); - nd.thick *= rayIn -> rox -> f.sca; + hitfront = 0; + } + + /* Get pattern kolour, modify diffuz valuz */ + copycolor(nd.mcolor, rayIn -> pcol); + multcolor(nd.rdiff, nd.mcolor); + multcolor(nd.tdiff, nd.mcolor); + + /* Load cal file, evaluate spekula refl/tranz varz */ + nd.dp = NULL; + mf = getfunc(mat, 9, 0x3f, 0); + setbrdfunc(&nd); + errno = 0; + setcolor(rspecCol, + evalue(mf->ep[0]), evalue(mf->ep[1]), evalue(mf->ep[2])); + setcolor(tspecCol, + evalue(mf->ep[3]), evalue(mf->ep[4]), evalue(mf->ep[5])); + if (errno == EDOM || errno == ERANGE) + objerror(mat, WARNING, "compute error"); + else { + /* Set up probz */ + prDiff = colorAvg(nd.rdiff); + ptDiff = colorAvg(nd.tdiff); + prSpec = colorAvg(rspecCol); + ptSpec = colorAvg(tspecCol); + albedo = prDiff + ptDiff + prSpec + ptSpec; + } + + /* Insert direct and indirect photon hitz if diffuz komponent */ + if (prDiff > FTINY || ptDiff > FTINY) + addPhotons(rayIn); + + /* Stochastically sample absorption or scattering evenz */ + if ((xi = pmapRandom(rouletteState)) > albedo) + /* Absorbed */ + return 0; + + if (xi > (albedo -= prSpec)) { + /* Ideal spekula reflekzion */ + photonRay(rayIn, &rayOut, PMAP_SPECREFL, rspecCol); + VSUM(rayOut.rdir, rayIn -> rdir, nd.pnorm, 2 * nd.pdot); + checknorm(rayOut.rdir); + } + else if (xi > (albedo -= ptSpec)) { + /* Ideal spekula tranzmission */ + photonRay(rayIn, &rayOut, PMAP_SPECTRANS, tspecCol); + if (hastexture) { + /* Perturb direkzion */ + VSUB(rayOut.rdir, rayIn -> rdir, rayIn -> pert); + if (normalize(rayOut.rdir) == 0.0) { + objerror(mat, WARNING, "illegal perturbation"); + VCOPY(rayOut.rdir, rayIn -> rdir); + } } + else VCOPY(rayOut.rdir, rayIn -> rdir); + } + else if (xi > (albedo -= prDiff)) { + /* Diffuz reflekzion */ + if (!hitfront) + flipsurface(rayIn); + photonRay(rayIn, &rayOut, PMAP_DIFFREFL, nd.mcolor); + diffPhotonScatter(nd.pnorm, &rayOut); + } + else { + /* Diffuz tranzmission */ + if (hitfront) + flipsurface(rayIn); + photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.mcolor); + bnorm [0] = -nd.pnorm [0]; + bnorm [1] = -nd.pnorm [1]; + bnorm [2] = -nd.pnorm [2]; + diffPhotonScatter(bnorm, &rayOut); + } + + tracePhoton(&rayOut); + return 0; +} + + + +int brdf2PhotonScatter (OBJREC *mat, RAY *rayIn) +/* Generate new photon ray for procedural or data driven BRDF material and + recurse. Only diffuse reflection and transmission are sampled. */ +{ + BRDFDAT nd; + RAY rayOut; + double dtmp, prDiff, ptDiff, albedo, xi; + MFUNC *mf; + FVECT bnorm; + + /* Check argz */ + if (mat -> oargs.nsargs < (hasdata(mat -> otype) ? 4 : 2) || + mat -> oargs.nfargs < (mat -> otype == MAT_TFUNC || + mat -> otype == MAT_TDATA ? 6 : 4)) + objerror(mat, USER, "bad # arguments"); - /* Perturb normal */ - raynormal(nd.pnorm, rayIn); - - /* Xform incident dir to local BSDF coords */ - err = SDcompXform(nd.toloc, nd.pnorm, upvec); - - if (!err) { - nd.vray [0] = -rayIn -> rdir [0]; - nd.vray [1] = -rayIn -> rdir [1]; - nd.vray [2] = -rayIn -> rdir [2]; - err = SDmapDir(nd.vray, nd.toloc, nd.vray); - } - - if (!err) - err = SDinvXform(nd.fromloc, nd.toloc); - - if (err) { - objerror(mat, WARNING, "Illegal orientation vector"); + if (rayIn -> rod < 0.0) { + /* Hit backside; reorient if visible, else transfer photon */ + if (!backvis) { + photonRay(rayIn, &rayOut, PMAP_XFER, NULL); + tracePhoton(&rayOut); return 0; } - /* Determine BSDF resolution */ - err = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, SDqueryMin + SDqueryMax, nd.sd); - - if (err) - objerror(mat, USER, transSDError(err)); - - nd.sr_vpsa [0] = sqrt(nd.sr_vpsa [0]); - nd.sr_vpsa [1] = sqrt(nd.sr_vpsa [1]); + raytexture(rayIn, mat -> omod); + flipsurface(rayIn); + } + else raytexture(rayIn, mat -> omod); - /* Orient perturbed normal towards incident side */ - if (!hitFront) { - nd.pnorm [0] = -nd.pnorm [0]; - nd.pnorm [1] = -nd.pnorm [1]; - nd.pnorm [2] = -nd.pnorm [2]; - } - - /* Following code adapted from SDsampBSDF() */ - { - SDSpectralDF *rdf, *tdf; - SDValue bsdfVal; - double xi, rhoDiff = 0; - float coef [SDmaxCh]; - int i, j, n, nr; - SDComponent *sdc; - const SDCDst **cdarr = NULL; - - /* Get diffuse albedo (?) */ - if (hitFront) { - bsdfVal = nd.sd -> rLambFront; - rdf = nd.sd -> rf; - tdf = nd.sd -> tf ? nd.sd -> tf : nd.sd -> tb; - } - else { - bsdfVal = nd.sd -> rLambBack; - rdf = nd.sd -> rb; - tdf = nd.sd -> tb ? nd.sd -> tb : nd.sd -> tf; - } - - rhoDiff = bsdfVal.cieY; - bsdfVal.cieY += nd.sd -> tLamb.cieY; - - /* Allocate non-diffuse sampling */ - i = nr = rdf ? rdf -> ncomp : 0; - j = tdf ? tdf -> ncomp : 0; - n = i + j; - - if (n > 0 && !(cdarr = (const SDCDst**)malloc(n * sizeof(SDCDst*)))) - objerror(mat, USER, transSDError(SDEmemory)); - - while (j-- > 0) { - /* Sum up non-diffuse transmittance */ - cdarr [i + j] = (*tdf -> comp [j].func -> getCDist)(nd.vray, &tdf -> comp [j]); - - if (!cdarr [i + j]) - cdarr [i + j] = &SDemptyCD; - else bsdfVal.cieY += cdarr [i + j] -> cTotal; - } - - while (i-- > 0) { - /* Sum up non-diffuse reflectance */ - cdarr [i] = (*rdf -> comp [i].func -> getCDist)(nd.vray, &rdf -> comp [i]); - - if (!cdarr [i]) - cdarr [i] = &SDemptyCD; - else bsdfVal.cieY += cdarr [i] -> cTotal; - } - - if (bsdfVal.cieY <= FTINY) { - /* Don't bother sampling, just absorb photon */ - if (cdarr) - free(cdarr); - return 0; - } - - /* Insert direct and indirect photon hits if diffuse component */ - if (rhoDiff > FTINY || nd.sd -> tLamb.cieY > FTINY) - addPhotons(rayIn); - - xi = pmapRandom(rouletteState); - - if ((xi -= rhoDiff) <= 0) { - /* Diffuse reflection */ - photonRay(rayIn, &rayOut, PMAP_DIFFREFL, nd.rdiff); - diffPhotonScatter(nd.pnorm, &rayOut); - } - else if ((xi -= nd.sd -> tLamb.cieY) <= 0) { - /* Diffuse transmission */ - flipsurface(rayIn); - photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.tdiff); - bsdfVal.spec = nd.sd -> tLamb.spec; - diffPhotonScatter(nd.pnorm, &rayOut); - } - else { - int rayOutType; - COLOR bsdfRGB; - - /* Non-diffuse CDF inversion (?) */ - for (i = 0; i < n && (xi -= cdarr [i] -> cTotal) > 0; i++); - - if (i >= n) { - /* Absorbed -- photon went Deer Hunter */ - if (cdarr) - free(cdarr); - return 0; - } + nd.mp = mat; + nd.pr = rayIn; + + /* Material kolour */ + setcolor(nd.mcolor, mat -> oargs.farg [0], mat -> oargs.farg [1], + mat -> oargs.farg [2]); + /* Spekula komponent */ + nd.rspec = mat -> oargs.farg [3]; + + /* Tranzmittanz */ + if (mat -> otype == MAT_TFUNC || mat -> otype == MAT_TDATA) { + nd.trans = mat -> oargs.farg [4] * (1.0 - nd.rspec); + nd.tspec = nd.trans * mat -> oargs.farg [5]; + dtmp = nd.trans - nd.tspec; + setcolor(nd.tdiff, dtmp, dtmp, dtmp); + } + else { + nd.tspec = nd.trans = 0.0; + setcolor(nd.tdiff, 0.0, 0.0, 0.0); + } + + /* Reflektanz */ + dtmp = 1.0 - nd.trans - nd.rspec; + setcolor(nd.rdiff, dtmp, dtmp, dtmp); + /* Perturb normal */ + nd.pdot = raynormal(nd.pnorm, rayIn); + /* Modify material kolour */ + multcolor(nd.mcolor, rayIn -> pcol); + multcolor(nd.rdiff, nd.mcolor); + multcolor(nd.tdiff, nd.mcolor); + + /* Load auxiliary filez */ + if (hasdata(mat -> otype)) { + nd.dp = getdata(mat -> oargs.sarg [1]); + getfunc(mat, 2, 0, 0); + } + else { + nd.dp = NULL; + getfunc(mat, 1, 0, 0); + } - if (i < nr) { - /* Non-diffuse reflection */ - sdc = &rdf -> comp [i]; - rayOutType = PMAP_SPECREFL; - } - else { - /* Non-diffuse transmission */ - sdc = &tdf -> comp [i - nr]; - rayOutType = PMAP_SPECTRANS; - } - - /* Generate non-diff sample dir */ - VCOPY(rayOut.rdir, nd.vray); - err = (*sdc -> func -> sampCDist) - (rayOut.rdir, pmapRandom(scatterState), cdarr [i]); - if (err) - objerror(mat, USER, transSDError(SDEinternal)); + /* Set up probz */ + prDiff = colorAvg(nd.rdiff); + ptDiff = colorAvg(nd.tdiff); + albedo = prDiff + ptDiff; - /* Get colour */ - j = (*sdc -> func -> getBSDFs)(coef, rayOut.rdir, nd.vray, sdc); - - if (j <= 0) { - sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error", - nd.sd -> name); - objerror(mat, USER, transSDError(SDEinternal)); - } - - bsdfVal.spec = sdc -> cspec [0]; - rhoDiff = coef [0]; - - while (--j) { - c_cmix(&bsdfVal.spec, rhoDiff, &bsdfVal.spec, coef [j], - &sdc -> cspec [j]); - rhoDiff += coef [j]; - } - - /* ? */ - c_ccvt(&bsdfVal.spec, C_CSXY + C_CSSPEC); - ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB); - - /* Xform outgoing dir to world coords */ - if ((err = SDmapDir(rayOut.rdir, nd.fromloc, rayOut.rdir))) { - objerror(mat, USER, transSDError(err)); - return 0; - } - - photonRay(rayIn, &rayOut, rayOutType, bsdfRGB); - } - - if (cdarr) - free(cdarr); - } - - /* Clean up BSDF */ - SDfreeCache(nd.sd); + /* Insert direct and indirect photon hitz if diffuz komponent */ + if (prDiff > FTINY || ptDiff > FTINY) + addPhotons(rayIn); - tracePhoton(&rayOut); + /* Stochastically sample absorption or scattering evenz */ + if ((xi = pmapRandom(rouletteState)) > albedo) + /* Absorbed */ return 0; + + if (xi > (albedo -= prDiff)) { + /* Diffuz reflekzion */ + photonRay(rayIn, &rayOut, PMAP_DIFFREFL, nd.rdiff); + diffPhotonScatter(nd.pnorm, &rayOut); } -#else + else { + /* Diffuz tranzmission */ + flipsurface(rayIn); + photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.tdiff); + bnorm [0] = -nd.pnorm [0]; + bnorm [1] = -nd.pnorm [1]; + bnorm [2] = -nd.pnorm [2]; + diffPhotonScatter(bnorm, &rayOut); + } + tracePhoton(&rayOut); + return 0; +} + + + /* + ================================================================== The following code is (c) Lucerne University of Applied Sciences and Arts, supported by the Swiss National Science Foundation (SNSF, #147053) -*/ + ================================================================== +*/ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) /* Generate new photon ray for BSDF modifier and recurse. */ { + int hasthick = (mat->otype == MAT_BSDF); int hitFront; SDError err; SDValue bsdfVal; @@ -1667,36 +1730,32 @@ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) BSDFDAT nd; RAY rayOut; COLOR bsdfRGB; + int transmitted; double prDiff, ptDiff, prDiffSD, ptDiffSD, prSpecSD, ptSpecSD, - albedo, xi, xi2; - const double patAlb = colorAvg(rayIn -> pcol); + albedo, xi; + const double patAlb = bright(rayIn -> pcol); /* Following code adapted from m_bsdf() */ /* Check arguments */ - if (mat -> oargs.nsargs < 6 || mat -> oargs.nfargs > 9 || + if (mat -> oargs.nsargs < hasthick+5 || mat -> oargs.nfargs > 9 || mat -> oargs.nfargs % 3) objerror(mat, USER, "bad # arguments"); - hitFront = (rayIn -> rod > 0); + hitFront = (rayIn -> rod > 0); - /* Load cal file */ - mf = getfunc(mat, 5, 0x1d, 1); - - /* Get thickness */ - nd.thick = evalue(mf -> ep [0]); - if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) - nd.thick = .0; - - if (nd.thick != .0 || (!hitFront && !backvis)) { - /* Proxy geometry present, so use it instead and transfer ray */ - photonRay(rayIn, &rayOut, PMAP_XFER, NULL); - tracePhoton(&rayOut); - - return 0; + /* Load cal file */ + mf = hasthick ? getfunc(mat, 5, 0x1d, 1) : getfunc(mat, 4, 0xe, 1); + + /* Get thickness */ + nd.thick = 0; + if (hasthick) { + nd.thick = evalue(mf -> ep [0]); + if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) + nd.thick = .0; } /* Get BSDF data */ - nd.sd = loadBSDF(mat -> oargs.sarg [1]); + nd.sd = loadBSDF(mat -> oargs.sarg [hasthick]); /* Extra diffuse reflectance from material def */ if (hitFront) { @@ -1706,10 +1765,10 @@ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) mat -> oargs.farg [2]); } else if (mat -> oargs.nfargs < 6) { - /* Check for absorbing backside */ - if (!backvis && !nd.sd -> rb && !nd.sd -> tf) { - SDfreeCache(nd.sd); - return 0; + /* Check for absorbing backside */ + if (!backvis && !nd.sd -> rb && !nd.sd -> tf) { + SDfreeCache(nd.sd); + return 0; } setcolor(nd.rdiff, .0, .0, .0); @@ -1717,26 +1776,26 @@ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) else setcolor(nd.rdiff, mat -> oargs.farg [3], mat -> oargs.farg [4], mat -> oargs.farg [5]); - /* Extra diffuse transmittance from material def */ - if (mat -> oargs.nfargs < 9) - setcolor(nd.tdiff, .0, .0, .0); + /* Extra diffuse transmittance from material def */ + if (mat -> oargs.nfargs < 9) + setcolor(nd.tdiff, .0, .0, .0); else setcolor(nd.tdiff, mat -> oargs.farg [6], mat -> oargs.farg [7], mat -> oargs.farg [8]); nd.mp = mat; nd.pr = rayIn; - + /* Get modifiers */ raytexture(rayIn, mat -> omod); /* Modify diffuse values */ multcolor(nd.rdiff, rayIn -> pcol); multcolor(nd.tdiff, rayIn -> pcol); - + /* Get up vector & xform to world coords */ - upvec [0] = evalue(mf -> ep [1]); - upvec [1] = evalue(mf -> ep [2]); - upvec [2] = evalue(mf -> ep [3]); + upvec [0] = evalue(mf -> ep [hasthick+0]); + upvec [1] = evalue(mf -> ep [hasthick+1]); + upvec [2] = evalue(mf -> ep [hasthick+2]); if (mf -> fxp != &unitxf) { multv3(upvec, upvec, mf -> fxp -> xfm); @@ -1770,7 +1829,8 @@ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) } /* Determine BSDF resolution */ - err = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, SDqueryMin + SDqueryMax, nd.sd); + err = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, + SDqueryMin + SDqueryMax, nd.sd); if (err) objerror(mat, USER, transSDError(err)); @@ -1779,7 +1839,7 @@ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) nd.sr_vpsa [1] = sqrt(nd.sr_vpsa [1]); /* Orient perturbed normal towards incident side */ - if (!hitFront) { + if (!hitFront) { nd.pnorm [0] = -nd.pnorm [0]; nd.pnorm [1] = -nd.pnorm [1]; nd.pnorm [2] = -nd.pnorm [2]; @@ -1807,12 +1867,14 @@ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) if (prDiff + ptDiff + prDiffSD + ptDiffSD > FTINY) addPhotons(rayIn); - xi = xi2 = pmapRandom(rouletteState); + xi = pmapRandom(rouletteState); if (xi > albedo) /* Absorbtion */ return 0; + transmitted = 0; + if ((xi -= prDiff) <= 0) { /* Diffuse reflection (extra component in material def) */ photonRay(rayIn, &rayOut, PMAP_DIFFREFL, nd.rdiff); @@ -1821,15 +1883,15 @@ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) else if ((xi -= ptDiff) <= 0) { /* Diffuse transmission (extra component in material def) */ - flipsurface(rayIn); photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.tdiff); - diffPhotonScatter(nd.pnorm, &rayOut); + diffPhotonScatter(nd.pnorm, &rayOut); + transmitted = 1; } - + else { /* Sample SDF */ if ((xi -= prDiffSD) <= 0) { /* Diffuse SDF reflection (constant component) */ - if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2, + if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), SDsampDf | SDsampR, nd.sd))) objerror(mat, USER, transSDError(err)); @@ -1841,7 +1903,7 @@ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) else if ((xi -= ptDiffSD) <= 0) { /* Diffuse SDF transmission (constant component) */ - if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2, + if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), SDsampDf | SDsampT, nd.sd))) objerror(mat, USER, transSDError(err)); @@ -1849,13 +1911,13 @@ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB); multcolor(bsdfRGB, rayIn -> pcol); addcolor(bsdfRGB, nd.tdiff); - flipsurface(rayIn); /* Necessary? */ photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, bsdfRGB); + transmitted = 1; } else if ((xi -= prSpecSD) <= 0) { /* Non-diffuse ("specular") SDF reflection */ - if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2, + if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), SDsampSp | SDsampR, nd.sd))) objerror(mat, USER, transSDError(err)); @@ -1865,15 +1927,15 @@ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) else { /* Non-diffuse ("specular") SDF transmission */ - if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2, + if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), SDsampSp | SDsampT, nd.sd))) objerror(mat, USER, transSDError(err)); /* Apply pattern to spectral component */ ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB); multcolor(bsdfRGB, rayIn -> pcol); - flipsurface(rayIn); /* Necessary? */ photonRay(rayIn, &rayOut, PMAP_SPECTRANS, bsdfRGB); + transmitted = 1; } /* Xform outgoing dir to world coords */ @@ -1886,15 +1948,18 @@ static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) /* Clean up */ SDfreeCache(nd.sd); + /* Offset outgoing photon origin by thickness to bypass proxy geometry */ + if (transmitted && nd.thick != 0) + VSUM(rayOut.rorg, rayOut.rorg, rayIn -> ron, -nd.thick); + tracePhoton(&rayOut); return 0; } -#endif static int lightPhotonScatter (OBJREC* mat, RAY* ray) -/* Light sources doan' reflect */ +/* Light sources doan' reflect, mang */ { return 0; } @@ -1905,14 +1970,15 @@ void initPhotonScatterFuncs () /* Init photonScatter[] dispatch table */ { int i; - + + /* Catch-all for inconsistencies */ for (i = 0; i < NUMOTYPE; i++) photonScatter [i] = o_default; - + photonScatter [MAT_LIGHT] = photonScatter [MAT_ILLUM] = photonScatter [MAT_GLOW] = photonScatter [MAT_SPOT] = lightPhotonScatter; - + photonScatter [MAT_PLASTIC] = photonScatter [MAT_METAL] = photonScatter [MAT_TRANS] = normalPhotonScatter; @@ -1921,7 +1987,7 @@ void initPhotonScatterFuncs () photonScatter [MAT_DIELECTRIC] = photonScatter [MAT_INTERFACE] = dielectricPhotonScatter; - + photonScatter [MAT_MIST] = mistPhotonScatter; photonScatter [MAT_GLASS] = glassPhotonScatter; photonScatter [MAT_CLIP] = clipPhotonScatter; @@ -1929,12 +1995,20 @@ void initPhotonScatterFuncs () photonScatter [MIX_FUNC] = mx_funcPhotonScatter; photonScatter [MIX_DATA] = mx_dataPhotonScatter; photonScatter [MIX_PICT]= mx_pdataPhotonScatter; - + photonScatter [PAT_BDATA] = photonScatter [PAT_CDATA] = photonScatter [PAT_BFUNC] = photonScatter [PAT_CFUNC] = photonScatter [PAT_CPICT] = photonScatter [TEX_FUNC] = photonScatter [TEX_DATA] = pattexPhotonScatter; - + photonScatter [MOD_ALIAS] = aliasPhotonScatter; - photonScatter [MAT_BSDF] = bsdfPhotonScatter; + photonScatter [MAT_BRTDF] = brdfPhotonScatter; + + photonScatter [MAT_PFUNC] = photonScatter [MAT_MFUNC] = + photonScatter [MAT_PDATA] = photonScatter [MAT_MDATA] = + photonScatter [MAT_TFUNC] = photonScatter [MAT_TDATA] = + brdf2PhotonScatter; + + photonScatter [MAT_BSDF] = photonScatter [MAT_ABSDF] = + bsdfPhotonScatter; }