提交 2142a250 编写于 作者: M Matt Pharr

Update from book source.

Rename texture mapping classes to not have "2D" and "3D" suffixes.
Otherwise just naming and formatting changes.
上级 cc09ec47
......@@ -63,20 +63,20 @@ void SurfaceInteraction::ComputeDifferentials(const RayDifferential &ray, Camera
// 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));
Float invDet = 1 / DifferenceOfProducts(ata00, ata11, ata01, ata01);
invDet = IsFinite(invDet) ? invDet : 0.f;
// 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);
// Compute $u$ and $v$ partial derivatives with respect to $x$ and $y$
// Compute $u$ and $v$ 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
// Clamp 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;
......@@ -98,7 +98,7 @@ RayDifferential SurfaceInteraction::SpawnRay(const RayDifferential &rayi,
if (rayi.hasDifferentials) {
// Compute ray differentials for specular reflection or transmission
// Compute common factors for specular ray differentials
Normal3f ns = shading.n;
Normal3f n = shading.n;
Normal3f dndx = shading.dndu * dudx + shading.dndv * dvdx;
Normal3f dndy = shading.dndu * dudy + shading.dndv * dvdy;
Vector3f dwodx = -rayi.rxDirection - wo, dwody = -rayi.ryDirection - wo;
......@@ -110,12 +110,12 @@ RayDifferential SurfaceInteraction::SpawnRay(const RayDifferential &rayi,
rd.ryOrigin = p() + dpdy;
// Compute differential reflected directions
Float dwoDotn_dx = Dot(dwodx, ns) + Dot(wo, dndx);
Float dwoDotn_dy = Dot(dwody, ns) + Dot(wo, dndy);
Float dwoDotn_dx = Dot(dwodx, n) + Dot(wo, dndx);
Float dwoDotn_dy = Dot(dwody, n) + Dot(wo, dndy);
rd.rxDirection =
wi - dwodx + 2 * Vector3f(Dot(wo, ns) * dndx + dwoDotn_dx * ns);
wi - dwodx + 2 * Vector3f(Dot(wo, n) * dndx + dwoDotn_dx * n);
rd.ryDirection =
wi - dwody + 2 * Vector3f(Dot(wo, ns) * dndy + dwoDotn_dy * ns);
wi - dwody + 2 * Vector3f(Dot(wo, n) * dndy + dwoDotn_dy * n);
} else if (flags == BxDFFlags::SpecularTransmission) {
// Initialize origins of specular differential rays
......@@ -125,23 +125,21 @@ RayDifferential SurfaceInteraction::SpawnRay(const RayDifferential &rayi,
// Compute differential transmitted directions
// Find oriented surface normal for transmission
if (Dot(wo, ns) < 0) {
ns = -ns;
if (Dot(wo, n) < 0) {
n = -n;
dndx = -dndx;
dndy = -dndy;
}
// Compute partial derivatives of $\mu$
Float dwoDotn_dx = Dot(dwodx, ns) + Dot(wo, dndx);
Float dwoDotn_dy = Dot(dwody, ns) + Dot(wo, dndy);
Float mu = Dot(wo, ns) / eta - AbsDot(wi, ns);
Float dmudx =
dwoDotn_dx * (1 / eta + (1 / Sqr(eta) * Dot(wo, ns)) / Dot(wi, ns));
Float dmudy =
dwoDotn_dy * (1 / eta + (1 / Sqr(eta) * Dot(wo, ns)) / Dot(wi, ns));
rd.rxDirection = wi - eta * dwodx + Vector3f(mu * dndx + dmudx * ns);
rd.ryDirection = wi - eta * dwody + Vector3f(mu * dndy + dmudy * ns);
Float dwoDotn_dx = Dot(dwodx, n) + Dot(wo, dndx);
Float dwoDotn_dy = Dot(dwody, n) + Dot(wo, dndy);
Float mu = Dot(wo, n) / eta - AbsDot(wi, n);
Float dmudx = dwoDotn_dx * (1 / eta + 1 / Sqr(eta) * Dot(wo, n) / Dot(wi, n));
Float dmudy = dwoDotn_dy * (1 / eta + 1 / Sqr(eta) * Dot(wo, n) / Dot(wi, n));
rd.rxDirection = wi - eta * dwodx + Vector3f(mu * dndx + dmudx * n);
rd.ryDirection = wi - eta * dwody + Vector3f(mu * dndy + dmudy * n);
}
}
// Squash potentially troublesome differentials
......
......@@ -41,27 +41,27 @@ TextureMapping2D TextureMapping2D::Create(const ParameterDictionary &parameters,
Float sv = parameters.GetOneFloat("vscale", 1.);
Float du = parameters.GetOneFloat("udelta", 0.);
Float dv = parameters.GetOneFloat("vdelta", 0.);
return alloc.new_object<UVMapping2D>(su, sv, du, dv);
return alloc.new_object<UVMapping>(su, sv, du, dv);
} else if (type == "spherical")
return alloc.new_object<SphericalMapping2D>(Inverse(renderFromTexture));
return alloc.new_object<SphericalMapping>(Inverse(renderFromTexture));
else if (type == "cylindrical")
return alloc.new_object<CylindricalMapping2D>(Inverse(renderFromTexture));
return alloc.new_object<CylindricalMapping>(Inverse(renderFromTexture));
else if (type == "planar")
return alloc.new_object<PlanarMapping2D>(
return alloc.new_object<PlanarMapping>(
Inverse(renderFromTexture),
parameters.GetOneVector3f("v1", Vector3f(1, 0, 0)),
parameters.GetOneVector3f("v2", Vector3f(0, 1, 0)),
parameters.GetOneFloat("udelta", 0.f), parameters.GetOneFloat("vdelta", 0.f));
else {
Error(loc, "2D texture mapping \"%s\" unknown", type);
return alloc.new_object<UVMapping2D>();
return alloc.new_object<UVMapping>();
}
}
TextureMapping3D TextureMapping3D::Create(const ParameterDictionary &parameters,
const Transform &renderFromTexture,
const FileLoc *loc, Allocator alloc) {
return alloc.new_object<TransformMapping3D>(Inverse(renderFromTexture));
return alloc.new_object<PointTransformMapping>(Inverse(renderFromTexture));
}
std::string FloatTexture::ToString() const {
......@@ -80,26 +80,25 @@ std::string SpectrumTexture::ToString() const {
return DispatchCPU(toStr);
}
std::string UVMapping2D::ToString() const {
return StringPrintf("[ UVMapping2D su: %f sv: %f du: %f dv: %f ]", su, sv, du, dv);
std::string UVMapping::ToString() const {
return StringPrintf("[ UVMapping su: %f sv: %f du: %f dv: %f ]", su, sv, du, dv);
}
std::string SphericalMapping2D::ToString() const {
return StringPrintf("[ SphericalMapping2D textureFromRender: %s ]",
textureFromRender);
std::string SphericalMapping::ToString() const {
return StringPrintf("[ SphericalMapping textureFromRender: %s ]", textureFromRender);
}
std::string CylindricalMapping2D::ToString() const {
return StringPrintf("[ CylindricalMapping2D textureFromRender: %s ]",
std::string CylindricalMapping::ToString() const {
return StringPrintf("[ CylindricalMapping textureFromRender: %s ]",
textureFromRender);
}
std::string PlanarMapping2D::ToString() const {
return StringPrintf("[ PlanarMapping2D vs: %s vt: %s ds: %f dt: %f]", vs, vt, ds, dt);
std::string PlanarMapping::ToString() const {
return StringPrintf("[ PlanarMapping vs: %s vt: %s ds: %f dt: %f]", vs, vt, ds, dt);
}
std::string TransformMapping3D::ToString() const {
return StringPrintf("[ TransformMapping3D textureFromRender: %s ]",
std::string PointTransformMapping::ToString() const {
return StringPrintf("[ PointTransformMapping textureFromRender: %s ]",
textureFromRender);
}
......
......@@ -68,11 +68,11 @@ struct TextureEvalContext {
int faceIndex = 0;
};
// UVMapping2D Definition
class UVMapping2D {
// UVMapping Definition
class UVMapping {
public:
// UVMapping2D Public Methods
UVMapping2D(Float su = 1, Float sv = 1, Float du = 0, Float dv = 0)
// UVMapping Public Methods
UVMapping(Float su = 1, Float sv = 1, Float du = 0, Float dv = 0)
: su(su), sv(sv), du(du), dv(dv) {}
std::string ToString() const;
......@@ -83,18 +83,18 @@ class UVMapping2D {
*dstdx = Vector2f(su * ctx.dudx, sv * ctx.dvdx);
*dstdy = Vector2f(su * ctx.dudy, sv * ctx.dvdy);
return {su * ctx.uv[0] + du, sv * ctx.uv[1] + dv};
return Point2f(su * ctx.uv[0] + du, sv * ctx.uv[1] + dv);
}
private:
Float su, sv, du, dv;
};
// SphericalMapping2D Definition
class SphericalMapping2D {
// SphericalMapping Definition
class SphericalMapping {
public:
// SphericalMapping2D Public Methods
SphericalMapping2D(const Transform &textureFromRender)
// SphericalMapping Public Methods
SphericalMapping(const Transform &textureFromRender)
: textureFromRender(textureFromRender) {}
std::string ToString() const;
......@@ -124,15 +124,15 @@ class SphericalMapping2D {
}
private:
// SphericalMapping2D Private Members
// SphericalMapping Private Members
Transform textureFromRender;
};
// CylindricalMapping2D Definition
class CylindricalMapping2D {
// CylindricalMapping Definition
class CylindricalMapping {
public:
// CylindricalMapping2D Public Methods
CylindricalMapping2D(const Transform &textureFromRender)
// CylindricalMapping Public Methods
CylindricalMapping(const Transform &textureFromRender)
: textureFromRender(textureFromRender) {}
std::string ToString() const;
......@@ -152,16 +152,16 @@ class CylindricalMapping2D {
}
private:
// CylindricalMapping2D Private Members
// CylindricalMapping Private Members
Transform textureFromRender;
};
// PlanarMapping2D Definition
class PlanarMapping2D {
// PlanarMapping Definition
class PlanarMapping {
public:
// PlanarMapping2D Public Methods
PlanarMapping2D(const Transform &textureFromRender, Vector3f vs, Vector3f vt,
Float ds, Float dt)
// PlanarMapping Public Methods
PlanarMapping(const Transform &textureFromRender, Vector3f vs, Vector3f vt, Float ds,
Float dt)
: textureFromRender(textureFromRender), vs(vs), vt(vt), ds(ds), dt(dt) {}
PBRT_CPU_GPU
......@@ -179,21 +179,21 @@ class PlanarMapping2D {
std::string ToString() const;
private:
// PlanarMapping Private Members
Transform textureFromRender;
Vector3f vs, vt;
Float ds, dt;
};
// TextureMapping2D Definition
class TextureMapping2D : public TaggedPointer<UVMapping2D, SphericalMapping2D,
CylindricalMapping2D, PlanarMapping2D> {
class TextureMapping2D : public TaggedPointer<UVMapping, SphericalMapping,
CylindricalMapping, PlanarMapping> {
public:
// TextureMapping2D Interface
using TaggedPointer::TaggedPointer;
PBRT_CPU_GPU
TextureMapping2D(TaggedPointer<UVMapping2D, SphericalMapping2D, CylindricalMapping2D,
PlanarMapping2D>
tp)
TextureMapping2D(
TaggedPointer<UVMapping, SphericalMapping, CylindricalMapping, PlanarMapping> tp)
: TaggedPointer(tp) {}
static TextureMapping2D Create(const ParameterDictionary &parameters,
......@@ -211,11 +211,11 @@ inline Point2f TextureMapping2D::Map(TextureEvalContext ctx, Vector2f *dstdx,
return Dispatch(map);
}
// TransformMapping3D Definition
class TransformMapping3D {
// PointTransformMapping Definition
class PointTransformMapping {
public:
// TransformMapping3D Public Methods
TransformMapping3D(const Transform &textureFromRender)
// PointTransformMapping Public Methods
PointTransformMapping(const Transform &textureFromRender)
: textureFromRender(textureFromRender) {}
std::string ToString() const;
......@@ -232,12 +232,12 @@ class TransformMapping3D {
};
// TextureMapping3D Definition
class TextureMapping3D : public TaggedPointer<TransformMapping3D> {
class TextureMapping3D : public TaggedPointer<PointTransformMapping> {
public:
// TextureMapping3D Interface
using TaggedPointer::TaggedPointer;
PBRT_CPU_GPU
TextureMapping3D(TaggedPointer<TransformMapping3D> tp) : TaggedPointer(tp) {}
TextureMapping3D(TaggedPointer<PointTransformMapping> tp) : TaggedPointer(tp) {}
static TextureMapping3D Create(const ParameterDictionary &parameters,
const Transform &renderFromTexture, const FileLoc *loc,
......
......@@ -75,20 +75,20 @@ void WavefrontPathIntegrator::EvaluateMaterialAndBSDF(MaterialEvalQueue *evalQue
// 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));
Float invDet = 1 / DifferenceOfProducts(ata00, ata11, ata01, ata01);
invDet = IsFinite(invDet) ? invDet : 0.f;
// 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);
// Compute $u$ and $v$ partial derivatives with respect to $x$ and $y$
// Compute $u$ and $v$ 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
// Clamp 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.
先完成此消息的编辑!
想要评论请 注册