-
Notifications
You must be signed in to change notification settings - Fork 92
Syoyo Fujita edited this page May 8, 2016
·
5 revisions
(Experimental. custom_intersection
branch)
You can support custom geometry and intersection by providing codes with C++ template.
See TriangleMesh
and TriangleSAHPred
class in nanort.h
, and examples/particle_primitive
for sphere example.
The following method is required to implement. (Please see source code for up to date information. Wiki may be a bit old)
class YourGeometry
{
/// Do ray interesection stuff for `prim_index` th primitive and return hit distance `t`,
/// varycentric coordinate `u` and `v`.
/// Returns true if there's intersection.
bool Intersect(float *t_inout, float *u_out, float *v_out, unsigned int prim_index) const;
/// Compute bounding box for `prim_index`th triangle.
/// This function is called for each primitive in BVH build.
void BoundingBox(float3 *bmin, float3 *bmax,
unsigned int prim_index) const;
/// Prepare BVH traversal(e.g. compute inverse ray direction)
/// This function is called only once in BVH traversal.
void PrepareTraversal(const Ray& ray, const BVHTraceOptions& trace_options) const;
private:
mutable ... // All methods are qualified with const, thus if you want store some state, use mutable.
}
/// Predicator required for std::partition which is called when building BVH.
class TriangleSAHPred {
public:
TriangleSAHPred(const float *vertices, const unsigned int *faces)
: axis_(0), pos_(0.0f), vertices_(vertices), faces_(faces) {}
void Set(int axis, float pos) {
axis_ = axis;
pos_ = pos;
}
bool operator()(unsigned int i) const {
}
...
}