Surface class

This is the abstract superclass for all surfaces.

Surfaces represent the geometry of the scene. A Surface could be an individual primitive like a Sphere, or it could be composed of many smaller primitives, e.g. the triangles composing a Mesh.

Derived classes

struct BBHNode
A node of an axis-aligned bounding box hierarchy.
struct Mesh
A triangle mesh.
class Scene
Main scene data structure.
class SurfaceGroup
A collection of Surfaces grouped together.
class Triangle
An instance of a triangle for a given face in a mesh.
class XformedSurfaceWithMaterial
A convenience subclass of Surface for simple surfaces with a Transform and a Material.

Public functions

void build() virtual
Perform any necessary precomputation before ray tracing.
void add_child(shared_ptr<Surface> surface) virtual
Add a child surface.
void add_to_parent(Surface* parent, shared_ptr<Surface> self, const json& j) virtual
Add this surface to the parent surface.
auto intersect(const Ray3f& ray, HitInfo& hit) const -> bool virtual
Ray-Surface intersection test.
auto bounds() const -> Box3f pure virtual
Return the surface's world-space AABB.
auto sample(EmitterRecord& rec, const Vec2f& rv) const -> Color3f virtual
Sample a direction from rec.o towards this surface.
auto pdf(const Vec3f& o, const Vec3f& v) const -> float virtual
Return the probability density of the sample generated by sample.
auto is_emissive() const -> bool virtual
Return whether or not this Surface's Material is emissive.

Function documentation

void Surface::build() virtual

Perform any necessary precomputation before ray tracing.

If a surface requires some precomputation (e.g. building an acceleration structure) overload this function. This will be called after the last child has been added and before any call to intersect().

The base class implementation just does nothing.

void Surface::add_child(shared_ptr<Surface> surface) virtual

Add a child surface.

This function will become useful once we create groups of objects. The base class implementation just throws an error.

This function should only be used before build() is called.

void Surface::add_to_parent(Surface* parent, shared_ptr<Surface> self, const json& j) virtual

Add this surface to the parent surface.

Parameters
parent The parent Surface (typically the scene) to add to.
self A shared_ptr version of this
j The json parameters used to create self

By default this function just calls add_child() on the parent.

This function is used by aggregate surfaces that shouldn't themselves be added to the scene (like a mesh), but instead need to create other surfaces (individual triangles) that get added to the scene.

bool Surface::intersect(const Ray3f& ray, HitInfo& hit) const virtual

Ray-Surface intersection test.

Parameters
ray A 3-dimensional ray data structure with minimum/maximum extent information
hit A detailed intersection record, which will be filled by the intersection query
Returns true if an intersection was found

Intersect a ray against this surface and return detailed intersection information.

Color3f Surface::sample(EmitterRecord& rec, const Vec2f& rv) const virtual

Sample a direction from rec.o towards this surface.

Parameters
rec An emitter query record. Only rec.o is used as input, the remaining fields are used as output.
rv Two uniformly distributed random variables on [0,1)
Returns The surface color value divided by the probability density of the sample. A zero value means that sampling failed.

Store result in rec, and return important weight (i.e. the color of the Surface divided by the probability density of the sample with respect to solid angle).