本文整理汇总了C++中BSDF::LocalToWorld方法的典型用法代码示例。如果您正苦于以下问题:C++ BSDF::LocalToWorld方法的具体用法?C++ BSDF::LocalToWorld怎么用?C++ BSDF::LocalToWorld使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSDF
的用法示例。
在下文中一共展示了BSDF::LocalToWorld方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
BSDF* bsdf;
// create BSDF which requires creating a Shape, casting a Ray
// that hits the shape to get a DifferentialGeometry object,
// and passing the DifferentialGeometry object into the BSDF
{
Transform t = RotateX(-90);
bool reverseOrientation = false;
ParamSet p;
Reference<Shape> disk = new Disk(new Transform(t), new Transform(Inverse(t)),
reverseOrientation, 0., 1., 0, 360.);
if (!disk) {
fprintf(stderr, "Could not load disk plugin\n"
" make sure the PBRT_SEARCHPATH environment variable is set\n");
exit(1);
}
Point origin(0.1, 1, 0); // offset slightly so we don't hit center of disk
Vector direction(0, -1, 0);
float tHit, rayEps;
Ray r(origin, direction, 1e-3, INFINITY);
DifferentialGeometry* dg = BSDF_ALLOC(arena, DifferentialGeometry)();
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);
示例2: TestBSDF
void TestBSDF(void (*createBSDF)(BSDF*, MemoryArena&),
const char* description) {
MemoryArena arena;
Options opt;
pbrtInit(opt);
const int thetaRes = CHI2_THETA_RES;
const int phiRes = CHI2_PHI_RES;
const int sampleCount = CHI2_SAMPLECOUNT;
Float* frequencies = new Float[thetaRes * phiRes];
Float* expFrequencies = new Float[thetaRes * phiRes];
RNG rng;
int index = 0;
std::cout.precision(3);
// Create BSDF, which requires creating a Shape, casting a Ray that
// hits the shape to get a SurfaceInteraction object.
BSDF* bsdf = nullptr;
Transform t = RotateX(-90);
Transform tInv = Inverse(t);
{
bool reverseOrientation = false;
ParamSet p;
std::shared_ptr<Shape> disk(
new Disk(&t, &tInv, reverseOrientation, 0., 1., 0, 360.));
Point3f origin(0.1, 1,
0); // offset slightly so we don't hit center of disk
Vector3f direction(0, -1, 0);
Float tHit;
Ray r(origin, direction);
SurfaceInteraction isect;
disk->Intersect(r, &tHit, &isect);
bsdf = ARENA_ALLOC(arena, BSDF)(isect);
createBSDF(bsdf, arena);
}
for (int k = 0; k < CHI2_RUNS; ++k) {
/* Randomly pick an outgoing direction on the hemisphere */
Point2f sample {rng.UniformFloat(), rng.UniformFloat()};
Vector3f woL = CosineSampleHemisphere(sample);
Vector3f wo = bsdf->LocalToWorld(woL);
FrequencyTable(bsdf, wo, rng, sampleCount, thetaRes, phiRes,
frequencies);
IntegrateFrequencyTable(bsdf, wo, sampleCount, thetaRes, phiRes,
expFrequencies);
std::string filename = StringPrintf("/tmp/chi2test_%s_%03i.m",
description, ++index);
DumpTables(frequencies, expFrequencies, thetaRes, phiRes,
filename.c_str());
auto result =
Chi2Test(frequencies, expFrequencies, thetaRes, phiRes, sampleCount,
CHI2_MINFREQ, CHI2_SLEVEL, CHI2_RUNS);
EXPECT_TRUE(result.first) << result.second << ", iteration " << k;
}
delete[] frequencies;
delete[] expFrequencies;
pbrtCleanup();
}
示例3: 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;
}
示例4: main
//.........这里部分代码省略.........
if (numGenerators != numGeneratorsDescrip) {
fprintf(stderr,
"SampleFuncArray and SampleFuncDescripArray out of sync!\n");
exit(1);
}
// for each bsdf model
for (int model = 0; model < numModels; model++) {
BSDF* bsdf;
// create BSDF which requires creating a Shape, casting a Ray
// that hits the shape to get a SurfaceInteraction object.
{
Transform t = RotateX(-90);
bool reverseOrientation = false;
ParamSet p;
std::shared_ptr<Shape> disk(
new Disk(new Transform(t), new Transform(Inverse(t)),
reverseOrientation, 0., 1., 0, 360.));
Point3f origin(
0.1, 1, 0); // offset slightly so we don't hit center of disk
Vector3f direction(0, -1, 0);
Float tHit;
Ray r(origin, direction);
SurfaceInteraction isect;
disk->Intersect(r, &tHit, &isect);
bsdf = ARENA_ALLOC(arena, BSDF)(isect);
(BSDFFuncArray[model])(bsdf);
}
// 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);