RenderKit / embree

Embree ray tracing kernels repository.
Apache License 2.0
2.32k stars 383 forks source link

Backface culling for curves #456

Open njroussel opened 10 months ago

njroussel commented 10 months ago

Hi :wave:

Thanks for the great work! I've been trying to get Embree to match with some other library and it requires me to use backface culling on the curve primitive.

As far as I can tell, the CMake option EMBREE_BACKFACE_CULLING_CURVES is only applicable to RTC_GEOMETRY_TYPE_ROUND_LINEAR_CURVE geometry type. Am I correct? I think this should be clarified in the documentation if it is the case.

I've sprinkled the necessary #if !defined (EMBREE_BACKFACE_CULLING_CURVES) in my fork wherever needed to support the RTC_GEOMETRY_TYPE_ROUND_BSPLINE_CURVE type. Would you be willing to consider a PR only for this geometry type? I personally don't need to fix all different curve types.

svenwoop commented 10 months ago

This change will not properly ignore backfacing hits. You just ignore the far intersection with the intersection of a segment of the curve, but if you intersect a bend curve on a shallow angle, you may also exit the curve on the near intersection. Reason is that such segments are itself still curved, this the cone bounding might indicate that the hit will be a near hit, but in the end the curvature. E.g. if the ray is entering the curve, and then traveling almost parallel to the exit plane. In that case the decision if the exit is near or far is an unstable decision and the approach will not work. The right way of doing this is checking the geometry normal Ng and ignoring hits based on this. I will add this to our todo list, maybe next release will also support backface culling of round curve types.