提交 5ac5351a 编写于 作者: M Matt Pharr

Update from book source. No functional changes.

上级 13a5538c
......@@ -29,8 +29,7 @@ class Interaction {
Interaction() = default;
PBRT_CPU_GPU
Interaction(const Point3fi &pi, const Normal3f &n, const Point2f &uv,
const Vector3f &wo, Float time)
Interaction(Point3fi pi, Normal3f n, Point2f uv, Vector3f wo, Float time)
: pi(pi), n(n), uv(uv), wo(Normalize(wo)), time(time) {}
PBRT_CPU_GPU
......@@ -46,6 +45,7 @@ class Interaction {
CHECK(IsSurfaceInteraction());
return (const SurfaceInteraction &)*this;
}
PBRT_CPU_GPU
SurfaceInteraction &AsSurface() {
CHECK(IsSurfaceInteraction());
......@@ -54,26 +54,24 @@ class Interaction {
// used by medium ctor
PBRT_CPU_GPU
Interaction(const Point3f &p, const Vector3f &wo, Float time, MediumHandle medium)
Interaction(Point3f p, Vector3f wo, Float time, MediumHandle medium)
: pi(p), time(time), wo(wo), medium(medium) {}
PBRT_CPU_GPU
Interaction(const Point3f &p, const Normal3f &n, Float time, MediumHandle medium)
Interaction(Point3f p, Normal3f n, Float time, MediumHandle medium)
: pi(p), n(n), time(time), medium(medium) {}
PBRT_CPU_GPU
Interaction(const Point3fi &pi, const Normal3f &n, Float time = 0,
const Point2f &uv = {})
Interaction(const Point3fi &pi, Normal3f n, Float time = 0, Point2f uv = {})
: pi(pi), n(n), uv(uv), time(time) {}
PBRT_CPU_GPU
Interaction(const Point3fi &pi, const Normal3f &n, const Point2f &uv)
: pi(pi), n(n), uv(uv) {}
Interaction(const Point3fi &pi, Normal3f n, Point2f uv) : pi(pi), n(n), uv(uv) {}
PBRT_CPU_GPU
Interaction(const Point3f &p, Float time, MediumHandle medium)
Interaction(Point3f p, Float time, MediumHandle medium)
: pi(p), time(time), medium(medium) {}
PBRT_CPU_GPU
Interaction(const Point3f &p, const MediumInterface *mediumInterface)
Interaction(Point3f p, const MediumInterface *mediumInterface)
: pi(p), mediumInterface(mediumInterface) {}
PBRT_CPU_GPU
Interaction(const Point3f &p, Float time, const MediumInterface *mediumInterface)
Interaction(Point3f p, Float time, const MediumInterface *mediumInterface)
: pi(p), time(time), mediumInterface(mediumInterface) {}
PBRT_CPU_GPU
const MediumInteraction &AsMedium() const {
......@@ -178,9 +176,8 @@ class SurfaceInteraction : public Interaction {
SurfaceInteraction() = default;
PBRT_CPU_GPU
SurfaceInteraction(const Point3fi &pi, const Point2f &uv, const Vector3f &wo,
const Vector3f &dpdu, const Vector3f &dpdv, const Normal3f &dndu,
const Normal3f &dndv, Float time, bool flipNormal)
SurfaceInteraction(Point3fi pi, Point2f uv, Vector3f wo, Vector3f dpdu, Vector3f dpdv,
Normal3f dndu, Normal3f dndv, Float time, bool flipNormal)
: Interaction(pi, Normal3f(Normalize(Cross(dpdu, dpdv))), uv, wo, time),
dpdu(dpdu),
dpdv(dpdv),
......@@ -201,17 +198,16 @@ class SurfaceInteraction : public Interaction {
}
PBRT_CPU_GPU
SurfaceInteraction(const Point3fi &pi, const Point2f &uv, const Vector3f &wo,
const Vector3f &dpdu, const Vector3f &dpdv, const Normal3f &dndu,
const Normal3f &dndv, Float time, bool flipNormal, int faceIndex)
SurfaceInteraction(Point3fi pi, Point2f uv, Vector3f wo, Vector3f dpdu, Vector3f dpdv,
Normal3f dndu, Normal3f dndv, Float time, bool flipNormal,
int faceIndex)
: SurfaceInteraction(pi, uv, wo, dpdu, dpdv, dndu, dndv, time, flipNormal) {
this->faceIndex = faceIndex;
}
PBRT_CPU_GPU
void SetShadingGeometry(const Normal3f &ns, const Vector3f &dpdus,
const Vector3f &dpdvs, const Normal3f &dndus,
const Normal3f &dndvs, bool orientationIsAuthoritative) {
void SetShadingGeometry(Normal3f ns, Vector3f dpdus, Vector3f dpdvs, Normal3f dndus,
Normal3f dndvs, bool orientationIsAuthoritative) {
// Compute _shading.n_ for _SurfaceInteraction_
shading.n = ns;
DCHECK_NE(shading.n, Normal3f(0, 0, 0));
......
......@@ -25,8 +25,7 @@ class Ray {
Ray() = default;
PBRT_CPU_GPU
Ray(const Point3f &o, const Vector3f &d, Float time = 0.f,
MediumHandle medium = nullptr)
Ray(Point3f o, Vector3f d, Float time = 0.f, MediumHandle medium = nullptr)
: o(o), d(d), time(time), medium(medium) {}
PBRT_CPU_GPU
......@@ -45,7 +44,7 @@ class RayDifferential : public Ray {
// RayDifferential Public Methods
RayDifferential() = default;
PBRT_CPU_GPU
RayDifferential(const Point3f &o, const Vector3f &d, Float time = 0.f,
RayDifferential(Point3f o, Vector3f d, Float time = 0.f,
MediumHandle medium = nullptr)
: Ray(o, d, time, medium) {}
......
......@@ -289,7 +289,7 @@ Float IntegrateCatmullRom(pstd::span<const Float> nodes, pstd::span<const Float>
// Square--Sphere Mapping Function Definitions
// Via source code from Clarberg: Fast Equal-Area Mapping of the (Hemi)Sphere using SIMD
Vector3f EqualAreaSquareToSphere(const Point2f &p) {
Vector3f EqualAreaSquareToSphere(Point2f p) {
CHECK(p.x >= 0 && p.x <= 1 && p.y >= 0 && p.y <= 1);
// Transform _p_ to $[-1,1]^2$ and compute absolute values
Float u = 2 * p.x - 1, v = 2 * p.y - 1;
......@@ -314,7 +314,7 @@ Vector3f EqualAreaSquareToSphere(const Point2f &p) {
}
// Via source code from Clarberg: Fast Equal-Area Mapping of the (Hemi)Sphere using SIMD
Point2f EqualAreaSphereToSquare(const Vector3f &d) {
Point2f EqualAreaSphereToSquare(Vector3f d) {
DCHECK(LengthSquared(d) > .999 && LengthSquared(d) < 1.001);
Float x = std::abs(d.x), y = std::abs(d.y), z = std::abs(d.z);
......
......@@ -106,8 +106,7 @@ class SquareMatrix;
// Math Inline Functions
// http://www.plunk.org/~hatch/rightway.php
PBRT_CPU_GPU
inline Float SinXOverX(Float x) {
PBRT_CPU_GPU inline Float SinXOverX(Float x) {
if (1 + x * x == 1)
return 1;
return std::sin(x) / x;
......@@ -1104,9 +1103,9 @@ PBRT_CPU_GPU inline Interval SumSquares(Interval i, Args... args) {
}
PBRT_CPU_GPU
Vector3f EqualAreaSquareToSphere(const Point2f &p);
Vector3f EqualAreaSquareToSphere(Point2f p);
PBRT_CPU_GPU
Point2f EqualAreaSphereToSquare(const Vector3f &v);
Point2f EqualAreaSphereToSquare(Vector3f v);
PBRT_CPU_GPU
Point2f WrapEqualAreaSquare(Point2f p);
......
......@@ -477,7 +477,7 @@ class BlackbodySpectrum {
PBRT_CPU_GPU
BlackbodySpectrum(Float T) : T(T) {
// Compute blackbody normalization constant for given temperature
Float lambdaMax = Float(2.8977721e-3 / T);
Float lambdaMax = 2.8977721e-3f / T;
normalizationFactor = 1 / Blackbody(lambdaMax * 1e9f, T);
}
......
......@@ -18,7 +18,7 @@ namespace pbrt {
// Transform Function Definitions
// clang-format off
Transform Translate(const Vector3f &delta) {
Transform Translate(Vector3f delta) {
SquareMatrix<4> m(1, 0, 0, delta.x,
0, 1, 0, delta.y,
0, 0, 1, delta.z,
......@@ -78,7 +78,7 @@ Transform RotateZ(Float theta) {
}
// clang-format on
Transform LookAt(const Point3f &pos, const Point3f &look, const Vector3f &up) {
Transform LookAt(Point3f pos, Point3f look, Vector3f up) {
SquareMatrix<4> worldFromCamera;
// Initialize fourth column of viewing matrix
worldFromCamera[0][3] = pos.x;
......@@ -998,7 +998,7 @@ RayDifferential AnimatedTransform::operator()(const RayDifferential &r,
}
}
Point3f AnimatedTransform::operator()(const Point3f &p, Float time) const {
Point3f AnimatedTransform::operator()(Point3f p, Float time) const {
if (!actuallyAnimated || time <= startTime)
return startTransform(p);
else if (time >= endTime)
......@@ -1007,7 +1007,7 @@ Point3f AnimatedTransform::operator()(const Point3f &p, Float time) const {
return t(p);
}
Vector3f AnimatedTransform::operator()(const Vector3f &v, Float time) const {
Vector3f AnimatedTransform::operator()(Vector3f v, Float time) const {
if (!actuallyAnimated || time <= startTime)
return startTransform(v);
else if (time >= endTime)
......@@ -1016,7 +1016,7 @@ Vector3f AnimatedTransform::operator()(const Vector3f &v, Float time) const {
return t(v);
}
Normal3f AnimatedTransform::operator()(const Normal3f &n, Float time) const {
Normal3f AnimatedTransform::operator()(Normal3f n, Float time) const {
if (!actuallyAnimated || time <= startTime)
return startTransform(n);
else if (time >= endTime)
......@@ -1097,7 +1097,7 @@ Bounds3f AnimatedTransform::MotionBounds(const Bounds3f &b) const {
return bounds;
}
Bounds3f AnimatedTransform::BoundPointMotion(const Point3f &p) const {
Bounds3f AnimatedTransform::BoundPointMotion(Point3f p) const {
if (!actuallyAnimated)
return Bounds3f(startTransform(p));
Bounds3f bounds(startTransform(p), endTransform(p));
......
......@@ -114,7 +114,7 @@ class Transform {
explicit Transform(const Frame &frame);
PBRT_CPU_GPU
explicit Transform(const Quaternion &q);
explicit Transform(Quaternion q);
PBRT_CPU_GPU
explicit operator Quaternion() const;
......@@ -188,7 +188,7 @@ class Transform {
// Transform Function Declarations
PBRT_CPU_GPU
Transform Translate(const Vector3f &delta);
Transform Translate(Vector3f delta);
PBRT_CPU_GPU
Transform Scale(Float x, Float y, Float z);
......@@ -201,7 +201,7 @@ PBRT_CPU_GPU
Transform RotateZ(Float theta);
PBRT_CPU_GPU
Transform LookAt(const Point3f &pos, const Point3f &look, const Vector3f &up);
Transform LookAt(Point3f pos, Point3f look, Vector3f up);
PBRT_CPU_GPU
Transform Orthographic(Float znear, Float zfar);
......@@ -210,18 +210,15 @@ PBRT_CPU_GPU
Transform Perspective(Float fov, Float znear, Float zfar);
// Transform Inline Functions
PBRT_CPU_GPU
inline Transform Inverse(const Transform &t) {
PBRT_CPU_GPU inline Transform Inverse(const Transform &t) {
return Transform(t.GetInverseMatrix(), t.GetMatrix());
}
PBRT_CPU_GPU
inline Transform Transpose(const Transform &t) {
PBRT_CPU_GPU inline Transform Transpose(const Transform &t) {
return Transform(Transpose(t.GetMatrix()), Transpose(t.GetInverseMatrix()));
}
PBRT_CPU_GPU
inline Transform Rotate(Float sinTheta, Float cosTheta, const Vector3f &axis) {
PBRT_CPU_GPU inline Transform Rotate(Float sinTheta, Float cosTheta, Vector3f axis) {
Vector3f a = Normalize(axis);
SquareMatrix<4> m;
// Compute rotation of first basis vector
......@@ -244,8 +241,7 @@ inline Transform Rotate(Float sinTheta, Float cosTheta, const Vector3f &axis) {
return Transform(m, Transpose(m));
}
PBRT_CPU_GPU
inline Transform Rotate(Float theta, const Vector3f &axis) {
PBRT_CPU_GPU inline Transform Rotate(Float theta, Vector3f axis) {
Float sinTheta = std::sin(Radians(theta));
Float cosTheta = std::cos(Radians(theta));
return Rotate(sinTheta, cosTheta, axis);
......@@ -253,20 +249,23 @@ inline Transform Rotate(Float theta, const Vector3f &axis) {
// Hughes-Moller 1999-ish. (But with |x| computed differently to avoid edge case when it
// happens to equal |to|.)
PBRT_CPU_GPU inline Transform RotateFromTo(const Vector3f &from, const Vector3f &to) {
Vector3f x = Cross(from, to);
if (LengthSquared(x) == 0)
PBRT_CPU_GPU inline Transform RotateFromTo(Vector3f from, Vector3f to) {
// Compute intermediate vector for vector reflection
Vector3f axis = Cross(from, to);
if (LengthSquared(axis) == 0)
return Transform();
x = Normalize(x);
axis = Normalize(axis);
Vector3f u = x - from, v = x - to;
// Initialize matrix _r_ for rotation
Vector3f u = axis - from, v = axis - to;
SquareMatrix<4> r;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j) {
for (int j = 0; j < 3; ++j)
// Initialize matrix element _r[i][j]_
r[i][j] = ((i == j) ? 1 : 0) - 2 / Dot(u, u) * u[i] * u[j] -
2 / Dot(v, v) * v[i] * v[j] +
4 * Dot(u, v) / (Dot(u, u) * Dot(v, v)) * v[i] * u[j];
}
return Transform(r, Transpose(r));
}
......@@ -368,7 +367,7 @@ inline Transform::Transform(const Frame &frame)
frame.y.z, 0, frame.z.x, frame.z.y, frame.z.z, 0, 0, 0, 0,
1)) {}
inline Transform::Transform(const Quaternion &q) {
inline Transform::Transform(Quaternion q) {
Float xx = q.v.x * q.v.x, yy = q.v.y * q.v.y, zz = q.v.z * q.v.z;
Float xy = q.v.x * q.v.y, xz = q.v.x * q.v.z, yz = q.v.y * q.v.z;
Float wx = q.v.x * q.w, wy = q.v.y * q.w, wz = q.v.z * q.w;
......@@ -460,21 +459,21 @@ class AnimatedTransform {
Ray ApplyInverse(const Ray &r, Float *tMax = nullptr) const;
PBRT_CPU_GPU
Point3f ApplyInverse(const Point3f &p, Float time) const {
Point3f ApplyInverse(Point3f p, Float time) const {
if (!actuallyAnimated)
return startTransform.ApplyInverse(p);
return Interpolate(time).ApplyInverse(p);
}
PBRT_CPU_GPU
Vector3f ApplyInverse(const Vector3f &v, Float time) const {
Vector3f ApplyInverse(Vector3f v, Float time) const {
if (!actuallyAnimated)
return startTransform.ApplyInverse(v);
return Interpolate(time).ApplyInverse(v);
}
PBRT_CPU_GPU
Normal3f operator()(const Normal3f &n, Float time) const;
Normal3f operator()(Normal3f n, Float time) const;
PBRT_CPU_GPU
Normal3f ApplyInverse(const Normal3f &n, Float time) const {
Normal3f ApplyInverse(Normal3f n, Float time) const {
if (!actuallyAnimated)
return startTransform.ApplyInverse(n);
return Interpolate(time).ApplyInverse(n);
......@@ -500,15 +499,15 @@ class AnimatedTransform {
PBRT_CPU_GPU
RayDifferential operator()(const RayDifferential &r, Float *tMax = nullptr) const;
PBRT_CPU_GPU
Point3f operator()(const Point3f &p, Float time) const;
Point3f operator()(Point3f p, Float time) const;
PBRT_CPU_GPU
Vector3f operator()(const Vector3f &v, Float time) const;
Vector3f operator()(Vector3f v, Float time) const;
PBRT_CPU_GPU
Bounds3f MotionBounds(const Bounds3f &b) const;
PBRT_CPU_GPU
Bounds3f BoundPointMotion(const Point3f &p) const;
Bounds3f BoundPointMotion(Point3f p) const;
// AnimatedTransform Public Members
Transform startTransform, endTransform;
......@@ -534,7 +533,7 @@ class AnimatedTransform {
DerivativeTerm(Float c, Float x, Float y, Float z) : kc(c), kx(x), ky(y), kz(z) {}
Float kc, kx, ky, kz;
PBRT_CPU_GPU
Float Eval(const Point3f &p) const { return kc + kx * p.x + ky * p.y + kz * p.z; }
Float Eval(Point3f p) const { return kc + kx * p.x + ky * p.y + kz * p.z; }
};
DerivativeTerm c1[3], c2[3], c3[3], c4[3], c5[3];
};
......
......@@ -798,16 +798,16 @@ class Quaternion {
Quaternion() = default;
PBRT_CPU_GPU
Quaternion &operator+=(const Quaternion &q) {
Quaternion &operator+=(Quaternion q) {
v += q.v;
w += q.w;
return *this;
}
PBRT_CPU_GPU
Quaternion operator+(const Quaternion &q) const { return {v + q.v, w + q.w}; }
Quaternion operator+(Quaternion q) const { return {v + q.v, w + q.w}; }
PBRT_CPU_GPU
Quaternion &operator-=(const Quaternion &q) {
Quaternion &operator-=(Quaternion q) {
v -= q.v;
w -= q.w;
return *this;
......@@ -815,7 +815,7 @@ class Quaternion {
PBRT_CPU_GPU
Quaternion operator-() const { return {-v, -w}; }
PBRT_CPU_GPU
Quaternion operator-(const Quaternion &q) const { return {v - q.v, w - q.w}; }
Quaternion operator-(Quaternion q) const { return {v - q.v, w - q.w}; }
PBRT_CPU_GPU
Quaternion &operator*=(Float f) {
v *= f;
......@@ -1094,27 +1094,23 @@ PBRT_CPU_GPU inline Vector3<T> FaceForward(const Vector3<T> &v, const Normal3<T>
// Quaternion Inline Functions
PBRT_CPU_GPU
inline Quaternion operator*(Float f, const Quaternion &q) {
inline Quaternion operator*(Float f, Quaternion q) {
return q * f;
}
PBRT_CPU_GPU
inline Float Dot(const Quaternion &q1, const Quaternion &q2) {
PBRT_CPU_GPU inline Float Dot(Quaternion q1, Quaternion q2) {
return Dot(q1.v, q2.v) + q1.w * q2.w;
}
PBRT_CPU_GPU
inline Float Length(const Quaternion &q) {
PBRT_CPU_GPU inline Float Length(Quaternion q) {
return std::sqrt(Dot(q, q));
}
PBRT_CPU_GPU
inline Quaternion Normalize(const Quaternion &q) {
PBRT_CPU_GPU inline Quaternion Normalize(Quaternion q) {
DCHECK_GT(Length(q), 0);
return q / Length(q);
}
PBRT_CPU_GPU
inline Float AngleBetween(const Quaternion &q1, const Quaternion &q2) {
PBRT_CPU_GPU inline Float AngleBetween(Quaternion q1, Quaternion q2) {
if (Dot(q1, q2) < 0)
return Pi - 2 * SafeASin(Length(q1 + q2) / 2);
else
......@@ -1122,8 +1118,7 @@ inline Float AngleBetween(const Quaternion &q1, const Quaternion &q2) {
}
// http://www.plunk.org/~hatch/rightway.php
PBRT_CPU_GPU
inline Quaternion Slerp(Float t, const Quaternion &q1, const Quaternion &q2) {
PBRT_CPU_GPU inline Quaternion Slerp(Float t, Quaternion q1, Quaternion q2) {
Float theta = AngleBetween(q1, q2);
Float sinThetaOverTheta = SinXOverX(theta);
return q1 * (1 - t) * SinXOverX((1 - t) * theta) / sinThetaOverTheta +
......@@ -1206,7 +1201,7 @@ class Bounds2 {
return Point2<T>((*this)[(corner & 1)].x, (*this)[(corner & 2) ? 1 : 0].y);
}
PBRT_CPU_GPU
Point2<T> Lerp(const Point2f &t) const {
Point2<T> Lerp(Point2f t) const {
return Point2<T>(pbrt::Lerp(t.x, pMin.x, pMax.x),
pbrt::Lerp(t.y, pMin.y, pMax.y));
}
......@@ -1296,7 +1291,7 @@ class Bounds3 {
}
PBRT_CPU_GPU
Point3<T> Lerp(const Point3f &t) const {
Point3<T> Lerp(Point3f t) const {
return Point3<T>(pbrt::Lerp(t.x, pMin.x, pMax.x), pbrt::Lerp(t.y, pMin.y, pMax.y),
pbrt::Lerp(t.z, pMin.z, pMax.z));
}
......@@ -1666,50 +1661,49 @@ PBRT_CPU_GPU inline Vector3f SphericalDirection(Float sinTheta, Float cosTheta,
Clamp(sinTheta, -1, 1) * std::sin(phi), Clamp(cosTheta, -1, 1));
}
PBRT_CPU_GPU inline Float SphericalTheta(const Vector3f &v) {
PBRT_CPU_GPU inline Float SphericalTheta(Vector3f v) {
return SafeACos(v.z);
}
PBRT_CPU_GPU inline Float SphericalPhi(const Vector3f &v) {
PBRT_CPU_GPU inline Float SphericalPhi(Vector3f v) {
Float p = std::atan2(v.y, v.x);
return (p < 0) ? (p + 2 * Pi) : p;
}
PBRT_CPU_GPU inline Float CosTheta(const Vector3f &w) {
PBRT_CPU_GPU inline Float CosTheta(Vector3f w) {
return w.z;
}
PBRT_CPU_GPU inline Float Cos2Theta(const Vector3f &w) {
PBRT_CPU_GPU inline Float Cos2Theta(Vector3f w) {
return Sqr(w.z);
}
PBRT_CPU_GPU inline Float AbsCosTheta(const Vector3f &w) {
PBRT_CPU_GPU inline Float AbsCosTheta(Vector3f w) {
return std::abs(w.z);
}
PBRT_CPU_GPU inline Float Sin2Theta(const Vector3f &w) {
PBRT_CPU_GPU inline Float Sin2Theta(Vector3f w) {
return std::max<Float>(0, 1 - Cos2Theta(w));
}
PBRT_CPU_GPU inline Float SinTheta(const Vector3f &w) {
PBRT_CPU_GPU inline Float SinTheta(Vector3f w) {
return std::sqrt(Sin2Theta(w));
}
PBRT_CPU_GPU inline Float TanTheta(const Vector3f &w) {
PBRT_CPU_GPU inline Float TanTheta(Vector3f w) {
return SinTheta(w) / CosTheta(w);
}
PBRT_CPU_GPU inline Float Tan2Theta(const Vector3f &w) {
PBRT_CPU_GPU inline Float Tan2Theta(Vector3f w) {
return Sin2Theta(w) / Cos2Theta(w);
}
PBRT_CPU_GPU inline Float CosPhi(const Vector3f &w) {
PBRT_CPU_GPU inline Float CosPhi(Vector3f w) {
Float sinTheta = SinTheta(w);
return (sinTheta == 0) ? 1 : Clamp(w.x / sinTheta, -1, 1);
}
PBRT_CPU_GPU inline Float SinPhi(const Vector3f &w) {
PBRT_CPU_GPU inline Float SinPhi(Vector3f w) {
Float sinTheta = SinTheta(w);
return (sinTheta == 0) ? 0 : Clamp(w.y / sinTheta, -1, 1);
}
PBRT_CPU_GPU
inline Float CosDPhi(const Vector3f &wa, const Vector3f &wb) {
PBRT_CPU_GPU inline Float CosDPhi(Vector3f wa, Vector3f wb) {
Float waxy = Sqr(wa.x) + Sqr(wa.y), wbxy = Sqr(wb.x) + Sqr(wb.y);
if (waxy == 0 || wbxy == 0)
return 1;
......@@ -1717,12 +1711,12 @@ inline Float CosDPhi(const Vector3f &wa, const Vector3f &wb) {
}
PBRT_CPU_GPU
inline bool SameHemisphere(const Vector3f &w, const Vector3f &wp) {
inline bool SameHemisphere(Vector3f w, Vector3f wp) {
return w.z * wp.z > 0;
}
PBRT_CPU_GPU
inline bool SameHemisphere(const Vector3f &w, const Normal3f &wp) {
inline bool SameHemisphere(Vector3f w, Normal3f wp) {
return w.z * wp.z > 0;
}
......@@ -1784,10 +1778,10 @@ class DirectionCone {
// DirectionCone Public Methods
DirectionCone() = default;
PBRT_CPU_GPU
DirectionCone(const Vector3f &w, Float cosTheta)
DirectionCone(Vector3f w, Float cosTheta)
: w(Normalize(w)), cosTheta(cosTheta), empty(false) {}
PBRT_CPU_GPU
explicit DirectionCone(const Vector3f &w) : DirectionCone(w, 1) {}
explicit DirectionCone(Vector3f w) : DirectionCone(w, 1) {}
PBRT_CPU_GPU
static DirectionCone EntireSphere() { return DirectionCone(Vector3f(0, 0, 1), -1); }
......@@ -1804,13 +1798,11 @@ class DirectionCone {
};
// DirectionCone Inline Functions
PBRT_CPU_GPU
inline bool Inside(const DirectionCone &d, const Vector3f &w) {
PBRT_CPU_GPU inline bool Inside(const DirectionCone &d, Vector3f w) {
return !d.empty && Dot(d.w, Normalize(w)) >= d.cosTheta;
}
PBRT_CPU_GPU
inline DirectionCone BoundSubtendedDirections(const Bounds3f &b, const Point3f &p) {
PBRT_CPU_GPU inline DirectionCone BoundSubtendedDirections(const Bounds3f &b, Point3f p) {
// Compute bounding sphere for _b_ and check if _p_ is inside
Float radius;
Point3f pCenter;
......@@ -1820,8 +1812,8 @@ inline DirectionCone BoundSubtendedDirections(const Bounds3f &b, const Point3f &
// Compute and return _DirectionCone_ for bounding sphere
Vector3f w = Normalize(pCenter - p);
Float sinThetaMax2 = radius * radius / DistanceSquared(pCenter, p);
Float cosThetaMax = SafeSqrt(1 - sinThetaMax2);
Float sin2ThetaMax = Sqr(radius) / DistanceSquared(pCenter, p);
Float cosThetaMax = SafeSqrt(1 - sin2ThetaMax);
return DirectionCone(w, cosThetaMax);
}
......@@ -1854,7 +1846,7 @@ class Frame {
PBRT_CPU_GPU
Frame() : x(1, 0, 0), y(0, 1, 0), z(0, 0, 1) {}
PBRT_CPU_GPU
Frame(const Vector3f &x, const Vector3f &y, const Vector3f &z) : x(x), y(y), z(z) {
Frame(Vector3f x, Vector3f y, Vector3f z) : x(x), y(y), z(z) {
DCHECK_LT(std::abs(LengthSquared(x) - 1), 1e-4);
DCHECK_LT(std::abs(LengthSquared(y) - 1), 1e-4);
DCHECK_LT(std::abs(LengthSquared(z) - 1), 1e-4);
......@@ -1864,68 +1856,63 @@ class Frame {
}
PBRT_CPU_GPU
static Frame FromXZ(const Vector3f &x, const Vector3f &z) {
return Frame(x, Cross(z, x), z);
}
static Frame FromXZ(Vector3f x, Vector3f z) { return Frame(x, Cross(z, x), z); }
PBRT_CPU_GPU
static Frame FromXY(const Vector3f &x, const Vector3f &y) {
return Frame(x, y, Cross(x, y));
}
static Frame FromXY(Vector3f x, Vector3f y) { return Frame(x, y, Cross(x, y)); }
PBRT_CPU_GPU
static Frame FromZ(const Vector3f &z) {
static Frame FromZ(Vector3f z) {
Vector3f x, y;
CoordinateSystem(z, &x, &y);
return Frame(x, y, z);
}
PBRT_CPU_GPU
static Frame FromX(const Vector3f &x) {
static Frame FromX(Vector3f x) {
Vector3f y, z;
CoordinateSystem(x, &y, &z);
return Frame(x, y, z);
}
PBRT_CPU_GPU
static Frame FromY(const Vector3f &y) {
static Frame FromY(Vector3f y) {
Vector3f x, z;
CoordinateSystem(y, &z, &x);
return Frame(x, y, z);
}
PBRT_CPU_GPU
static Frame FromX(const Normal3f &x) {
static Frame FromX(Normal3f x) {
Vector3f y, z;
CoordinateSystem(x, &y, &z);
return Frame(Vector3f(x), y, z);
}
PBRT_CPU_GPU
static Frame FromY(const Normal3f &y) {
static Frame FromY(Normal3f y) {
Vector3f x, z;
CoordinateSystem(y, &z, &x);
return Frame(x, Vector3f(y), z);
}
PBRT_CPU_GPU
static Frame FromZ(const Normal3f &z) { return FromZ(Vector3f(z)); }
static Frame FromZ(Normal3f z) { return FromZ(Vector3f(z)); }
PBRT_CPU_GPU
Vector3f ToLocal(const Vector3f &v) const {
Vector3f ToLocal(Vector3f v) const {
return Vector3f(Dot(v, x), Dot(v, y), Dot(v, z));
}
PBRT_CPU_GPU
Normal3f ToLocal(const Normal3f &n) const {
Normal3f ToLocal(Normal3f n) const {
return Normal3f(Dot(n, x), Dot(n, y), Dot(n, z));
}
PBRT_CPU_GPU
Vector3f FromLocal(const Vector3f &v) const { return v.x * x + v.y * y + v.z * z; }
Vector3f FromLocal(Vector3f v) const { return v.x * x + v.y * y + v.z * z; }
PBRT_CPU_GPU
Normal3f FromLocal(const Normal3f &n) const {
return Normal3f(n.x * x + n.y * y + n.z * z);
}
Normal3f FromLocal(Normal3f n) const { return Normal3f(n.x * x + n.y * y + n.z * z); }
std::string ToString() const {
return StringPrintf("[ Frame x: %s y: %s z: %s ]", x, y, z);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册