PBRT_V2 总结记录 <1> Scene 和 Renderer

流程概述

PBRT_V2 的流程 : 解释完 scene file之后,会进入到 api.cpp 的 pbrtWorldEnd() 方法,在这个 pbrtWorldEnd() 方法中会进行 两个 大的任务。

a : 创建 Scene 和 Renderer

Scene *scene = renderOptions->MakeScene();

Renderer *renderer = renderOptions->MakeRenderer();

b: 渲染

if (scene && renderer) renderer->Render(scene);

1. Scene 类

// Scene Declarations
class Scene {
public:
	// Scene Public Methods
	Scene(Primitive *accel, const vector<Light *> &lts, VolumeRegion *vr);
	~Scene();
	bool Intersect(const Ray &ray, Intersection *isect) const {
		bool hit = aggregate->Intersect(ray, isect);
		return hit;
	}
	bool IntersectP(const Ray &ray) const {
		bool hit = aggregate->IntersectP(ray);
		return hit;
	}
	const BBox &WorldBound() const;

	// Scene Public Data
	Primitive *aggregate;
	vector<Light *> lights;
	VolumeRegion *volumeRegion;
	BBox bound;
};

Primitive *aggregate  作用 : (保存场景的 geometric Primitive)

 Each geometric object in the scene is represented by a Primitive, which combines two
objects: a Shape that specifies its geometry, and a Material that describes its appearance
(e.g., the object’s color, whether it has a dull or glossy finish). All of these geometric 

primitives are collected into a single aggregate Primitive in the Scene member variable
Scene::aggregate. This aggregate is a special kind of primitive that itself holds references
to many other primitives. Because it implements the Primitive interface it appears no
different than a single primitive to the rest of the system. The specific class used to
implement Scene::aggregate stores all the scene’s primitives in an acceleration data
structure that reduces the number of unnecessary ray intersection tests with primitives
that a given ray doesn’t pass near.


vector<Light *> lights 作用 :  (保存场景的  Light)

Each light source in the scene is represented by a Light object, which specifies the shape of a light and the distribution of energy that it emits. The Scene stores all of the lights in a vector class。

VolumeRegion *volumeRegion 作用 : (保存场景的  体积物体(例如雾))

In addition to geometric primitives, pbrt also supports participating media, or volumetric
primitives. These types of primitives are supported through the VolumeRegion
interface.  Like Primitives, multiple VolumeRegions are all stored together in a single aggregate region,
Scene::volumeRegion.

bool Intersect(const Ray &ray, Intersection *isect) const; 作用 : (传入Ray, 判断是否与 场景物体相交,返回相关信息 Intersection)

The Intersect() method traces
the given ray into the scene and returns a Boolean value indicating whether the ray
intersected any of the primitives. If so, it fills in the provided Intersection structure
with information about the closest intersection point along the ray.

bool IntersectP(const Ray &ray) const ;  作用 : (传入Ray, 判断是否与 场景物体相交,不返回人物相交信息)

which checks for the existence of intersections
along the ray, but does not return any information about those intersections.
Because this routine doesn’t need to search for the closest intersection or compute
any additional information about the intersections, it is generally more efficient than
Scene::Intersect(). This routine is used for shadow rays.

const BBox &Scene::WorldBound() : (返回 所有 几何物体 构成的 包围盒)

returns a 3D box that bounds all of the geometry in the
scene, which is simply the bounding box of Scene::aggregate. The Scene class caches
this bound to avoid having to repeatedly compute it.

2. Renderer 类

class Renderer {
public:
	// Renderer Interface
	virtual ~Renderer();
	virtual void Render(const Scene *scene) = 0;
	virtual Spectrum Li(const Scene *scene, const RayDifferential &ray,
		const Sample *sample, RNG &rng, MemoryArena &arena,
		Intersection *isect = NULL, Spectrum *T = NULL) const = 0;
	virtual Spectrum Transmittance(const Scene *scene,
		const RayDifferential &ray, const Sample *sample,
		RNG &rng, MemoryArena &arena) const = 0;
};

类的作用 : (渲染场景,所有高级的Renderer 都要继承这个Renderer 接口)

Rendering an image of the scene is handled by an instance of a class that implements
the Renderer interface. Renderer is an abstract base class that defines a few methods
that must be provided by all renderers.

virtual void Render(const Scene *scene) = 0; 作用 :(渲染场景到一张图片中 或者 计算测量场景光照数据)

The main method that Renderers must provide is Render(); the Renderer is passed a
pointer to a Scene and computes an image of the scene or more generally, a set of
measurements of the scene lighting. For example, in Section 17.3, we define a completely
different kind of Renderer that computes measurements of incident illumination at a set
of points in the scene and writes the results to a text file, without generating an image at
all. These measurements can then be used for interactive rendering of the scene, among
other applications.

virtual Spectrum Li(const Scene *scene, const RayDifferential &ray,
const Sample *sample, RNG &rng, MemoryArena &arena,
Intersection *isect = NULL, Spectrum *T = NULL) const = 0;   作用 :(返回 一条Ray 的 incident radiance)

Renderers are also required to provide methods that compute information about the
illumination along rays in the scene. Li() returns the incident radiance along the given
ray. In addition to the ray and the scene,
it takes a number of additional parameters: the
Sample (whichmay be NULL) provides random sample values forMonte Carlo integration

computations in the integrator, and the RNG is a pseudo-random number generator that
is also available for this purpose. The MemoryArena performs efficient allocation of small
temporary amounts of memory that may be needed while computing radiance along the
ray. Finally, information about the ray’s geometric intersection point can be returned via
the Intersection, if its pointer is non-NULL, and the volumetric transmittance along the
ray is returned via the T parameter, also if non-NULL.

virtual Spectrum Transmittance(const Scene *scene,
const RayDifferential &ray, const Sample *sample,
RNG &rng, MemoryArena &arena) const = 0;   作用 : (返回 通过体积物体的光的衰减程度 )

Transmittance() returns the fraction of light that is attenuated by volumetric scattering
along the ray.
Renderer implementations will generally dispatch(调度) to Integrators (defined
in Chapters 15 and 16) to compute the values returned by Li() and Transmittance().

猜你喜欢

转载自blog.csdn.net/aa20274270/article/details/82878539