PBRT_V2 總結記錄 <18> OrthoCamera 和 EnvironmentCamera
OrthoCamera 類
// OrthographicCamera Declarations class OrthoCamera : public ProjectiveCamera { public: // OrthoCamera Public Methods OrthoCamera(const AnimatedTransform &cam2world, const float screenWindow[4], float sopen, float sclose, float lensr, float focald, Film *film); float GenerateRay(const CameraSample &sample, Ray *) const; float GenerateRayDifferential(const CameraSample &sample, RayDifferential *) const; private: // OrthoCamera Private Data Vector dxCamera, dyCamera; };
類的作用: 正交相機
1. 建構函式
OrthoCamera::OrthoCamera(const AnimatedTransform &cam2world, const float screenWindow[4], float sopen, float sclose, float lensr, float focald, Film *f) : ProjectiveCamera(cam2world, Orthographic(0., 1.), screenWindow, sopen, sclose, lensr, focald, f) { // Compute differential changes in origin for ortho camera rays dxCamera = RasterToCamera(Vector(1, 0, 0)); dyCamera = RasterToCamera(Vector(0, 1, 0)); }
細節:
(主要在 Orthographic() 函式中生成正交投影矩陣)
The orthographic camera constructor generates the orthographic transformation matrix with the Orthographic() function, which will be defined shortly.
Orthographic() 函式:
Transform Orthographic(float znear, float zfar) { return Scale(1.f, 1.f, 1.f / (zfar - znear)) * Translate(Vector(0.f, 0.f, -znear)); }
Figure 6.2: The orthographic view volume is an axis-aligned box in camera space, defined such that objects inside the region are projected onto the z = hither face of the box.
The orthographic viewing transformation leaves x and y coordinates unchanged, but maps z values at the hither plane to 0 and z values at the yon plane to 1. To do this, the scene is first translated along the z axis so that the hither plane is aligned with z = 0. Then, the scene is scaled in z so that the yon plane maps to z = 1. The composition of these two transformations gives the overall transformation. (For a ray tracer like pbrt, we’d like the hither plane to be at 0 so that rays start at the plane that goes through the camera’s position; the yon plane offset doesn’t particularly matter.)
總結: 正交投影矩陣 在PBRT中的生成思路:
a. 保持x,y 座標不變
b. z : 【0, 1】, 所以,第一步就是進行z偏移,把近平面的 移到 z = 0 ,之後再縮放 z值,把遠平面變成 z = 1,所以就涉及到了 平移和縮放。
2. GenerateRay
float OrthoCamera::GenerateRay(const CameraSample &sample, Ray *ray) const {
// Generate raster and camera samples
Point Pras(sample.imageX, sample.imageY, 0);
Point Pcamera;
RasterToCamera(Pras, &Pcamera);
*ray = Ray(Pcamera, Vector(0,0,1), 0.f, INFINITY);
// Modify ray for depth of field
if (lensRadius > 0.) {
// Sample point on lens
float lensU, lensV;
ConcentricSampleDisk(sample.lensU, sample.lensV, &lensU, &lensV);
lensU *= lensRadius;
lensV *= lensRadius;
// Compute point on plane of focus
float ft = focalDistance / ray->d.z;
Point Pfocus = (*ray)(ft);
// Update ray for effect of lens
ray->o = Point(lensU, lensV, 0.f);
ray->d = Normalize(Pfocus - ray->o);
}
ray->time = sample.time;
CameraToWorld(*ray, ray);
return 1.f;
}
思路:
(需要注意的是,正交相機,發出的射線的方向是 (0,0,1))
Figure 6.4: To create a ray with the orthographic camera, a raster space position on the image plane is transformed to camera space, giving the ray’s origin on the hither plane. The ray’s direction in camera space is (0, 0, 1), down the z axis.