In PBRT Chapter Camera Model, when describing Camera::GenerateRay(), it writes

It is important that the direction component of the returned ray be normalized—many other parts of the system will depend on this behavior.

src/cameras/perspective.cpp: line 75:

Float PerspectiveCamera::GenerateRay(const CameraSample &sample,
                                     Ray *ray) const {
    *ray = Ray(Point3f(0, 0, 0), Normalize(Vector3f(pCamera)));

I haven't found any other part of the system actually mention the necessity of normalizing the ray (direction), but when it comes to applying transformations on Rays, the length of ray.direction could change:

src/core/transform.h: line 251 (or line 382):

inline Ray Transform::operator()(const Ray &r) const {
    Vector3f oError;
    Point3f o = (*this)(r.o, &oError);
    Vector3f d = (*this)(r.d);
    // Offset ray origin to edge of error bounds and compute _tMax_
    Float lengthSquared = d.LengthSquared();
    Float tMax = r.tMax;
    if (lengthSquared > 0) {
        Float dt = Dot(Abs(d), oError) / lengthSquared;
        o += d * dt;
        tMax -= dt;
    return Ray(o, d, tMax, r.time, r.medium);

the function that transform Vector3 (src/core/transform.h: line 235):

template <typename T>
inline Vector3<T> Transform::operator()(const Vector3<T> &v) const {
    T x = v.x, y = v.y, z = v.z;
    return Vector3<T>(m.m[0][0] * x + m.m[0][1] * y + m.m[0][2] * z,
                      m.m[1][0] * x + m.m[1][1] * y + m.m[1][2] * z,
                      m.m[2][0] * x + m.m[2][1] * y + m.m[2][2] * z);

Appling transformation on direction of ray (Vector3f d = (*this)(r.d);) would possibly alter it's length, thus break normality, and contradict to previous text "many other parts of the system will depend on this behavior (that rays should be normalized)."

So my question is: why is keeping the generated rays normalized important? And why does it matters no more in applying transformations?

  • 1
    $\begingroup$ Typically directions are used with dot-product calculations (e.g Lighting), and that only works if both vectors are unit length. $\endgroup$
    – PaulHK
    Dec 12, 2022 at 2:42


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.