Skip to content
Syoyo Fujita edited this page May 8, 2016 · 5 revisions

Custom geometry and intersection

(Experimental. custom_intersection branch)

You can support custom geometry and intersection by providing codes with C++ template.

The following method is required to implement.

    /// 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);
    /// 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);
    /// 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);
/// 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 {
   }
   ...
}
Clone this wiki locally