提交 2e759a5a 编写于 作者: M Matt Pharr

Update from book source. No functional changes.

Just variable renaming and formatting...
上级 4fa5af5e
......@@ -156,11 +156,10 @@ class CameraBase {
Vector3f *dpdx, Vector3f *dpdy) const {
// Compute tangent plane equation for ray differential intersections
Point3f pCamera = CameraFromRender(p, time);
Normal3f nCamera = CameraFromRender(n, time);
Transform DownZFromCamera =
RotateFromTo(Normalize(Vector3f(pCamera)), Vector3f(0, 0, 1));
Point3f pDownZ = DownZFromCamera(pCamera);
Normal3f nDownZ = DownZFromCamera(nCamera);
Normal3f nDownZ = DownZFromCamera(CameraFromRender(n, time));
Float d = Dot(nDownZ, Vector3f(pDownZ));
// Find intersection points for approximated camera differential rays
......
......@@ -42,7 +42,7 @@ void SurfaceInteraction::ComputeDifferentials(const RayDifferential &ray, Camera
int samplesPerPixel) {
if (ray.hasDifferentials && Dot(n, ray.rxDirection) != 0 &&
Dot(n, ray.ryDirection) != 0) {
// Estimate screen-space change in $\pt{}$
// Estimate screen-space change in $\pt{}$ using ray differentials
// Compute auxiliary intersection points with plane, _px_ and _py_
Float d = -Dot(n, Vector3f(p()));
Float tx = (-Dot(n, Vector3f(ray.rxOrigin)) - d) / Dot(n, ray.rxDirection);
......@@ -55,24 +55,28 @@ void SurfaceInteraction::ComputeDifferentials(const RayDifferential &ray, Camera
dpdx = px - p();
dpdy = py - p();
} else
} else {
// Approximate screen-space change in $\pt{}$ based on camera projection
camera.Approximate_dp_dxy(p(), n, time, samplesPerPixel, &dpdx, &dpdy);
}
// Estimate screen-space change in $(u,v)$
Float a00 = Dot(dpdu, dpdu), a01 = Dot(dpdu, dpdv), a11 = Dot(dpdv, dpdv);
Float invDet = 1 / (DifferenceOfProducts(a00, a11, a01, a01));
Float b0x = Dot(dpdu, dpdx), b1x = Dot(dpdv, dpdx);
Float b0y = Dot(dpdu, dpdy), b1y = Dot(dpdv, dpdy);
/* Set the UV partials to zero if dpdu and/or dpdv == 0 */
// Compute $\transpose{\XFORM{A}} \XFORM{A}$ and its determinant
Float ata00 = Dot(dpdu, dpdu), ata01 = Dot(dpdu, dpdv);
Float ata11 = Dot(dpdv, dpdv);
Float invDet = 1 / (DifferenceOfProducts(ata00, ata11, ata01, ata01));
invDet = IsFinite(invDet) ? invDet : 0.f;
dudx = DifferenceOfProducts(a11, b0x, a01, b1x) * invDet;
dvdx = DifferenceOfProducts(a00, b1x, a01, b0x) * invDet;
// Compute $\transpose{\XFORM{A}} \VEC{b}$ for $x$ and $y$
Float atb0x = Dot(dpdu, dpdx), atb1x = Dot(dpdv, dpdx);
Float atb0y = Dot(dpdu, dpdy), atb1y = Dot(dpdv, dpdy);
dudy = DifferenceOfProducts(a11, b0y, a01, b1y) * invDet;
dvdy = DifferenceOfProducts(a00, b1y, a01, b0y) * invDet;
// Compute $u$ and $v$ partial derivatives with respect to $x$ and $y$
dudx = DifferenceOfProducts(ata11, atb0x, ata01, atb1x) * invDet;
dvdx = DifferenceOfProducts(ata00, atb1x, ata01, atb0x) * invDet;
dudy = DifferenceOfProducts(ata11, atb0y, ata01, atb1y) * invDet;
dvdy = DifferenceOfProducts(ata00, atb1y, ata01, atb0y) * invDet;
// Clamp partial derivatives of $u$ and $v$ to reasonable values
dudx = IsFinite(dudx) ? Clamp(dudx, -1e8f, 1e8f) : 0.f;
dvdx = IsFinite(dvdx) ? Clamp(dvdx, -1e8f, 1e8f) : 0.f;
dudy = IsFinite(dudy) ? Clamp(dudy, -1e8f, 1e8f) : 0.f;
......@@ -106,12 +110,12 @@ RayDifferential SurfaceInteraction::SpawnRay(const RayDifferential &rayi,
rd.ryOrigin = p() + dpdy;
// Compute differential reflected directions
Float dwoDotNdx = Dot(dwodx, ns) + Dot(wo, dndx);
Float dwoDotNdy = Dot(dwody, ns) + Dot(wo, dndy);
Float dwoDotn_dx = Dot(dwodx, ns) + Dot(wo, dndx);
Float dwoDotn_dy = Dot(dwody, ns) + Dot(wo, dndy);
rd.rxDirection =
wi - dwodx + 2 * Vector3f(Dot(wo, ns) * dndx + dwoDotNdx * ns);
wi - dwodx + 2 * Vector3f(Dot(wo, ns) * dndx + dwoDotn_dx * ns);
rd.ryDirection =
wi - dwody + 2 * Vector3f(Dot(wo, ns) * dndy + dwoDotNdy * ns);
wi - dwody + 2 * Vector3f(Dot(wo, ns) * dndy + dwoDotn_dy * ns);
} else if (flags == BxDFFlags::SpecularTransmission) {
// Initialize origins of specular differential rays
......
......@@ -686,7 +686,7 @@ void BasicSceneBuilder::AreaLightSource(const std::string &name,
void BasicScene::SetOptions(SceneEntity filter, SceneEntity film,
CameraSceneEntity camera, SceneEntity sampler,
SceneEntity integ, SceneEntity accel) {
// Store information for specificed integrator and accelerator
// Store information for specified integrator and accelerator
filmColorSpace = film.parameters.ColorSpace();
integrator = integ;
accelerator = accel;
......@@ -767,7 +767,7 @@ Medium BasicScene::GetMedium(const std::string &name, const FileLoc *loc) {
Medium m = iter->second;
mediaMutex.unlock();
return m;
} else {
} else {
auto fiter = mediumFutures.find(name);
if (fiter == mediumFutures.end())
ErrorExit(loc, "%s: medium is not defined.", name);
......@@ -795,11 +795,10 @@ std::map<std::string, Medium> BasicScene::CreateMedia() {
mediaMap[m.first] = *med;
}
}
LOG_VERBOSE("Consume media futures finished");
mediumFutures.clear();
}
mediumFutures.clear();
mediaMutex.unlock();
LOG_VERBOSE("Consume media futures finished");
return mediaMap;
}
......
......@@ -362,6 +362,7 @@ class Future {
Wait();
return fut.get();
}
pstd::optional<T> TryGet(std::mutex *mutex) {
if (IsReady())
return Get();
......
......@@ -75,6 +75,7 @@ void *monotonic_buffer_resource::do_allocate(size_t bytes, size_t align) {
// so this is tied to pbrt's current usage of them...
CHECK(constructTID == std::this_thread::get_id());
#endif
if (bytes > block_size)
// We've got a big allocation; let the current block be so that
// smaller allocations have a chance at using up more of it.
......
......@@ -79,9 +79,8 @@ static void updateMaterialNeeds(
WavefrontPathIntegrator::WavefrontPathIntegrator(
pstd::pmr::memory_resource *memoryResource, BasicScene &scene)
: memoryResource(memoryResource) {
ThreadLocal<Allocator> threadAllocators([memoryResource]() {
return Allocator(memoryResource);
});
ThreadLocal<Allocator> threadAllocators(
[memoryResource]() { return Allocator(memoryResource); });
Allocator alloc = threadAllocators.Get();
......
......@@ -72,21 +72,23 @@ void WavefrontPathIntegrator::EvaluateMaterialAndBSDF(MaterialEvalQueue *evalQue
&dpdy);
Vector3f dpdu = w.dpdu, dpdv = w.dpdv;
// Estimate screen-space change in $(u,v)$
Float a00 = Dot(dpdu, dpdu), a01 = Dot(dpdu, dpdv), a11 = Dot(dpdv, dpdv);
Float invDet = 1 / (DifferenceOfProducts(a00, a11, a01, a01));
Float b0x = Dot(dpdu, dpdx), b1x = Dot(dpdv, dpdx);
Float b0y = Dot(dpdu, dpdy), b1y = Dot(dpdv, dpdy);
/* Set the UV partials to zero if dpdu and/or dpdv == 0 */
// Compute $\transpose{\XFORM{A}} \XFORM{A}$ and its determinant
Float ata00 = Dot(dpdu, dpdu), ata01 = Dot(dpdu, dpdv);
Float ata11 = Dot(dpdv, dpdv);
Float invDet = 1 / (DifferenceOfProducts(ata00, ata11, ata01, ata01));
invDet = IsFinite(invDet) ? invDet : 0.f;
dudx = DifferenceOfProducts(a11, b0x, a01, b1x) * invDet;
dvdx = DifferenceOfProducts(a00, b1x, a01, b0x) * invDet;
// Compute $\transpose{\XFORM{A}} \VEC{b}$ for $x$ and $y$
Float atb0x = Dot(dpdu, dpdx), atb1x = Dot(dpdv, dpdx);
Float atb0y = Dot(dpdu, dpdy), atb1y = Dot(dpdv, dpdy);
dudy = DifferenceOfProducts(a11, b0y, a01, b1y) * invDet;
dvdy = DifferenceOfProducts(a00, b1y, a01, b0y) * invDet;
// Compute $u$ and $v$ partial derivatives with respect to $x$ and $y$
dudx = DifferenceOfProducts(ata11, atb0x, ata01, atb1x) * invDet;
dvdx = DifferenceOfProducts(ata00, atb1x, ata01, atb0x) * invDet;
dudy = DifferenceOfProducts(ata11, atb0y, ata01, atb1y) * invDet;
dvdy = DifferenceOfProducts(ata00, atb1y, ata01, atb0y) * invDet;
// Clamp partial derivatives of $u$ and $v$ to reasonable values
dudx = IsFinite(dudx) ? Clamp(dudx, -1e8f, 1e8f) : 0.f;
dvdx = IsFinite(dvdx) ? Clamp(dvdx, -1e8f, 1e8f) : 0.f;
dudy = IsFinite(dudy) ? Clamp(dudy, -1e8f, 1e8f) : 0.f;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册