// Copyright 2009-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 #pragma once #include "default.h" #include "ray.h" #include "point_query.h" #include "context.h" namespace embree { class Scene; /*! Base class for the acceleration structure data. */ class AccelData : public RefCount { ALIGNED_CLASS_(16); public: enum Type { TY_UNKNOWN = 0, TY_ACCELN = 1, TY_ACCEL_INSTANCE = 2, TY_BVH4 = 3, TY_BVH8 = 4, TY_GPU = 5 }; public: AccelData (const Type type) : bounds(empty), type(type) {} /*! notifies the acceleration structure about the deletion of some geometry */ virtual void deleteGeometry(size_t geomID) {}; /*! clears the acceleration structure data */ virtual void clear() = 0; /*! returns normal bounds */ __forceinline BBox3fa getBounds() const { return bounds.bounds(); } /*! returns bounds for some time */ __forceinline BBox3fa getBounds(float t) const { return bounds.interpolate(t); } /*! returns linear bounds */ __forceinline LBBox3fa getLinearBounds() const { return bounds; } /*! checks if acceleration structure is empty */ __forceinline bool isEmpty() const { return bounds.bounds0.lower.x == float(pos_inf); } public: LBBox3fa bounds; // linear bounds Type type; }; /*! Base class for all intersectable and buildable acceleration structures. */ class Accel : public AccelData { ALIGNED_CLASS_(16); public: struct Intersectors; /*! Type of collide function */ typedef void (*CollideFunc)(void* bvh0, void* bvh1, RTCCollideFunc callback, void* userPtr); /*! Type of point query function */ typedef bool(*PointQueryFunc)(Intersectors* This, /*!< this pointer to accel */ PointQuery* query, /*!< point query for lookup */ PointQueryContext* context); /*!< point query context */ /*! Type of intersect function pointer for single rays. */ typedef void (*IntersectFunc)(Intersectors* This, /*!< this pointer to accel */ RTCRayHit& ray, /*!< ray to intersect */ RayQueryContext* context); /*! Type of intersect function pointer for ray packets of size 4. */ typedef void (*IntersectFunc4)(const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRayHit4& ray, /*!< ray packet to intersect */ RayQueryContext* context); /*! Type of intersect function pointer for ray packets of size 8. */ typedef void (*IntersectFunc8)(const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRayHit8& ray, /*!< ray packet to intersect */ RayQueryContext* context); /*! Type of intersect function pointer for ray packets of size 16. */ typedef void (*IntersectFunc16)(const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRayHit16& ray, /*!< ray packet to intersect */ RayQueryContext* context); /*! Type of occlusion function pointer for single rays. */ typedef void (*OccludedFunc) (Intersectors* This, /*!< this pointer to accel */ RTCRay& ray, /*!< ray to test occlusion */ RayQueryContext* context); /*! Type of occlusion function pointer for ray packets of size 4. */ typedef void (*OccludedFunc4) (const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRay4& ray, /*!< ray packet to test occlusion. */ RayQueryContext* context); /*! Type of occlusion function pointer for ray packets of size 8. */ typedef void (*OccludedFunc8) (const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRay8& ray, /*!< ray packet to test occlusion. */ RayQueryContext* context); /*! Type of occlusion function pointer for ray packets of size 16. */ typedef void (*OccludedFunc16) (const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRay16& ray, /*!< ray packet to test occlusion. */ RayQueryContext* context); typedef void (*ErrorFunc) (); struct Collider { Collider (ErrorFunc error = nullptr) : collide((CollideFunc)error), name(nullptr) {} Collider (CollideFunc collide, const char* name) : collide(collide), name(name) {} operator bool() const { return name; } public: CollideFunc collide; const char* name; }; struct Intersector1 { Intersector1 (ErrorFunc error = nullptr) : intersect((IntersectFunc)error), occluded((OccludedFunc)error), name(nullptr) {} Intersector1 (IntersectFunc intersect, OccludedFunc occluded, const char* name) : intersect(intersect), occluded(occluded), pointQuery(nullptr), name(name) {} Intersector1 (IntersectFunc intersect, OccludedFunc occluded, PointQueryFunc pointQuery, const char* name) : intersect(intersect), occluded(occluded), pointQuery(pointQuery), name(name) {} operator bool() const { return name; } public: static const char* type; IntersectFunc intersect; OccludedFunc occluded; PointQueryFunc pointQuery; const char* name; }; struct Intersector4 { Intersector4 (ErrorFunc error = nullptr) : intersect((IntersectFunc4)error), occluded((OccludedFunc4)error), name(nullptr) {} Intersector4 (IntersectFunc4 intersect, OccludedFunc4 occluded, const char* name) : intersect(intersect), occluded(occluded), name(name) {} operator bool() const { return name; } public: static const char* type; IntersectFunc4 intersect; OccludedFunc4 occluded; const char* name; }; struct Intersector8 { Intersector8 (ErrorFunc error = nullptr) : intersect((IntersectFunc8)error), occluded((OccludedFunc8)error), name(nullptr) {} Intersector8 (IntersectFunc8 intersect, OccludedFunc8 occluded, const char* name) : intersect(intersect), occluded(occluded), name(name) {} operator bool() const { return name; } public: static const char* type; IntersectFunc8 intersect; OccludedFunc8 occluded; const char* name; }; struct Intersector16 { Intersector16 (ErrorFunc error = nullptr) : intersect((IntersectFunc16)error), occluded((OccludedFunc16)error), name(nullptr) {} Intersector16 (IntersectFunc16 intersect, OccludedFunc16 occluded, const char* name) : intersect(intersect), occluded(occluded), name(name) {} operator bool() const { return name; } public: static const char* type; IntersectFunc16 intersect; OccludedFunc16 occluded; const char* name; }; struct Intersectors { Intersectors() : ptr(nullptr), leafIntersector(nullptr), collider(nullptr), intersector1(nullptr), intersector4(nullptr), intersector8(nullptr), intersector16(nullptr) {} Intersectors (ErrorFunc error) : ptr(nullptr), leafIntersector(nullptr), collider(error), intersector1(error), intersector4(error), intersector8(error), intersector16(error) {} void print(size_t ident) { if (collider.name) { for (size_t i=0; i