本文整理汇总了C++中BSDF::WorldToLocal方法的典型用法代码示例。如果您正苦于以下问题:C++ BSDF::WorldToLocal方法的具体用法?C++ BSDF::WorldToLocal怎么用?C++ BSDF::WorldToLocal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSDF
的用法示例。
在下文中一共展示了BSDF::WorldToLocal方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Li
Spectrum GlossyPRTIntegrator::Li(const Scene *scene, const Renderer *,
const RayDifferential &ray, const Intersection &isect,
const Sample *sample, RNG &rng, MemoryArena &arena) const {
Spectrum L = 0.f;
Vector wo = -ray.d;
// Compute emitted light if ray hit an area light source
L += isect.Le(wo);
// Evaluate BSDF at hit point
BSDF *bsdf = isect.GetBSDF(ray, arena);
const Point &p = bsdf->dgShading.p;
// Compute reflected radiance with glossy PRT at point
// Compute SH radiance transfer matrix at point and SH coefficients
Spectrum *c_t = arena.Alloc<Spectrum>(SHTerms(lmax));
Spectrum *T = arena.Alloc<Spectrum>(SHTerms(lmax)*SHTerms(lmax));
SHComputeTransferMatrix(p, isect.rayEpsilon, scene, rng, nSamples,
lmax, T);
SHMatrixVectorMultiply(T, c_in, c_t, lmax);
// Rotate incident SH lighting to local coordinate frame
Vector r1 = bsdf->LocalToWorld(Vector(1,0,0));
Vector r2 = bsdf->LocalToWorld(Vector(0,1,0));
Normal nl = Normal(bsdf->LocalToWorld(Vector(0,0,1)));
Matrix4x4 rot(r1.x, r2.x, nl.x, 0,
r1.y, r2.y, nl.y, 0,
r1.z, r2.z, nl.z, 0,
0, 0, 0, 1);
Spectrum *c_l = arena.Alloc<Spectrum>(SHTerms(lmax));
SHRotate(c_t, c_l, rot, lmax, arena);
#if 0
// Sample BSDF and integrate against direct SH coefficients
float *Ylm = ALLOCA(float, SHTerms(lmax));
int ns = 1024;
for (int i = 0; i < ns; ++i) {
Vector wi;
float pdf;
Spectrum f = bsdf->Sample_f(wo, &wi, BSDFSample(rng), &pdf);
if (pdf > 0.f && !f.IsBlack() && !scene->IntersectP(Ray(p, wi))) {
f *= fabsf(Dot(wi, n)) / (pdf * ns);
SHEvaluate(bsdf->WorldToLocal(wi), lmax, Ylm);
Spectrum Li = 0.f;
for (int j = 0; j < SHTerms(lmax); ++j)
Li += Ylm[j] * c_l[j] * f;
L += Li.Clamp();
}
}
#else
// Compute final coefficients _c\_o_ using BSDF matrix
Spectrum *c_o = arena.Alloc<Spectrum>(SHTerms(lmax));
SHMatrixVectorMultiply(B, c_l, c_o, lmax);
// Evaluate outgoing radiance function for $\wo$ and add to _L_
Vector woLocal = bsdf->WorldToLocal(wo);
float *Ylm = ALLOCA(float, SHTerms(lmax));
SHEvaluate(woLocal, lmax, Ylm);
Spectrum Li = 0.f;
for (int i = 0; i < SHTerms(lmax); ++i)
Li += Ylm[i] * c_o[i];
L += Li.Clamp();
#endif
return L;
}
示例2: main
//.........这里部分代码省略.........
disk->Intersect(r, &tHit, &rayEps, dg);
bsdf = BSDF_ALLOC(arena, BSDF)(*dg, dg->nn);
(BSDFFuncArray[model])(bsdf);
}
// facing directly at normal
Vector woL = Normalize(Vector(0, 0, 1));
Vector wo = bsdf->LocalToWorld(woL);
const Normal &n = bsdf->dgShading.nn;
// for each method of generating samples over the hemisphere
for (int gen = 0; gen < numGenerators; gen++) {
double redSum = 0.0;
const int numHistoBins = 10;
double histogram[numHistoBins][numHistoBins];
for (int i = 0; i < numHistoBins; i++) {
for (int j = 0; j < numHistoBins; j++) {
histogram[i][j] = 0;
}
}
int badSamples = 0;
int outsideSamples = 0;
int warningTarget = 1;
for (int sample = 0; sample < estimates; sample++) {
Vector wi;
float pdf;
Spectrum f;
// sample hemisphere around bsdf, wo is fixed
(SampleFuncArray[gen])(bsdf, wo, & wi, & pdf, & f);
double redF = spectrumRedValue(f);
// add hemisphere sample to histogram
Vector wiL = bsdf->WorldToLocal(wi);
float x = Clamp(wiL.x, -1.f, 1.f);
float y = Clamp(wiL.y, -1.f, 1.f);
float wiPhi = (atan2(y, x) + M_PI) / (2.0 * M_PI);
float wiCosTheta = wiL.z;
bool validSample = (wiCosTheta > 1e-7);
if (wiPhi < -0.0001 || wiPhi > 1.0001 || wiCosTheta > 1.0001) {
// wiCosTheta can be less than 0
fprintf(stderr, "bad wi! %.3f %.3f %.3f, (%.3f %.3f)\n",
wiL[0], wiL[1], wiL[2], wiPhi, wiCosTheta);
} else if (validSample) {
int histoPhi = (int) (wiPhi * numHistoBins);
int histoCosTheta = (int) (wiCosTheta * numHistoBins);
histogram[histoCosTheta][histoPhi] += 1.0 / pdf;
}
if (!validSample) {
outsideSamples++;
} else if (pdf == 0.f || isnan(pdf) || redF < 0 || isnan(redF)) {
if (badSamples == warningTarget) {
fprintf(stderr, "warning %d, bad sample %d! "
"pdf: %.3f, redF: %.3f\n",
warningTarget, sample, pdf, redF);
warningTarget *= 10;
}
badSamples++;
} else {
// outgoing radiance estimate =
// bsdf * incomingRadiance * cos(wi) / pdf
redSum += redF * environmentRadiance * AbsDot(wi, n) / pdf;
}
}
int goodSamples = estimates - badSamples;
// print results
fprintf(stderr, "*** BRDF: '%s', Samples: '%s'\n\n"
"wi histogram showing the relative weight in each bin\n"
" all entries should be close to 2pi = %.5f:\n"
" (%d bad samples, %d outside samples)\n\n"
" cos(theta) bins\n",
BSDFFuncDescripArray[model], SampleFuncDescripArray[gen],
M_PI * 2.0, badSamples, outsideSamples);
double totalSum = 0.0;
for (int i = 0; i < numHistoBins; i++) {
fprintf(stderr, " phi bin %02d:", i);
for (int j = 0; j < numHistoBins; j++) {
fprintf(stderr, " %5.2f", histogram[i][j] *
numHistoBins * numHistoBins / goodSamples);
totalSum += histogram[i][j];
}
fprintf(stderr, "\n");
}
fprintf(stderr, "\n final average : %.5f (error %.5f)\n\n"
" radiance = %.5f\n\n",
totalSum / goodSamples, totalSum / goodSamples - M_PI * 2.0,
redSum / goodSamples);
}
}
pbrtCleanup();
return 0;
}
示例3: main
//.........这里部分代码省略.........
// facing directly at normal
Vector3f woL = Normalize(Vector3f(0, 0, 1));
Vector3f wo = bsdf->LocalToWorld(woL);
// was bsdf->dgShading.nn
const Normal3f n = Normal3f(bsdf->LocalToWorld(Vector3f(0, 0, 1)));
// for each method of generating samples over the hemisphere
for (int gen = 0; gen < numGenerators; gen++) {
double redSum = 0.0;
const int numHistoBins = 10;
double histogram[numHistoBins][numHistoBins];
for (int i = 0; i < numHistoBins; i++) {
for (int j = 0; j < numHistoBins; j++) {
histogram[i][j] = 0;
}
}
int badSamples = 0;
int outsideSamples = 0;
int warningTarget = 1;
for (int sample = 0; sample < estimates; sample++) {
Vector3f wi;
Float pdf;
Spectrum f;
// sample hemisphere around bsdf, wo is fixed
(SampleFuncArray[gen])(bsdf, wo, &wi, &pdf, &f);
double redF = spectrumRedValue(f);
// add hemisphere sample to histogram
Vector3f wiL = bsdf->WorldToLocal(wi);
float x = Clamp(wiL.x, -1.f, 1.f);
float y = Clamp(wiL.y, -1.f, 1.f);
float wiPhi = (atan2(y, x) + Pi) / (2.0 * Pi);
float wiCosTheta = wiL.z;
bool validSample = (wiCosTheta > 1e-7);
if (wiPhi < -0.0001 || wiPhi > 1.0001 || wiCosTheta > 1.0001) {
// wiCosTheta can be less than 0
fprintf(stderr, "bad wi! %.3f %.3f %.3f, (%.3f %.3f)\n",
wiL[0], wiL[1], wiL[2], wiPhi, wiCosTheta);
} else if (validSample) {
int histoPhi = (int)(wiPhi * numHistoBins);
if (histoPhi == numHistoBins)
--histoPhi;
int histoCosTheta = (int)(wiCosTheta * numHistoBins);
if (histoCosTheta == numHistoBins)
--histoCosTheta;
assert(histoPhi >= 0 && histoPhi < numHistoBins);
assert(histoCosTheta >= 0 && histoCosTheta < numHistoBins);
histogram[histoCosTheta][histoPhi] += 1.0 / pdf;
}
if (!validSample) {
outsideSamples++;
} else if (pdf == 0.f || std::isnan(pdf) || redF < 0 ||
std::isnan(redF)) {
if (badSamples == warningTarget) {
fprintf(stderr,
"warning %d, bad sample %d! "
"pdf: %.3f, redF: %.3f\n",
warningTarget, sample, pdf, redF);
warningTarget *= 10;
}