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 BBHLeaf
A lighter-weight version of SurfaceGroup for BBH leaf nodes that need to store multiple surfaces, but which don't need to store additional information like a transform or explicitly stored bounds.
struct BBHNode
A node of an axis-aligned bounding box hierarchy.
struct Mesh
A triangle mesh.
class Scene
Main scene data structure.
class Triangle
An instance of a triangle for a given face in a mesh.
class XformedSurface
A convenience subclass of Surface for surfaces with a Transform.

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.

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 in/out The parent Surface (typically the scene) to add to.
self in A shared_ptr version of this
in 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 in A 3-dimensional ray data structure with minimum/maximum extent information
hit out 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.