# PBRT: why normalize ray's direction

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.

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:

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 * x + m.m * y + m.m * z,
m.m * x + m.m * y + m.m * z,
m.m * x + m.m * y + m.m * 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?

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