rayint icon indicating copy to clipboard operation
rayint copied to clipboard

Frustum culling

Open sweeneychris opened this issue 9 years ago • 4 comments

Thanks for a great app for fast ray intersections! I was wondering what needs to be done in your opinion to add functionality for view frustum culling? It seems most of the constructs are in place to do this easily. I am new to this area but would be happy to take a stab at implementing it if you can provide a bit of guidance.

sweeneychris avatar May 13 '16 17:05 sweeneychris

Hi Chris,

since I have no concept of views or cameras within this project I don't think we should add the functionality. But you can implement a view frustum culling around the ray intersection tests within few lines as I did for example within the texturing project starting here.

Note that the code starting in line 182 does:

  1. Backface culling
  2. A halfspace culling (I falsely referred to it as basic view frustum culling)
  3. A culling base on ray impact angle (You don't want that in rendering)
  4. A projection onto the view plane (The real view frustum culling, although three is also a "valid" pixel check in there)

Thanks for the offer and the interest in the project :-) I'll leave this issue open if you have further questions - feel free to ask.

Cheers, Nils

nmoehrle avatar May 15 '16 08:05 nmoehrle

Even though there is no concept of cameras or views, I can still imagine an interface where clipping planes are provided and the method returns all geometry that satisfies those planes.

I will take a look at the referenced code. Thanks for the response!

sweeneychris avatar May 17 '16 16:05 sweeneychris

Sorry for the late response :-(

An culling based on clipping planes specified as point normal pairs sounds indeed like a good idea. Are you imagining something like:

template <typename Vec3fType>
struct Plane {
    Vec3fType normal;
    Vec3fType origin;
}

template <typename IdxType, typename Vec3fType>
BVHTree<IdxType, Vec3fType>::inside(std::vector<typename Plane<Vec3fType> > convex,
    std::vector<IdxType> * faces, bool completely = false)

where the planes describe a convex subspace and all faces within that space are added to the faces vector.

However I am currently unsure how to efficiently check if a aabb is piercing a convex subspace.

nmoehrle avatar Jun 07 '16 06:06 nmoehrle

Yes, that's exactly how I was imagining it!

I think it would need to explicitly check for a convex subspace -- it should simply return no faces if it is not possible to satisfy all plane boundaries. This would return immediately in this case since the largest BB would not satisfy the plane constraints.

sweeneychris avatar Jun 09 '16 18:06 sweeneychris