PBRT_V2 总结记录 <6> RayDifferential 和 DifferentialGeometry

RayDifferential 类

class RayDifferential : public Ray {
public:
	// RayDifferential Public Methods
	RayDifferential() { hasDifferentials = false; }
	RayDifferential(const Point &org, const Vector &dir, float start,
		float end = INFINITY, float t = 0.f, int d = 0)
		: Ray(org, dir, start, end, t, d) {
		hasDifferentials = false;
	}
	RayDifferential(const Point &org, const Vector &dir, const Ray &parent,
		float start, float end = INFINITY)
		: Ray(org, dir, start, end, parent.time, parent.depth + 1) {
		hasDifferentials = false;
	}
	explicit RayDifferential(const Ray &ray) : Ray(ray) {
		hasDifferentials = false;
	}
	bool HasNaNs() const {
		return Ray::HasNaNs() ||
			(hasDifferentials && (rxOrigin.HasNaNs() || ryOrigin.HasNaNs() ||
				rxDirection.HasNaNs() || ryDirection.HasNaNs()));
	}
	void ScaleDifferentials(float s) {
		rxOrigin = o + (rxOrigin - o) * s;
		ryOrigin = o + (ryOrigin - o) * s;
		rxDirection = d + (rxDirection - d) * s;
		ryDirection = d + (ryDirection - d) * s;
	}

	// RayDifferential Public Data
	bool hasDifferentials;
	Point rxOrigin, ryOrigin;
	Vector rxDirection, ryDirection;
};

类的作用:(RayDifferential 来源主要是因为用于 Texture 的 antialiasing ,RayDifferential 继承 Ray类,相对与Ray来说,保存多了2条辅助的ray,这两条ray 是由 主ray 在file plane 的x,y轴上各偏移一个sample得到的,(sampleX + 1, sampleY) (sampleX, sampleY+1))

In order to be able to perform better antialiasing with the texture functions defined in
Chapter 10, pbrt keeps track of some additional information with each ray that is traced.
In Section 10.1, this information will be used to compute information so that the Texture
class can estimate the projected area on the image plane of a small part of the scene. From
this, the Texture can compute the texture’s average value over that area, leading to a better
final image.
RayDifferential is a subclass of Ray that contains additional information about two
auxiliary(辅助) rays. These extra rays represent camera rays offset one sample in the x and y
direction from the main ray on the film plane
. By determining the area that these three
rays project to on an object being shaded, the Texture can estimate an area to average
over for proper antialiasing.

void ScaleDifferentials(float s) {
        rxOrigin = o + (rxOrigin - o) * s;
        ryOrigin = o + (ryOrigin - o) * s;
        rxDirection = d + (rxDirection - d) * s;
        ryDirection = d + (ryDirection - d) * s;
    }

作用:(在Camera->GenerateRayDifferential(samples[i], &rays[i]) 方法生成 RayDifferential , GenerateRayDifferential方法 得到的RayDifferential 保存 的 是 3条Ray的信息,分别是(imageX, imageY) ,(imageX+1, imageY) ,(imageX, imageY+1) ,这样 3条 Ray每条都是相差一个Pixel,然而ScaleDifferentials就是为了让这3条ray 相差只是一个Sample,并不是一个Pixel)

Camera implementations in pbrt compute differentials for rays leaving the camera under
the assumption that camera rays are spaced one pixel apart. The ScaleDifferentials()
method below updates the differential rays for an actual sample spacing s.

DifferentialGeometry 类

// DifferentialGeometry Declarations
struct DifferentialGeometry {
	DifferentialGeometry() {
		u = v = dudx = dvdx = dudy = dvdy = 0.;
		shape = NULL;
	}
	// DifferentialGeometry Public Methods
	DifferentialGeometry(const Point &P, const Vector &DPDU,
		const Vector &DPDV, const Normal &DNDU,
		const Normal &DNDV, float uu, float vv,
		const Shape *sh);

	// 作用 P484
	/*
	call the Differentialgeometry::ComputeDifferentials() method to compute information
	about the projected size of the surface area around the intersection on the image
	plane for use in texture antialiasing and then forward the request to the Primitive
	*/

	// 思路 : P505
	// 计算dudx, dvdx,dudy, dvdy
	void ComputeDifferentials(const RayDifferential &r) const;

	// DifferentialGeometry Public Data
	Point p;
	Normal nn;
	float u, v;
	const Shape *shape;
	Vector dpdu, dpdv;
	Normal dndu, dndv;
	mutable Vector dpdx, dpdy;
	mutable float dudx, dvdx, dudy, dvdy;
};

类的作用:(DifferentialGeometry  类主要用于表示几何体与Ray的相交点的几何信息集合,这个相关点 包含了很多以后渲染要用到的信息,例如,相关的位置坐标,法线,uv坐标,偏导数dpdu,dpdv, dndu,dndv)

We will wrap up this chapter by developing a self-contained representation for the geometry
of a particular point on a surface (typically the point of a ray intersection).
This abstraction needs to hide the particular type of geometric shape the point lies
on, supplying enough information about the surface point to allow the shading and
geometric operations in the rest of pbrt to be implemented generically, without the
need to distinguish between different shape types such as spheres and triangles.

The position of the 3D point p
The surface normal n at the point
(u, v) coordinates from the parameterization of the surface
The parametric partial derivatives dpdu, dpdv
The partial derivatives of the change in surface normal dndu, dndv
A pointer to the Shape that the differential geometry lies on (the Shape class will be
introduced in the next chapter)

猜你喜欢

转载自blog.csdn.net/aa20274270/article/details/82934090
今日推荐