| 2 |
|
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 4 |
|
/* |
| 5 |
< |
================================================================== |
| 5 |
> |
|
| 6 |
> |
====================================================================== |
| 7 |
|
Photon map support routines for scattering by materials. |
| 8 |
|
|
| 9 |
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
| 10 |
|
(c) Fraunhofer Institute for Solar Energy Systems, |
| 11 |
+ |
supported by the German Research Foundation |
| 12 |
+ |
(DFG LU-204/10-2, "Fassadenintegrierte Regelsysteme FARESYS") |
| 13 |
|
(c) Lucerne University of Applied Sciences and Arts, |
| 14 |
< |
supported by the Swiss National Science Foundation (SNSF, #147053) |
| 15 |
< |
================================================================== |
| 14 |
> |
supported by the Swiss National Science Foundation |
| 15 |
> |
(SNSF #147053, "Daylight Redirecting Components") |
| 16 |
> |
====================================================================== |
| 17 |
|
|
| 18 |
|
*/ |
| 19 |
|
|
| 38 |
|
#define SP_FLAT 010 |
| 39 |
|
#define SP_BADU 040 |
| 40 |
|
#define MLAMBDA 500 |
| 41 |
< |
#define RINDEX 1.52 |
| 41 |
> |
#define RINDEX 1.52 |
| 42 |
|
#define FRESNE(ci) (exp(-5.85*(ci)) - 0.00287989916) |
| 43 |
|
|
| 44 |
|
|
| 50 |
|
COLOR mcolor, scolor; |
| 51 |
|
FVECT vrefl, prdir, pnorm; |
| 52 |
|
double alpha2, rdiff, rspec, trans, tdiff, tspec, pdot; |
| 53 |
< |
} NORMDAT; |
| 53 |
> |
} NORMDAT; |
| 54 |
|
|
| 55 |
|
typedef struct { |
| 56 |
|
OBJREC *mp; |
| 59 |
|
COLOR mcolor, scolor; |
| 60 |
|
FVECT vrefl, prdir, u, v, pnorm; |
| 61 |
|
double u_alpha, v_alpha, rdiff, rspec, trans, tdiff, tspec, pdot; |
| 62 |
< |
} ANISODAT; |
| 62 |
> |
} ANISODAT; |
| 63 |
|
|
| 64 |
|
typedef struct { |
| 65 |
|
OBJREC *mp; |
| 66 |
< |
RAY *pr; |
| 67 |
< |
FVECT pnorm; |
| 68 |
< |
FVECT vray; |
| 69 |
< |
double sr_vpsa [2]; |
| 70 |
< |
RREAL toloc [3][3]; |
| 71 |
< |
RREAL fromloc [3][3]; |
| 72 |
< |
double thick; |
| 66 |
> |
RAY *pr; |
| 67 |
> |
DATARRAY *dp; |
| 68 |
> |
COLOR mcolor; |
| 69 |
> |
COLOR rdiff; |
| 70 |
> |
COLOR tdiff; |
| 71 |
> |
double rspec; |
| 72 |
> |
double trans; |
| 73 |
> |
double tspec; |
| 74 |
> |
FVECT pnorm; |
| 75 |
> |
double pdot; |
| 76 |
> |
} BRDFDAT; |
| 77 |
> |
|
| 78 |
> |
typedef struct { |
| 79 |
> |
OBJREC *mp; |
| 80 |
> |
RAY *pr; |
| 81 |
> |
FVECT pnorm; |
| 82 |
> |
FVECT vray; |
| 83 |
> |
double sr_vpsa [2]; |
| 84 |
> |
RREAL toloc [3][3]; |
| 85 |
> |
RREAL fromloc [3][3]; |
| 86 |
> |
double thick; |
| 87 |
|
SDData *sd; |
| 88 |
|
COLOR runsamp; |
| 89 |
|
COLOR rdiff; |
| 142 |
|
|
| 143 |
|
/* Propagate index of emitting light source */ |
| 144 |
|
rayOut -> rsrc = rayIn -> rsrc; |
| 145 |
+ |
|
| 146 |
+ |
/* Update maximum photon path distance */ |
| 147 |
+ |
rayOut -> rmax = rayIn -> rmax - rayIn -> rot; |
| 148 |
|
} |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
|
| 131 |
– |
|
| 152 |
|
static void addPhotons (const RAY *r) |
| 153 |
|
/* Insert photon hits, where applicable */ |
| 154 |
|
{ |
| 155 |
|
if (!r -> rlvl) |
| 156 |
< |
/* Add direct photon map at primary hitpoint */ |
| 156 |
> |
/* Add direct photon at primary hitpoint */ |
| 157 |
|
newPhoton(directPmap, r); |
| 158 |
|
else { |
| 159 |
< |
/* Add global or precomputed photon map at indirect hitpoint */ |
| 159 |
> |
/* Add global or precomputed photon at indirect hitpoint */ |
| 160 |
|
newPhoton(preCompPmap ? preCompPmap : globalPmap, r); |
| 161 |
|
|
| 162 |
|
/* Store caustic photon if specular flag set */ |
| 223 |
|
int niter, i = 0; |
| 224 |
|
|
| 225 |
|
/* Set up sample coordinates */ |
| 226 |
< |
getperpendicular(u, nd -> pnorm, 1); |
| 226 |
> |
getperpendicular(u, nd -> pnorm, 1); |
| 227 |
|
fcross(v, nd -> pnorm, u); |
| 228 |
|
|
| 229 |
|
if (nd -> specfl & SP_REFL) { |
| 257 |
|
cosp = cos(d); |
| 258 |
|
sinp = sin(d); |
| 259 |
|
d2 = pmapRandom(scatterState); |
| 260 |
< |
d = d2 <= FTINY ? 1 : sqrt(-log(d2) * nd -> alpha2); |
| 260 |
> |
d = d2 <= FTINY ? 1 : sqrt(-log(d2) * nd -> alpha2); |
| 261 |
|
|
| 262 |
|
for (i = 0; i < 3; i++) |
| 263 |
|
rayOut -> rdir [i] = nd -> prdir [i] + |
| 278 |
|
static void diffPhotonScatter (FVECT normal, RAY* rayOut) |
| 279 |
|
/* Generate cosine-weighted direction for diffuse ray */ |
| 280 |
|
{ |
| 281 |
< |
const RREAL cosThetaSqr = pmapRandom(scatterState), |
| 281 |
> |
const RREAL cosThetaSqr = pmapRandom(scatterState), |
| 282 |
|
cosTheta = sqrt(cosThetaSqr), |
| 283 |
< |
sinTheta = sqrt(1 - cosThetaSqr), |
| 284 |
< |
phi = 2 * PI * pmapRandom(scatterState), |
| 283 |
> |
sinTheta = sqrt(1 - cosThetaSqr), |
| 284 |
> |
phi = 2 * PI * pmapRandom(scatterState), |
| 285 |
|
du = cos(phi) * sinTheta, dv = sin(phi) * sinTheta; |
| 286 |
|
FVECT u, v; |
| 287 |
|
int i = 0; |
| 322 |
|
} |
| 323 |
|
else raytexture(rayIn, mat -> omod); |
| 324 |
|
|
| 325 |
+ |
nd.mp = mat; |
| 326 |
|
nd.rp = rayIn; |
| 327 |
|
|
| 328 |
|
/* Get material color */ |
| 335 |
|
if ((nd.alpha2 *= nd.alpha2) <= FTINY) |
| 336 |
|
nd.specfl |= SP_PURE; |
| 337 |
|
|
| 317 |
– |
if (rayIn -> ro != NULL && isflat(rayIn -> ro -> otype)) |
| 318 |
– |
nd.specfl |= SP_FLAT; |
| 319 |
– |
|
| 338 |
|
/* Perturb normal */ |
| 339 |
|
if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > sqr(FTINY)) )) |
| 340 |
|
nd.pdot = raynormal(nd.pnorm, rayIn); |
| 343 |
|
nd.pdot = rayIn -> rod; |
| 344 |
|
} |
| 345 |
|
|
| 346 |
< |
nd.pdot = max(nd.pdot, .001); |
| 346 |
> |
if (!hastexture && rayIn -> ro != NULL && isflat(rayIn -> ro -> otype)) |
| 347 |
> |
nd.specfl |= SP_FLAT; |
| 348 |
> |
|
| 349 |
> |
nd.pdot = max(nd.pdot, .001); |
| 350 |
|
|
| 351 |
|
/* Modify material color */ |
| 352 |
|
multcolor(nd.mcolor, rayIn -> pcol); |
| 439 |
|
|
| 440 |
|
if (hastexture) { |
| 441 |
|
/* Perturb */ |
| 442 |
< |
for (i = 0; i < 3; i++) |
| 442 |
> |
for (i = 0; i < 3; i++) |
| 443 |
|
nd.prdir [i] = rayIn -> rdir [i] - rayIn -> pert [i]; |
| 444 |
|
|
| 445 |
< |
if (DOT(nd.prdir, rayIn -> ron) < -FTINY) |
| 445 |
> |
if (DOT(nd.prdir, rayIn -> ron) < -FTINY) |
| 446 |
|
normalize(nd.prdir); |
| 447 |
|
else VCOPY(nd.prdir, rayIn -> rdir); |
| 448 |
|
} |
| 449 |
|
else VCOPY(nd.prdir, rayIn -> rdir); |
| 450 |
|
|
| 451 |
|
if ((nd.specfl & (SP_TRAN | SP_PURE)) == (SP_TRAN | SP_PURE)) |
| 452 |
< |
/* Perfect specular transmission */ |
| 452 |
> |
/* Perfect specular transmission */ |
| 453 |
|
VCOPY(rayOut.rdir, nd.prdir); |
| 454 |
< |
else if (!isoSpecPhotonScatter(&nd, &rayOut)) |
| 454 |
> |
else if (!isoSpecPhotonScatter(&nd, &rayOut)) |
| 455 |
|
return 0; |
| 456 |
|
|
| 457 |
< |
photonRay(rayIn, &rayOut, PMAP_SPECTRANS, nd.mcolor); |
| 457 |
> |
photonRay(rayIn, &rayOut, PMAP_SPECTRANS, nd.mcolor); |
| 458 |
|
} |
| 459 |
|
|
| 460 |
|
else if (xi > (albedo -= prdiff)) { |
| 484 |
|
|
| 485 |
|
|
| 486 |
|
|
| 487 |
< |
static void getacoords (ANISODAT *np) |
| 487 |
> |
static void getacoords (ANISODAT *nd) |
| 488 |
|
/* Set up coordinate system for anisotropic sampling; cloned from aniso.c */ |
| 489 |
|
{ |
| 490 |
< |
MFUNC *mf; |
| 491 |
< |
int i; |
| 490 |
> |
MFUNC *mf; |
| 491 |
> |
int i; |
| 492 |
|
|
| 493 |
< |
mf = getfunc(np->mp, 3, 0x7, 1); |
| 494 |
< |
setfunc(np->mp, np->rp); |
| 495 |
< |
errno = 0; |
| 496 |
< |
|
| 497 |
< |
for (i = 0; i < 3; i++) |
| 498 |
< |
np->u[i] = evalue(mf->ep[i]); |
| 478 |
< |
|
| 479 |
< |
if ((errno == EDOM) | (errno == ERANGE)) { |
| 480 |
< |
objerror(np->mp, WARNING, "compute error"); |
| 481 |
< |
np->specfl |= SP_BADU; |
| 482 |
< |
return; |
| 483 |
< |
} |
| 493 |
> |
mf = getfunc(nd -> mp, 3, 0x7, 1); |
| 494 |
> |
setfunc(nd -> mp, nd -> rp); |
| 495 |
> |
errno = 0; |
| 496 |
> |
|
| 497 |
> |
for (i = 0; i < 3; i++) |
| 498 |
> |
nd -> u [i] = evalue(mf -> ep [i]); |
| 499 |
|
|
| 500 |
< |
if (mf->fxp != &unitxf) |
| 501 |
< |
multv3(np->u, np->u, mf->fxp->xfm); |
| 500 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
| 501 |
> |
nd -> u [0] = nd -> u [1] = nd -> u [2] = 0.0; |
| 502 |
|
|
| 503 |
< |
fcross(np->v, np->pnorm, np->u); |
| 504 |
< |
|
| 505 |
< |
if (normalize(np->v) == 0.0) { |
| 506 |
< |
objerror(np->mp, WARNING, "illegal orientation vector"); |
| 492 |
< |
np->specfl |= SP_BADU; |
| 493 |
< |
return; |
| 494 |
< |
} |
| 503 |
> |
if (mf -> fxp != &unitxf) |
| 504 |
> |
multv3(nd -> u, nd -> u, mf -> fxp -> xfm); |
| 505 |
> |
|
| 506 |
> |
fcross(nd -> v, nd -> pnorm, nd -> u); |
| 507 |
|
|
| 508 |
< |
fcross(np->u, np->v, np->pnorm); |
| 508 |
> |
if (normalize(nd -> v) == 0.0) { |
| 509 |
> |
if (fabs(nd -> u_alpha - nd -> v_alpha) > 0.001) |
| 510 |
> |
objerror(nd -> mp, WARNING, "illegal orientation vector"); |
| 511 |
> |
getperpendicular(nd -> u, nd -> pnorm, 1); |
| 512 |
> |
fcross(nd -> v, nd -> pnorm, nd -> u); |
| 513 |
> |
nd -> u_alpha = nd -> v_alpha = |
| 514 |
> |
sqrt(0.5 * (sqr(nd -> u_alpha) + sqr(nd -> v_alpha))); |
| 515 |
> |
} |
| 516 |
> |
else fcross(nd -> u, nd -> v, nd -> pnorm); |
| 517 |
|
} |
| 518 |
|
|
| 519 |
|
|
| 536 |
|
if (rayOut -> rtype & TRANS) { |
| 537 |
|
/* Specular transmission */ |
| 538 |
|
|
| 539 |
< |
if (DOT(rayIn -> pert, rayIn -> pert) <= FTINY * FTINY) |
| 539 |
> |
if (DOT(rayIn -> pert, rayIn -> pert) <= sqr(FTINY)) |
| 540 |
|
VCOPY(nd -> prdir, rayIn -> rdir); |
| 541 |
|
else { |
| 542 |
|
/* perturb */ |
| 572 |
|
} |
| 573 |
|
} |
| 574 |
|
|
| 575 |
< |
return 0; |
| 575 |
> |
return 0; |
| 576 |
|
} |
| 577 |
|
|
| 578 |
|
else { |
| 590 |
|
d = d2 <= FTINY ? 1 |
| 591 |
|
: sqrt(-log(d2) / |
| 592 |
|
(sqr(cosp) / sqr(nd -> u_alpha) + |
| 593 |
< |
sqr(sinp) / (nd -> v_alpha * nd -> v_alpha))); |
| 593 |
> |
sqr(sinp) / (nd->v_alpha * nd->v_alpha))); |
| 594 |
|
|
| 595 |
|
for (i = 0; i < 3; i++) |
| 596 |
|
h [i] = nd -> pnorm [i] + |
| 619 |
|
if (mat -> oargs.nfargs != (mat -> otype == MAT_TRANS2 ? 8 : 6)) |
| 620 |
|
objerror(mat, USER, "bad number of real arguments"); |
| 621 |
|
|
| 622 |
+ |
nd.mp = mat; |
| 623 |
|
nd.rp = rayIn; |
| 603 |
– |
nd.mp = objptr(rayIn -> ro -> omod); |
| 624 |
|
|
| 625 |
|
/* get material color */ |
| 626 |
|
copycolor(nd.mcolor, mat -> oargs.farg); |
| 664 |
|
if (nd.rspec > FTINY) { |
| 665 |
|
nd.specfl |= SP_REFL; |
| 666 |
|
|
| 667 |
< |
/* comput e specular color */ |
| 667 |
> |
/* compute specular color */ |
| 668 |
|
if (mat -> otype == MAT_METAL2) |
| 669 |
|
copycolor(nd.scolor, nd.mcolor); |
| 670 |
|
else setcolor(nd.scolor, 1, 1, 1); |
| 767 |
|
/* get modifiers */ |
| 768 |
|
raytexture(rayIn, mat -> omod); |
| 769 |
|
|
| 770 |
< |
if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > FTINY * FTINY))) |
| 770 |
> |
if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > sqr(FTINY)))) |
| 771 |
|
/* Perturb normal */ |
| 772 |
|
cos1 = raynormal(dnorm, rayIn); |
| 773 |
|
else { |
| 777 |
|
|
| 778 |
|
/* index of refraction */ |
| 779 |
|
nratio = mat -> otype == |
| 780 |
< |
MAT_DIELECTRIC ? mat -> oargs.farg [3] + mat -> oargs.farg [4] / MLAMBDA |
| 781 |
< |
: mat -> oargs.farg [3] / mat -> oargs.farg [7]; |
| 780 |
> |
MAT_DIELECTRIC ? mat->oargs.farg[3] + mat->oargs.farg[4] / MLAMBDA |
| 781 |
> |
: mat->oargs.farg[3] / mat->oargs.farg[7]; |
| 782 |
|
|
| 783 |
|
if (cos1 < 0) { |
| 784 |
|
/* inside */ |
| 855 |
|
for (i = 0; i < 3; i++) |
| 856 |
|
rayOut.rdir [i] = nratio * rayIn -> rdir [i] + d1 * dnorm [i]; |
| 857 |
|
|
| 858 |
< |
if (hastexture && DOT(rayOut.rdir, rayIn -> ron) * hastexture >= -FTINY) { |
| 858 |
> |
if (hastexture && DOT(rayOut.rdir, rayIn->ron)*hastexture >= -FTINY) { |
| 859 |
|
d1 *= hastexture; |
| 860 |
|
|
| 861 |
|
for (i = 0; i < 3; i++) |
| 874 |
|
photonRay(rayIn, &rayOut, PMAP_SPECREFL, NULL); |
| 875 |
|
VSUM(rayOut.rdir, rayIn -> rdir, dnorm, 2 * cos1); |
| 876 |
|
|
| 877 |
< |
if (hastexture && DOT(rayOut.rdir, rayIn -> ron) * hastexture <= FTINY) |
| 877 |
> |
if (hastexture && DOT(rayOut.rdir, rayIn->ron) * hastexture <= FTINY) |
| 878 |
|
for (i = 0; i < 3; i++) |
| 879 |
|
rayOut.rdir [i] = rayIn -> rdir [i] + |
| 880 |
|
2 * rayIn -> rod * rayIn -> ron [i]; |
| 914 |
|
/* reorient if necessary */ |
| 915 |
|
if (rayIn -> rod < 0) |
| 916 |
|
flipsurface(rayIn); |
| 917 |
< |
if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > FTINY * FTINY) )) |
| 917 |
> |
if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > sqr(FTINY)))) |
| 918 |
|
pdot = raynormal(pnorm, rayIn); |
| 919 |
|
else { |
| 920 |
|
VCOPY(pnorm, rayIn -> ron); |
| 996 |
|
/* Transfer photon scattering to alias target */ |
| 997 |
|
{ |
| 998 |
|
OBJECT aliasObj; |
| 999 |
< |
OBJREC aliasRec; |
| 999 |
> |
OBJREC aliasRec, *aliasPtr; |
| 1000 |
|
|
| 1001 |
|
/* Straight replacement? */ |
| 1002 |
|
if (!mat -> oargs.nsargs) { |
| 1013 |
|
if (mat -> oargs.nsargs != 1) |
| 1014 |
|
objerror(mat, INTERNAL, "bad # string arguments"); |
| 1015 |
|
|
| 1016 |
< |
aliasObj = lastmod(objndx(mat), mat -> oargs.sarg [0]); |
| 1017 |
< |
|
| 998 |
< |
if (aliasObj < 0) |
| 999 |
< |
objerror(mat, USER, "bad reference"); |
| 1000 |
< |
|
| 1001 |
< |
memcpy(&aliasRec, objptr(aliasObj), sizeof(OBJREC)); |
| 1016 |
> |
aliasPtr = mat; |
| 1017 |
> |
aliasObj = objndx(aliasPtr); |
| 1018 |
|
|
| 1019 |
+ |
/* Follow alias trail */ |
| 1020 |
+ |
do { |
| 1021 |
+ |
aliasObj = aliasPtr -> oargs.nsargs == 1 |
| 1022 |
+ |
? lastmod(aliasObj, aliasPtr -> oargs.sarg [0]) |
| 1023 |
+ |
: aliasPtr -> omod; |
| 1024 |
+ |
if (aliasObj < 0) |
| 1025 |
+ |
objerror(aliasPtr, USER, "bad reference"); |
| 1026 |
+ |
|
| 1027 |
+ |
aliasPtr = objptr(aliasObj); |
| 1028 |
+ |
} while (aliasPtr -> otype == MOD_ALIAS); |
| 1029 |
+ |
|
| 1030 |
+ |
/* Copy alias object */ |
| 1031 |
+ |
aliasRec = *aliasPtr; |
| 1032 |
+ |
|
| 1033 |
|
/* Substitute modifier */ |
| 1034 |
|
aliasRec.omod = mat -> omod; |
| 1035 |
|
|
| 1036 |
|
/* Replacement scattering routine */ |
| 1037 |
|
photonScatter [aliasRec.otype] (&aliasRec, rayIn); |
| 1038 |
+ |
|
| 1039 |
+ |
/* Avoid potential memory leak? */ |
| 1040 |
+ |
if (aliasRec.os != aliasPtr -> os) { |
| 1041 |
+ |
if (aliasPtr -> os) |
| 1042 |
+ |
free_os(aliasPtr); |
| 1043 |
+ |
aliasPtr -> os = aliasRec.os; |
| 1044 |
+ |
} |
| 1045 |
+ |
|
| 1046 |
|
return 0; |
| 1047 |
|
} |
| 1048 |
|
|
| 1071 |
|
continue; |
| 1072 |
|
|
| 1073 |
|
if ((mod = lastmod(obj, mat -> oargs.sarg [i])) == OVOID) { |
| 1074 |
< |
sprintf(errmsg, "unknown modifier \"%s\"", mat -> oargs.sarg [i]); |
| 1074 |
> |
sprintf(errmsg, "unknown modifier \"%s\"", mat->oargs.sarg[i]); |
| 1075 |
|
objerror(mat, WARNING, errmsg); |
| 1076 |
|
continue; |
| 1077 |
|
} |
| 1267 |
|
if (!strcmp(mat -> oargs.sarg [i], VOIDID)) |
| 1268 |
|
mod [i] = OVOID; |
| 1269 |
|
else if ((mod [i] = lastmod(obj, mat -> oargs.sarg [i])) == OVOID) { |
| 1270 |
< |
sprintf(errmsg, "undefined modifier \"%s\"", mat -> oargs.sarg [i]); |
| 1270 |
> |
sprintf(errmsg, "undefined modifier \"%s\"", mat->oargs.sarg[i]); |
| 1271 |
|
objerror(mat, USER, errmsg); |
| 1272 |
|
} |
| 1273 |
|
|
| 1332 |
|
if (!strcmp(mat -> oargs.sarg [i], VOIDID)) |
| 1333 |
|
mod [i] = OVOID; |
| 1334 |
|
else if ((mod [i] = lastmod(obj, mat -> oargs.sarg [i])) == OVOID) { |
| 1335 |
< |
sprintf(errmsg, "undefined modifier \"%s\"", mat -> oargs.sarg [i]); |
| 1335 |
> |
sprintf(errmsg, "undefined modifier \"%s\"", mat->oargs.sarg[i]); |
| 1336 |
|
objerror(mat, USER, errmsg); |
| 1337 |
|
} |
| 1338 |
|
|
| 1394 |
|
if (!strcmp(mat -> oargs.sarg [i], VOIDID)) |
| 1395 |
|
mod [i] = OVOID; |
| 1396 |
|
else if ((mod [i] = lastmod(obj, mat -> oargs.sarg [i])) == OVOID) { |
| 1397 |
< |
sprintf(errmsg, "undefined modifier \"%s\"", mat -> oargs.sarg [i]); |
| 1397 |
> |
sprintf(errmsg, "undefined modifier \"%s\"", mat->oargs.sarg[i]); |
| 1398 |
|
objerror(mat, USER, errmsg); |
| 1399 |
|
} |
| 1400 |
|
|
| 1452 |
|
|
| 1453 |
|
|
| 1454 |
|
|
| 1455 |
+ |
static int setbrdfunc(BRDFDAT *bd) |
| 1456 |
+ |
/* Set up brdf function and variables; ripped off from m_brdf.c */ |
| 1457 |
+ |
{ |
| 1458 |
+ |
FVECT v; |
| 1459 |
+ |
|
| 1460 |
+ |
if (setfunc(bd -> mp, bd -> pr) == 0) |
| 1461 |
+ |
return 0; |
| 1462 |
+ |
|
| 1463 |
+ |
/* (Re)Assign func variables */ |
| 1464 |
+ |
multv3(v, bd -> pnorm, funcxf.xfm); |
| 1465 |
+ |
varset("NxP", '=', v [0] / funcxf.sca); |
| 1466 |
+ |
varset("NyP", '=', v [1] / funcxf.sca); |
| 1467 |
+ |
varset("NzP", '=', v [2] / funcxf.sca); |
| 1468 |
+ |
varset("RdotP", '=', |
| 1469 |
+ |
bd -> pdot <= -1. ? -1. : bd -> pdot >= 1. ? 1. : bd -> pdot); |
| 1470 |
+ |
varset("CrP", '=', colval(bd -> mcolor, RED)); |
| 1471 |
+ |
varset("CgP", '=', colval(bd -> mcolor, GRN)); |
| 1472 |
+ |
varset("CbP", '=', colval(bd -> mcolor, BLU)); |
| 1473 |
+ |
|
| 1474 |
+ |
return 1; |
| 1475 |
+ |
} |
| 1476 |
+ |
|
| 1477 |
+ |
|
| 1478 |
+ |
|
| 1479 |
+ |
static int brdfPhotonScatter (OBJREC *mat, RAY *rayIn) |
| 1480 |
+ |
/* Generate new photon ray for BRTDfunc material and recurse. Only ideal |
| 1481 |
+ |
reflection and transmission are sampled for the specular componentent. */ |
| 1482 |
+ |
{ |
| 1483 |
+ |
int hitfront = 1, hastexture, i; |
| 1484 |
+ |
BRDFDAT nd; |
| 1485 |
+ |
RAY rayOut; |
| 1486 |
+ |
COLOR rspecCol, tspecCol; |
| 1487 |
+ |
double prDiff, ptDiff, prSpec, ptSpec, albedo, xi; |
| 1488 |
+ |
MFUNC *mf; |
| 1489 |
+ |
FVECT bnorm; |
| 1490 |
+ |
|
| 1491 |
+ |
/* Check argz */ |
| 1492 |
+ |
if (mat -> oargs.nsargs < 10 || mat -> oargs.nfargs < 9) |
| 1493 |
+ |
objerror(mat, USER, "bad # arguments"); |
| 1494 |
+ |
|
| 1495 |
+ |
nd.mp = mat; |
| 1496 |
+ |
nd.pr = rayIn; |
| 1497 |
+ |
/* Dummiez */ |
| 1498 |
+ |
nd.rspec = nd.tspec = 1.0; |
| 1499 |
+ |
nd.trans = 0.5; |
| 1500 |
+ |
|
| 1501 |
+ |
/* Diffuz reflektanz */ |
| 1502 |
+ |
if (rayIn -> rod > 0.0) |
| 1503 |
+ |
setcolor(nd.rdiff, mat -> oargs.farg[0], mat -> oargs.farg [1], |
| 1504 |
+ |
mat -> oargs.farg [2]); |
| 1505 |
+ |
else |
| 1506 |
+ |
setcolor(nd.rdiff, mat-> oargs.farg [3], mat -> oargs.farg [4], |
| 1507 |
+ |
mat -> oargs.farg [5]); |
| 1508 |
+ |
/* Diffuz tranzmittanz */ |
| 1509 |
+ |
setcolor(nd.tdiff, mat -> oargs.farg [6], mat -> oargs.farg [7], |
| 1510 |
+ |
mat -> oargs.farg [8]); |
| 1511 |
+ |
|
| 1512 |
+ |
/* Get modz */ |
| 1513 |
+ |
raytexture(rayIn, mat -> omod); |
| 1514 |
+ |
hastexture = (DOT(rayIn -> pert, rayIn -> pert) > sqr(FTINY)); |
| 1515 |
+ |
if (hastexture) { |
| 1516 |
+ |
/* Perturb normal */ |
| 1517 |
+ |
nd.pdot = raynormal(nd.pnorm, rayIn); |
| 1518 |
+ |
} |
| 1519 |
+ |
else { |
| 1520 |
+ |
VCOPY(nd.pnorm, rayIn -> ron); |
| 1521 |
+ |
nd.pdot = rayIn -> rod; |
| 1522 |
+ |
} |
| 1523 |
+ |
|
| 1524 |
+ |
if (rayIn -> rod < 0.0) { |
| 1525 |
+ |
/* Orient perturbed valuz */ |
| 1526 |
+ |
nd.pdot = -nd.pdot; |
| 1527 |
+ |
for (i = 0; i < 3; i++) { |
| 1528 |
+ |
nd.pnorm [i] = -nd.pnorm [i]; |
| 1529 |
+ |
rayIn -> pert [i] = -rayIn -> pert [i]; |
| 1530 |
+ |
} |
| 1531 |
+ |
|
| 1532 |
+ |
hitfront = 0; |
| 1533 |
+ |
} |
| 1534 |
+ |
|
| 1535 |
+ |
/* Get pattern kolour, modify diffuz valuz */ |
| 1536 |
+ |
copycolor(nd.mcolor, rayIn -> pcol); |
| 1537 |
+ |
multcolor(nd.rdiff, nd.mcolor); |
| 1538 |
+ |
multcolor(nd.tdiff, nd.mcolor); |
| 1539 |
+ |
|
| 1540 |
+ |
/* Load cal file, evaluate spekula refl/tranz varz */ |
| 1541 |
+ |
nd.dp = NULL; |
| 1542 |
+ |
mf = getfunc(mat, 9, 0x3f, 0); |
| 1543 |
+ |
setbrdfunc(&nd); |
| 1544 |
+ |
errno = 0; |
| 1545 |
+ |
setcolor(rspecCol, |
| 1546 |
+ |
evalue(mf->ep[0]), evalue(mf->ep[1]), evalue(mf->ep[2])); |
| 1547 |
+ |
setcolor(tspecCol, |
| 1548 |
+ |
evalue(mf->ep[3]), evalue(mf->ep[4]), evalue(mf->ep[5])); |
| 1549 |
+ |
if ((errno == EDOM) | (errno == ERANGE)) |
| 1550 |
+ |
objerror(mat, WARNING, "compute error"); |
| 1551 |
+ |
else { |
| 1552 |
+ |
/* Set up probz */ |
| 1553 |
+ |
prDiff = colorAvg(nd.rdiff); |
| 1554 |
+ |
ptDiff = colorAvg(nd.tdiff); |
| 1555 |
+ |
prSpec = colorAvg(rspecCol); |
| 1556 |
+ |
ptSpec = colorAvg(tspecCol); |
| 1557 |
+ |
albedo = prDiff + ptDiff + prSpec + ptSpec; |
| 1558 |
+ |
} |
| 1559 |
+ |
|
| 1560 |
+ |
/* Insert direct and indirect photon hitz if diffuz komponent */ |
| 1561 |
+ |
if (prDiff > FTINY || ptDiff > FTINY) |
| 1562 |
+ |
addPhotons(rayIn); |
| 1563 |
+ |
|
| 1564 |
+ |
/* Stochastically sample absorption or scattering evenz */ |
| 1565 |
+ |
if ((xi = pmapRandom(rouletteState)) > albedo) |
| 1566 |
+ |
/* Absorbed */ |
| 1567 |
+ |
return 0; |
| 1568 |
+ |
|
| 1569 |
+ |
if (xi > (albedo -= prSpec)) { |
| 1570 |
+ |
/* Ideal spekula reflekzion */ |
| 1571 |
+ |
photonRay(rayIn, &rayOut, PMAP_SPECREFL, rspecCol); |
| 1572 |
+ |
VSUM(rayOut.rdir, rayIn -> rdir, nd.pnorm, 2 * nd.pdot); |
| 1573 |
+ |
checknorm(rayOut.rdir); |
| 1574 |
+ |
} |
| 1575 |
+ |
else if (xi > (albedo -= ptSpec)) { |
| 1576 |
+ |
/* Ideal spekula tranzmission */ |
| 1577 |
+ |
photonRay(rayIn, &rayOut, PMAP_SPECTRANS, tspecCol); |
| 1578 |
+ |
if (hastexture) { |
| 1579 |
+ |
/* Perturb direkzion */ |
| 1580 |
+ |
VSUB(rayOut.rdir, rayIn -> rdir, rayIn -> pert); |
| 1581 |
+ |
if (normalize(rayOut.rdir) == 0.0) { |
| 1582 |
+ |
objerror(mat, WARNING, "illegal perturbation"); |
| 1583 |
+ |
VCOPY(rayOut.rdir, rayIn -> rdir); |
| 1584 |
+ |
} |
| 1585 |
+ |
} |
| 1586 |
+ |
else VCOPY(rayOut.rdir, rayIn -> rdir); |
| 1587 |
+ |
} |
| 1588 |
+ |
else if (xi > (albedo -= prDiff)) { |
| 1589 |
+ |
/* Diffuz reflekzion */ |
| 1590 |
+ |
if (!hitfront) |
| 1591 |
+ |
flipsurface(rayIn); |
| 1592 |
+ |
photonRay(rayIn, &rayOut, PMAP_DIFFREFL, nd.mcolor); |
| 1593 |
+ |
diffPhotonScatter(nd.pnorm, &rayOut); |
| 1594 |
+ |
} |
| 1595 |
+ |
else { |
| 1596 |
+ |
/* Diffuz tranzmission */ |
| 1597 |
+ |
if (hitfront) |
| 1598 |
+ |
flipsurface(rayIn); |
| 1599 |
+ |
photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.mcolor); |
| 1600 |
+ |
bnorm [0] = -nd.pnorm [0]; |
| 1601 |
+ |
bnorm [1] = -nd.pnorm [1]; |
| 1602 |
+ |
bnorm [2] = -nd.pnorm [2]; |
| 1603 |
+ |
diffPhotonScatter(bnorm, &rayOut); |
| 1604 |
+ |
} |
| 1605 |
+ |
|
| 1606 |
+ |
tracePhoton(&rayOut); |
| 1607 |
+ |
return 0; |
| 1608 |
+ |
} |
| 1609 |
+ |
|
| 1610 |
+ |
|
| 1611 |
+ |
|
| 1612 |
+ |
int brdf2PhotonScatter (OBJREC *mat, RAY *rayIn) |
| 1613 |
+ |
/* Generate new photon ray for procedural or data driven BRDF material and |
| 1614 |
+ |
recurse. Only diffuse reflection and transmission are sampled. */ |
| 1615 |
+ |
{ |
| 1616 |
+ |
BRDFDAT nd; |
| 1617 |
+ |
RAY rayOut; |
| 1618 |
+ |
double dtmp, prDiff, ptDiff, albedo, xi; |
| 1619 |
+ |
MFUNC *mf; |
| 1620 |
+ |
FVECT bnorm; |
| 1621 |
+ |
|
| 1622 |
+ |
/* Check argz */ |
| 1623 |
+ |
if (mat -> oargs.nsargs < (hasdata(mat -> otype) ? 4 : 2) || |
| 1624 |
+ |
mat -> oargs.nfargs < (mat -> otype == MAT_TFUNC || |
| 1625 |
+ |
mat -> otype == MAT_TDATA ? 6 : 4)) |
| 1626 |
+ |
objerror(mat, USER, "bad # arguments"); |
| 1627 |
+ |
|
| 1628 |
+ |
if (rayIn -> rod < 0.0) { |
| 1629 |
+ |
/* Hit backside; reorient if visible, else transfer photon */ |
| 1630 |
+ |
if (!backvis) { |
| 1631 |
+ |
photonRay(rayIn, &rayOut, PMAP_XFER, NULL); |
| 1632 |
+ |
tracePhoton(&rayOut); |
| 1633 |
+ |
return 0; |
| 1634 |
+ |
} |
| 1635 |
+ |
|
| 1636 |
+ |
raytexture(rayIn, mat -> omod); |
| 1637 |
+ |
flipsurface(rayIn); |
| 1638 |
+ |
} |
| 1639 |
+ |
else raytexture(rayIn, mat -> omod); |
| 1640 |
+ |
|
| 1641 |
+ |
nd.mp = mat; |
| 1642 |
+ |
nd.pr = rayIn; |
| 1643 |
+ |
|
| 1644 |
+ |
/* Material kolour */ |
| 1645 |
+ |
setcolor(nd.mcolor, mat -> oargs.farg [0], mat -> oargs.farg [1], |
| 1646 |
+ |
mat -> oargs.farg [2]); |
| 1647 |
+ |
/* Spekula komponent */ |
| 1648 |
+ |
nd.rspec = mat -> oargs.farg [3]; |
| 1649 |
+ |
|
| 1650 |
+ |
/* Tranzmittanz */ |
| 1651 |
+ |
if (mat -> otype == MAT_TFUNC || mat -> otype == MAT_TDATA) { |
| 1652 |
+ |
nd.trans = mat -> oargs.farg [4] * (1.0 - nd.rspec); |
| 1653 |
+ |
nd.tspec = nd.trans * mat -> oargs.farg [5]; |
| 1654 |
+ |
dtmp = nd.trans - nd.tspec; |
| 1655 |
+ |
setcolor(nd.tdiff, dtmp, dtmp, dtmp); |
| 1656 |
+ |
} |
| 1657 |
+ |
else { |
| 1658 |
+ |
nd.tspec = nd.trans = 0.0; |
| 1659 |
+ |
setcolor(nd.tdiff, 0.0, 0.0, 0.0); |
| 1660 |
+ |
} |
| 1661 |
+ |
|
| 1662 |
+ |
/* Reflektanz */ |
| 1663 |
+ |
dtmp = 1.0 - nd.trans - nd.rspec; |
| 1664 |
+ |
setcolor(nd.rdiff, dtmp, dtmp, dtmp); |
| 1665 |
+ |
/* Perturb normal */ |
| 1666 |
+ |
nd.pdot = raynormal(nd.pnorm, rayIn); |
| 1667 |
+ |
/* Modify material kolour */ |
| 1668 |
+ |
multcolor(nd.mcolor, rayIn -> pcol); |
| 1669 |
+ |
multcolor(nd.rdiff, nd.mcolor); |
| 1670 |
+ |
multcolor(nd.tdiff, nd.mcolor); |
| 1671 |
+ |
|
| 1672 |
+ |
/* Load auxiliary filez */ |
| 1673 |
+ |
if (hasdata(mat -> otype)) { |
| 1674 |
+ |
nd.dp = getdata(mat -> oargs.sarg [1]); |
| 1675 |
+ |
getfunc(mat, 2, 0, 0); |
| 1676 |
+ |
} |
| 1677 |
+ |
else { |
| 1678 |
+ |
nd.dp = NULL; |
| 1679 |
+ |
getfunc(mat, 1, 0, 0); |
| 1680 |
+ |
} |
| 1681 |
+ |
|
| 1682 |
+ |
/* Set up probz */ |
| 1683 |
+ |
prDiff = colorAvg(nd.rdiff); |
| 1684 |
+ |
ptDiff = colorAvg(nd.tdiff); |
| 1685 |
+ |
albedo = prDiff + ptDiff; |
| 1686 |
+ |
|
| 1687 |
+ |
/* Insert direct and indirect photon hitz if diffuz komponent */ |
| 1688 |
+ |
if (prDiff > FTINY || ptDiff > FTINY) |
| 1689 |
+ |
addPhotons(rayIn); |
| 1690 |
+ |
|
| 1691 |
+ |
/* Stochastically sample absorption or scattering evenz */ |
| 1692 |
+ |
if ((xi = pmapRandom(rouletteState)) > albedo) |
| 1693 |
+ |
/* Absorbed */ |
| 1694 |
+ |
return 0; |
| 1695 |
+ |
|
| 1696 |
+ |
if (xi > (albedo -= prDiff)) { |
| 1697 |
+ |
/* Diffuz reflekzion */ |
| 1698 |
+ |
photonRay(rayIn, &rayOut, PMAP_DIFFREFL, nd.rdiff); |
| 1699 |
+ |
diffPhotonScatter(nd.pnorm, &rayOut); |
| 1700 |
+ |
} |
| 1701 |
+ |
else { |
| 1702 |
+ |
/* Diffuz tranzmission */ |
| 1703 |
+ |
flipsurface(rayIn); |
| 1704 |
+ |
photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.tdiff); |
| 1705 |
+ |
bnorm [0] = -nd.pnorm [0]; |
| 1706 |
+ |
bnorm [1] = -nd.pnorm [1]; |
| 1707 |
+ |
bnorm [2] = -nd.pnorm [2]; |
| 1708 |
+ |
diffPhotonScatter(bnorm, &rayOut); |
| 1709 |
+ |
} |
| 1710 |
+ |
|
| 1711 |
+ |
tracePhoton(&rayOut); |
| 1712 |
+ |
return 0; |
| 1713 |
+ |
} |
| 1714 |
+ |
|
| 1715 |
+ |
|
| 1716 |
+ |
|
| 1717 |
|
/* |
| 1718 |
< |
================================================================== |
| 1718 |
> |
====================================================================== |
| 1719 |
|
The following code is |
| 1720 |
|
(c) Lucerne University of Applied Sciences and Arts, |
| 1721 |
< |
supported by the Swiss National Science Foundation (SNSF, #147053) |
| 1722 |
< |
================================================================== |
| 1723 |
< |
*/ |
| 1721 |
> |
supported by the Swiss National Science Foundation |
| 1722 |
> |
(SNSF #147053, "Daylight Redirecting Components") |
| 1723 |
> |
====================================================================== |
| 1724 |
> |
*/ |
| 1725 |
|
|
| 1726 |
|
static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) |
| 1727 |
|
/* Generate new photon ray for BSDF modifier and recurse. */ |
| 1728 |
|
{ |
| 1729 |
< |
int hitFront; |
| 1730 |
< |
SDError err; |
| 1731 |
< |
SDValue bsdfVal; |
| 1732 |
< |
FVECT upvec; |
| 1733 |
< |
MFUNC *mf; |
| 1734 |
< |
BSDFDAT nd; |
| 1735 |
< |
RAY rayOut; |
| 1736 |
< |
COLOR bsdfRGB; |
| 1737 |
< |
int transmitted; |
| 1738 |
< |
double prDiff, ptDiff, prDiffSD, ptDiffSD, prSpecSD, ptSpecSD, |
| 1739 |
< |
albedo, xi; |
| 1740 |
< |
const double patAlb = bright(rayIn -> pcol); |
| 1729 |
> |
int hasthick = (mat->otype == MAT_BSDF); |
| 1730 |
> |
int hitFront; |
| 1731 |
> |
SDError err; |
| 1732 |
> |
SDValue bsdfVal; |
| 1733 |
> |
FVECT upvec; |
| 1734 |
> |
MFUNC *mf; |
| 1735 |
> |
BSDFDAT nd; |
| 1736 |
> |
RAY rayOut; |
| 1737 |
> |
COLOR bsdfRGB; |
| 1738 |
> |
int transmitted; |
| 1739 |
> |
double prDiff, ptDiff, prDiffSD, ptDiffSD, prSpecSD, ptSpecSD, |
| 1740 |
> |
albedo, xi; |
| 1741 |
> |
const double patAlb = bright(rayIn -> pcol); |
| 1742 |
|
|
| 1743 |
|
/* Following code adapted from m_bsdf() */ |
| 1744 |
|
/* Check arguments */ |
| 1745 |
< |
if (mat -> oargs.nsargs < 6 || mat -> oargs.nfargs > 9 || |
| 1746 |
< |
mat -> oargs.nfargs % 3) |
| 1745 |
> |
if ( |
| 1746 |
> |
mat -> oargs.nsargs < hasthick+5 || |
| 1747 |
> |
mat -> oargs.nfargs > 9 || mat -> oargs.nfargs % 3 |
| 1748 |
> |
) |
| 1749 |
|
objerror(mat, USER, "bad # arguments"); |
| 1750 |
|
|
| 1751 |
< |
hitFront = (rayIn -> rod > 0); |
| 1751 |
> |
hitFront = (rayIn -> rod > 0); |
| 1752 |
|
|
| 1753 |
< |
/* Load cal file */ |
| 1754 |
< |
mf = getfunc(mat, 5, 0x1d, 1); |
| 1451 |
< |
|
| 1452 |
< |
/* Get thickness */ |
| 1453 |
< |
nd.thick = evalue(mf -> ep [0]); |
| 1454 |
< |
if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) |
| 1455 |
< |
nd.thick = .0; |
| 1753 |
> |
/* Load cal file */ |
| 1754 |
> |
mf = hasthick ? getfunc(mat, 5, 0x1d, 1) : getfunc(mat, 4, 0xe, 1); |
| 1755 |
|
|
| 1756 |
+ |
/* Get thickness */ |
| 1757 |
+ |
nd.thick = 0; |
| 1758 |
+ |
if (hasthick) { |
| 1759 |
+ |
nd.thick = evalue(mf -> ep [0]); |
| 1760 |
+ |
if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) |
| 1761 |
+ |
nd.thick = .0; |
| 1762 |
+ |
} |
| 1763 |
+ |
|
| 1764 |
|
/* Get BSDF data */ |
| 1765 |
< |
nd.sd = loadBSDF(mat -> oargs.sarg [1]); |
| 1765 |
> |
nd.sd = loadBSDF(mat -> oargs.sarg [hasthick]); |
| 1766 |
|
|
| 1767 |
|
/* Extra diffuse reflectance from material def */ |
| 1768 |
|
if (hitFront) { |
| 1769 |
|
if (mat -> oargs.nfargs < 3) |
| 1770 |
|
setcolor(nd.rdiff, .0, .0, .0); |
| 1771 |
< |
else setcolor(nd.rdiff, mat -> oargs.farg [0], mat -> oargs.farg [1], |
| 1772 |
< |
mat -> oargs.farg [2]); |
| 1771 |
> |
else setcolor( |
| 1772 |
> |
nd.rdiff, |
| 1773 |
> |
mat -> oargs.farg [0], mat -> oargs.farg [1], mat -> oargs.farg [2] |
| 1774 |
> |
); |
| 1775 |
|
} |
| 1776 |
|
else if (mat -> oargs.nfargs < 6) { |
| 1777 |
< |
/* Check for absorbing backside */ |
| 1778 |
< |
if (!backvis && !nd.sd -> rb && !nd.sd -> tf) { |
| 1779 |
< |
SDfreeCache(nd.sd); |
| 1780 |
< |
return 0; |
| 1777 |
> |
/* Check for absorbing backside */ |
| 1778 |
> |
if (!backvis && !nd.sd -> rb && !nd.sd -> tf) { |
| 1779 |
> |
SDfreeCache(nd.sd); |
| 1780 |
> |
return 0; |
| 1781 |
|
} |
| 1782 |
|
|
| 1783 |
|
setcolor(nd.rdiff, .0, .0, .0); |
| 1784 |
|
} |
| 1785 |
< |
else setcolor(nd.rdiff, mat -> oargs.farg [3], mat -> oargs.farg [4], |
| 1786 |
< |
mat -> oargs.farg [5]); |
| 1785 |
> |
else setcolor( |
| 1786 |
> |
nd.rdiff, |
| 1787 |
> |
mat -> oargs.farg [3], mat -> oargs.farg [4], mat -> oargs.farg [5] |
| 1788 |
> |
); |
| 1789 |
|
|
| 1790 |
< |
/* Extra diffuse transmittance from material def */ |
| 1791 |
< |
if (mat -> oargs.nfargs < 9) |
| 1792 |
< |
setcolor(nd.tdiff, .0, .0, .0); |
| 1793 |
< |
else setcolor(nd.tdiff, mat -> oargs.farg [6], mat -> oargs.farg [7], |
| 1794 |
< |
mat -> oargs.farg [8]); |
| 1790 |
> |
/* Extra diffuse transmittance from material def */ |
| 1791 |
> |
if (mat -> oargs.nfargs < 9) |
| 1792 |
> |
setcolor(nd.tdiff, .0, .0, .0); |
| 1793 |
> |
else setcolor( |
| 1794 |
> |
nd.tdiff, |
| 1795 |
> |
mat -> oargs.farg [6], mat -> oargs.farg [7], mat -> oargs.farg [8] |
| 1796 |
> |
); |
| 1797 |
|
|
| 1798 |
|
nd.mp = mat; |
| 1799 |
|
nd.pr = rayIn; |
| 1800 |
< |
|
| 1800 |
> |
|
| 1801 |
|
/* Get modifiers */ |
| 1802 |
|
raytexture(rayIn, mat -> omod); |
| 1803 |
|
|
| 1804 |
|
/* Modify diffuse values */ |
| 1805 |
|
multcolor(nd.rdiff, rayIn -> pcol); |
| 1806 |
|
multcolor(nd.tdiff, rayIn -> pcol); |
| 1807 |
< |
|
| 1807 |
> |
|
| 1808 |
|
/* Get up vector & xform to world coords */ |
| 1809 |
< |
upvec [0] = evalue(mf -> ep [1]); |
| 1810 |
< |
upvec [1] = evalue(mf -> ep [2]); |
| 1811 |
< |
upvec [2] = evalue(mf -> ep [3]); |
| 1809 |
> |
upvec [0] = evalue(mf -> ep [hasthick+0]); |
| 1810 |
> |
upvec [1] = evalue(mf -> ep [hasthick+1]); |
| 1811 |
> |
upvec [2] = evalue(mf -> ep [hasthick+2]); |
| 1812 |
|
|
| 1813 |
|
if (mf -> fxp != &unitxf) { |
| 1814 |
|
multv3(upvec, upvec, mf -> fxp -> xfm); |
| 1842 |
|
} |
| 1843 |
|
|
| 1844 |
|
/* Determine BSDF resolution */ |
| 1845 |
< |
err = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, SDqueryMin + SDqueryMax, nd.sd); |
| 1845 |
> |
err = SDsizeBSDF( |
| 1846 |
> |
nd.sr_vpsa, nd.vray, NULL, SDqueryMin + SDqueryMax, nd.sd |
| 1847 |
> |
); |
| 1848 |
|
|
| 1849 |
|
if (err) |
| 1850 |
|
objerror(mat, USER, transSDError(err)); |
| 1853 |
|
nd.sr_vpsa [1] = sqrt(nd.sr_vpsa [1]); |
| 1854 |
|
|
| 1855 |
|
/* Orient perturbed normal towards incident side */ |
| 1856 |
< |
if (!hitFront) { |
| 1856 |
> |
if (!hitFront) { |
| 1857 |
|
nd.pnorm [0] = -nd.pnorm [0]; |
| 1858 |
|
nd.pnorm [1] = -nd.pnorm [1]; |
| 1859 |
|
nd.pnorm [2] = -nd.pnorm [2]; |
| 1897 |
|
|
| 1898 |
|
else if ((xi -= ptDiff) <= 0) { |
| 1899 |
|
/* Diffuse transmission (extra component in material def) */ |
| 1585 |
– |
flipsurface(rayIn); |
| 1586 |
– |
nd.thick = -nd.thick; |
| 1900 |
|
photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.tdiff); |
| 1901 |
|
diffPhotonScatter(nd.pnorm, &rayOut); |
| 1902 |
|
transmitted = 1; |
| 1905 |
|
else { /* Sample SDF */ |
| 1906 |
|
if ((xi -= prDiffSD) <= 0) { |
| 1907 |
|
/* Diffuse SDF reflection (constant component) */ |
| 1908 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
| 1909 |
< |
SDsampDf | SDsampR, nd.sd))) |
| 1908 |
> |
if ((err = SDsampBSDF( |
| 1909 |
> |
&bsdfVal, nd.vray, pmapRandom(scatterState), |
| 1910 |
> |
SDsampDf | SDsampR, nd.sd |
| 1911 |
> |
))) |
| 1912 |
|
objerror(mat, USER, transSDError(err)); |
| 1913 |
|
|
| 1914 |
|
/* Apply pattern to spectral component */ |
| 1919 |
|
|
| 1920 |
|
else if ((xi -= ptDiffSD) <= 0) { |
| 1921 |
|
/* Diffuse SDF transmission (constant component) */ |
| 1922 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
| 1923 |
< |
SDsampDf | SDsampT, nd.sd))) |
| 1922 |
> |
if ((err = SDsampBSDF( |
| 1923 |
> |
&bsdfVal, nd.vray, pmapRandom(scatterState), |
| 1924 |
> |
SDsampDf | SDsampT, nd.sd |
| 1925 |
> |
))) |
| 1926 |
|
objerror(mat, USER, transSDError(err)); |
| 1927 |
|
|
| 1928 |
|
/* Apply pattern to spectral component */ |
| 1929 |
|
ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB); |
| 1930 |
|
multcolor(bsdfRGB, rayIn -> pcol); |
| 1931 |
|
addcolor(bsdfRGB, nd.tdiff); |
| 1615 |
– |
flipsurface(rayIn); /* Necessary? */ |
| 1616 |
– |
nd.thick = -nd.thick; |
| 1932 |
|
photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, bsdfRGB); |
| 1933 |
|
transmitted = 1; |
| 1934 |
|
} |
| 1935 |
|
|
| 1936 |
|
else if ((xi -= prSpecSD) <= 0) { |
| 1937 |
|
/* Non-diffuse ("specular") SDF reflection */ |
| 1938 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
| 1939 |
< |
SDsampSp | SDsampR, nd.sd))) |
| 1938 |
> |
if ((err = SDsampBSDF( |
| 1939 |
> |
&bsdfVal, nd.vray, pmapRandom(scatterState), |
| 1940 |
> |
SDsampSp | SDsampR, nd.sd |
| 1941 |
> |
))) |
| 1942 |
|
objerror(mat, USER, transSDError(err)); |
| 1943 |
|
|
| 1944 |
|
ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB); |
| 1947 |
|
|
| 1948 |
|
else { |
| 1949 |
|
/* Non-diffuse ("specular") SDF transmission */ |
| 1950 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
| 1951 |
< |
SDsampSp | SDsampT, nd.sd))) |
| 1950 |
> |
if ((err = SDsampBSDF( |
| 1951 |
> |
&bsdfVal, nd.vray, pmapRandom(scatterState), |
| 1952 |
> |
SDsampSp | SDsampT, nd.sd |
| 1953 |
> |
))) |
| 1954 |
|
objerror(mat, USER, transSDError(err)); |
| 1955 |
|
|
| 1956 |
|
/* Apply pattern to spectral component */ |
| 1957 |
|
ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB); |
| 1958 |
|
multcolor(bsdfRGB, rayIn -> pcol); |
| 1640 |
– |
flipsurface(rayIn); /* Necessary? */ |
| 1641 |
– |
nd.thick = -nd.thick; |
| 1959 |
|
photonRay(rayIn, &rayOut, PMAP_SPECTRANS, bsdfRGB); |
| 1960 |
|
transmitted = 1; |
| 1961 |
|
} |
| 1970 |
|
/* Clean up */ |
| 1971 |
|
SDfreeCache(nd.sd); |
| 1972 |
|
|
| 1973 |
< |
/* Need to offset ray origin to get past detail geometry? */ |
| 1973 |
> |
/* Offset outgoing photon origin by thickness to bypass proxy geometry */ |
| 1974 |
|
if (transmitted && nd.thick != 0) |
| 1975 |
|
VSUM(rayOut.rorg, rayOut.rorg, rayIn -> ron, -nd.thick); |
| 1976 |
|
|
| 1981 |
|
|
| 1982 |
|
|
| 1983 |
|
static int lightPhotonScatter (OBJREC* mat, RAY* ray) |
| 1984 |
< |
/* Light sources doan' reflect */ |
| 1984 |
> |
/* Light sources doan' reflect, mang */ |
| 1985 |
|
{ |
| 1986 |
|
return 0; |
| 1987 |
|
} |
| 1992 |
|
/* Init photonScatter[] dispatch table */ |
| 1993 |
|
{ |
| 1994 |
|
int i; |
| 1995 |
< |
|
| 1995 |
> |
|
| 1996 |
> |
/* Catch-all for inconsistencies */ |
| 1997 |
|
for (i = 0; i < NUMOTYPE; i++) |
| 1998 |
|
photonScatter [i] = o_default; |
| 1999 |
< |
|
| 1999 |
> |
|
| 2000 |
|
photonScatter [MAT_LIGHT] = photonScatter [MAT_ILLUM] = |
| 2001 |
|
photonScatter [MAT_GLOW] = photonScatter [MAT_SPOT] = |
| 2002 |
|
lightPhotonScatter; |
| 2003 |
< |
|
| 2003 |
> |
|
| 2004 |
|
photonScatter [MAT_PLASTIC] = photonScatter [MAT_METAL] = |
| 2005 |
|
photonScatter [MAT_TRANS] = normalPhotonScatter; |
| 2006 |
|
|
| 2009 |
|
|
| 2010 |
|
photonScatter [MAT_DIELECTRIC] = photonScatter [MAT_INTERFACE] = |
| 2011 |
|
dielectricPhotonScatter; |
| 2012 |
< |
|
| 2012 |
> |
|
| 2013 |
|
photonScatter [MAT_MIST] = mistPhotonScatter; |
| 2014 |
|
photonScatter [MAT_GLASS] = glassPhotonScatter; |
| 2015 |
|
photonScatter [MAT_CLIP] = clipPhotonScatter; |
| 2017 |
|
photonScatter [MIX_FUNC] = mx_funcPhotonScatter; |
| 2018 |
|
photonScatter [MIX_DATA] = mx_dataPhotonScatter; |
| 2019 |
|
photonScatter [MIX_PICT]= mx_pdataPhotonScatter; |
| 2020 |
< |
|
| 2020 |
> |
|
| 2021 |
|
photonScatter [PAT_BDATA] = photonScatter [PAT_CDATA] = |
| 2022 |
|
photonScatter [PAT_BFUNC] = photonScatter [PAT_CFUNC] = |
| 2023 |
|
photonScatter [PAT_CPICT] = photonScatter [TEX_FUNC] = |
| 2024 |
|
photonScatter [TEX_DATA] = pattexPhotonScatter; |
| 2025 |
< |
|
| 2025 |
> |
|
| 2026 |
|
photonScatter [MOD_ALIAS] = aliasPhotonScatter; |
| 2027 |
< |
photonScatter [MAT_BSDF] = bsdfPhotonScatter; |
| 2027 |
> |
photonScatter [MAT_BRTDF] = brdfPhotonScatter; |
| 2028 |
> |
|
| 2029 |
> |
photonScatter [MAT_PFUNC] = photonScatter [MAT_MFUNC] = |
| 2030 |
> |
photonScatter [MAT_PDATA] = photonScatter [MAT_MDATA] = |
| 2031 |
> |
photonScatter [MAT_TFUNC] = photonScatter [MAT_TDATA] = |
| 2032 |
> |
brdf2PhotonScatter; |
| 2033 |
> |
|
| 2034 |
> |
photonScatter [MAT_BSDF] = photonScatter [MAT_ABSDF] = |
| 2035 |
> |
bsdfPhotonScatter; |
| 2036 |
|
} |