Path: blob/master/thirdparty/embree/include/embree4/rtcore_scene.h
9905 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "rtcore_device.h"67RTC_NAMESPACE_BEGIN89/* Opaque traversable type */10typedef struct RTCTraversableTy* RTCTraversable;1112/* Forward declarations for ray structures */13struct RTCRayHit;14struct RTCRayHit4;15struct RTCRayHit8;16struct RTCRayHit16;1718/* Scene flags */19enum RTCSceneFlags20{21RTC_SCENE_FLAG_NONE = 0,22RTC_SCENE_FLAG_DYNAMIC = (1 << 0),23RTC_SCENE_FLAG_COMPACT = (1 << 1),24RTC_SCENE_FLAG_ROBUST = (1 << 2),25RTC_SCENE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS = (1 << 3),26RTC_SCENE_FLAG_PREFETCH_USM_SHARED_ON_GPU = (1 << 4),27};2829/* Additional arguments for rtcIntersect1/4/8/16 calls */30struct RTCIntersectArguments31{32enum RTCRayQueryFlags flags; // intersection flags33enum RTCFeatureFlags feature_mask; // selectively enable features for traversal34struct RTCRayQueryContext* context; // optional pointer to ray query context35RTCFilterFunctionN filter; // filter function to execute36RTCIntersectFunctionN intersect; // user geometry intersection callback to execute37#if RTC_MIN_WIDTH38float minWidthDistanceFactor; // curve radius is set to this factor times distance to ray origin39#endif40};4142/* Initializes intersection arguments. */43RTC_FORCEINLINE void rtcInitIntersectArguments(struct RTCIntersectArguments* args)44{45args->flags = RTC_RAY_QUERY_FLAG_INCOHERENT;46args->feature_mask = RTC_FEATURE_FLAG_ALL;47args->context = NULL;48args->filter = NULL;49args->intersect = NULL;5051#if RTC_MIN_WIDTH52args->minWidthDistanceFactor = 0.0f;53#endif54}5556/* Additional arguments for rtcOccluded1/4/8/16 calls */57struct RTCOccludedArguments58{59enum RTCRayQueryFlags flags; // intersection flags60enum RTCFeatureFlags feature_mask; // selectively enable features for traversal61struct RTCRayQueryContext* context; // optional pointer to ray query context62RTCFilterFunctionN filter; // filter function to execute63RTCOccludedFunctionN occluded; // user geometry occlusion callback to execute6465#if RTC_MIN_WIDTH66float minWidthDistanceFactor; // curve radius is set to this factor times distance to ray origin67#endif68};6970/* Initializes an intersection arguments. */71RTC_FORCEINLINE void rtcInitOccludedArguments(struct RTCOccludedArguments* args)72{73args->flags = RTC_RAY_QUERY_FLAG_INCOHERENT;74args->feature_mask = RTC_FEATURE_FLAG_ALL;75args->context = NULL;76args->filter = NULL;77args->occluded = NULL;7879#if RTC_MIN_WIDTH80args->minWidthDistanceFactor = 0.0f;81#endif82}8384/* Creates a new scene. */85RTC_API RTCScene rtcNewScene(RTCDevice device);8687/* Returns the device the scene got created in. The reference count of88* the device is incremented by this function. */89RTC_API RTCDevice rtcGetSceneDevice(RTCScene hscene);9091/* Retains the scene (increments the reference count). */92RTC_API void rtcRetainScene(RTCScene scene);9394/* Releases the scene (decrements the reference count). */95RTC_API void rtcReleaseScene(RTCScene scene);9697/* Returns the traversable object of the scene which can be passed to ray queries. */98RTC_API RTCTraversable rtcGetSceneTraversable(RTCScene scene);99100/* Attaches the geometry to a scene. */101RTC_API unsigned int rtcAttachGeometry(RTCScene scene, RTCGeometry geometry);102103/* Attaches the geometry to a scene using the specified geometry ID. */104RTC_API void rtcAttachGeometryByID(RTCScene scene, RTCGeometry geometry, unsigned int geomID);105106/* Detaches the geometry from the scene. */107RTC_API void rtcDetachGeometry(RTCScene scene, unsigned int geomID);108109/* Gets a geometry handle from the scene. This function is not thread safe and should get used during rendering. */110RTC_API RTCGeometry rtcGetGeometry(RTCScene scene, unsigned int geomID);111112/* Gets a geometry handle from the scene. This function is thread safe and should NOT get used during rendering. */113RTC_API RTCGeometry rtcGetGeometryThreadSafe(RTCScene scene, unsigned int geomID);114115116/* Commits the scene. */117RTC_API void rtcCommitScene(RTCScene scene);118119/* Commits the scene from multiple threads. */120RTC_API void rtcJoinCommitScene(RTCScene scene);121122123/* Progress monitor callback function */124typedef bool (*RTCProgressMonitorFunction)(void* ptr, double n);125126/* Sets the progress monitor callback function of the scene. */127RTC_API void rtcSetSceneProgressMonitorFunction(RTCScene scene, RTCProgressMonitorFunction progress, void* ptr);128129/* Sets the build quality of the scene. */130RTC_API void rtcSetSceneBuildQuality(RTCScene scene, enum RTCBuildQuality quality);131132/* Sets the scene flags. */133RTC_API void rtcSetSceneFlags(RTCScene scene, enum RTCSceneFlags flags);134135/* Returns the scene flags. */136RTC_API enum RTCSceneFlags rtcGetSceneFlags(RTCScene scene);137138/* Returns the axis-aligned bounds of the scene. */139RTC_API void rtcGetSceneBounds(RTCScene scene, struct RTCBounds* bounds_o);140141/* Returns the linear axis-aligned bounds of the scene. */142RTC_API void rtcGetSceneLinearBounds(RTCScene scene, struct RTCLinearBounds* bounds_o);143144#if !defined(__SYCL_DEVICE_ONLY__)145146/* Gets the user-defined data pointer of the geometry. This function is not thread safe and should get used during rendering. */147RTC_SYCL_API void* rtcGetGeometryUserDataFromScene(RTCScene scene, unsigned int geomID);148149/* Returns the interpolated transformation of an instance for the specified time. */150RTC_SYCL_API void rtcGetGeometryTransformFromScene(RTCScene scene, unsigned int geomID, float time, enum RTCFormat format, void* xfm);151152/* Perform a closest point query of the scene. */153RTC_API bool rtcPointQuery(RTCScene scene, struct RTCPointQuery* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void* userPtr);154155/* Perform a closest point query with a packet of 4 points with the scene. */156RTC_API bool rtcPointQuery4(const int* valid, RTCScene scene, struct RTCPointQuery4* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr);157158/* Perform a closest point query with a packet of 4 points with the scene. */159RTC_API bool rtcPointQuery8(const int* valid, RTCScene scene, struct RTCPointQuery8* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr);160161/* Perform a closest point query with a packet of 4 points with the scene. */162RTC_API bool rtcPointQuery16(const int* valid, RTCScene scene, struct RTCPointQuery16* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr);163164165/* Intersects a single ray with the scene. */166RTC_SYCL_API void rtcIntersect1(RTCScene scene, struct RTCRayHit* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);167168/* Intersects a packet of 4 rays with the scene. */169RTC_API void rtcIntersect4(const int* valid, RTCScene scene, struct RTCRayHit4* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);170171/* Intersects a packet of 8 rays with the scene. */172RTC_API void rtcIntersect8(const int* valid, RTCScene scene, struct RTCRayHit8* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);173174/* Intersects a packet of 16 rays with the scene. */175RTC_API void rtcIntersect16(const int* valid, RTCScene scene, struct RTCRayHit16* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);176177178/* Forwards ray inside user geometry callback. */179RTC_SYCL_API void rtcForwardIntersect1(const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID);180181/* Forwards ray inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */182RTC_SYCL_API void rtcForwardIntersect1Ex(const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID, unsigned int instPrimID);183184/* Forwards ray packet of size 4 inside user geometry callback. */185RTC_API void rtcForwardIntersect4(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID);186187/* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */188RTC_API void rtcForwardIntersect4Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID, unsigned int primInstID);189190/* Forwards ray packet of size 8 inside user geometry callback. */191RTC_API void rtcForwardIntersect8(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID);192193/* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */194RTC_API void rtcForwardIntersect8Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID, unsigned int primInstID);195196/* Forwards ray packet of size 16 inside user geometry callback. */197RTC_API void rtcForwardIntersect16(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID);198199/* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */200RTC_API void rtcForwardIntersect16Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID, unsigned int primInstID);201202203/* Tests a single ray for occlusion with the scene. */204RTC_SYCL_API void rtcOccluded1(RTCScene scene, struct RTCRay* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);205206/* Tests a packet of 4 rays for occlusion occluded with the scene. */207RTC_API void rtcOccluded4(const int* valid, RTCScene scene, struct RTCRay4* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);208209/* Tests a packet of 8 rays for occlusion with the scene. */210RTC_API void rtcOccluded8(const int* valid, RTCScene scene, struct RTCRay8* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);211212/* Tests a packet of 16 rays for occlusion with the scene. */213RTC_API void rtcOccluded16(const int* valid, RTCScene scene, struct RTCRay16* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);214215216/* Forwards single occlusion ray inside user geometry callback. */217RTC_SYCL_API void rtcForwardOccluded1(const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID);218219/* Forwards single occlusion ray inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */220RTC_SYCL_API void rtcForwardOccluded1Ex(const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID, unsigned int instPrimID);221222/* Forwards occlusion ray packet of size 4 inside user geometry callback. */223RTC_API void rtcForwardOccluded4(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID);224225/* Forwards occlusion ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */226RTC_API void rtcForwardOccluded4Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID, unsigned int instPrimID);227228/* Forwards occlusion ray packet of size 8 inside user geometry callback. */229RTC_API void rtcForwardOccluded8(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID);230231/* Forwards occlusion ray packet of size 8 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */232RTC_API void rtcForwardOccluded8Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID, unsigned int instPrimID);233234/* Forwards occlusion ray packet of size 16 inside user geometry callback. */235RTC_API void rtcForwardOccluded16(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID);236237/* Forwards occlusion ray packet of size 16 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */238RTC_API void rtcForwardOccluded16Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID, unsigned int instPrimID);239240#endif241242/* Gets the user-defined data pointer of the geometry. This function is not thread safe and should get used during rendering. */243RTC_SYCL_API void* rtcGetGeometryUserDataFromTraversable(RTCTraversable traversable, unsigned int geomID);244245/* Returns the interpolated transformation of an instance for the specified time. */246RTC_SYCL_API void rtcGetGeometryTransformFromTraversable(RTCTraversable traversable, unsigned int geomID, float time, enum RTCFormat format, void* xfm);247248/* Perform a closest point query of the scene. */249RTC_API bool rtcTraversablePointQuery(RTCTraversable traversable, struct RTCPointQuery* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void* userPtr);250251/* Perform a closest point query with a packet of 4 points with the scene. */252RTC_API bool rtcTraversablePointQuery4(const int* valid, RTCTraversable traversable, struct RTCPointQuery4* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr);253254/* Perform a closest point query with a packet of 4 points with the scene. */255RTC_API bool rtcTraversablePointQuery8(const int* valid, RTCTraversable traversable, struct RTCPointQuery8* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr);256257/* Perform a closest point query with a packet of 4 points with the scene. */258RTC_API bool rtcTraversablePointQuery16(const int* valid, RTCTraversable traversable, struct RTCPointQuery16* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr);259260261/* Intersects a single ray with the scene. */262RTC_SYCL_API void rtcTraversableIntersect1(RTCTraversable traversable, struct RTCRayHit* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);263264/* Intersects a packet of 4 rays with the scene. */265RTC_API void rtcTraversableIntersect4(const int* valid, RTCTraversable traversable, struct RTCRayHit4* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);266267/* Intersects a packet of 8 rays with the scene. */268RTC_API void rtcTraversableIntersect8(const int* valid, RTCTraversable traversable, struct RTCRayHit8* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);269270/* Intersects a packet of 16 rays with the scene. */271RTC_API void rtcTraversableIntersect16(const int* valid, RTCTraversable traversable, struct RTCRayHit16* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT);272273274/* Forwards ray inside user geometry callback. */275RTC_SYCL_API void rtcTraversableForwardIntersect1(const struct RTCIntersectFunctionNArguments* args, RTCTraversable traversable, struct RTCRay* ray, unsigned int instID);276277/* Forwards ray inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */278RTC_SYCL_API void rtcTraversableForwardIntersect1Ex(const struct RTCIntersectFunctionNArguments* args, RTCTraversable traversable, struct RTCRay* ray, unsigned int instID, unsigned int instPrimID);279280/* Forwards ray packet of size 4 inside user geometry callback. */281RTC_API void rtcTraversableForwardIntersect4(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCTraversable traversable, struct RTCRay4* ray, unsigned int instID);282283/* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */284RTC_API void rtcTraversableForwardIntersect4Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCTraversable traversable, struct RTCRay4* ray, unsigned int instID, unsigned int primInstID);285286/* Forwards ray packet of size 8 inside user geometry callback. */287RTC_API void rtcTraversableForwardIntersect8(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCTraversable traversable, struct RTCRay8* ray, unsigned int instID);288289/* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */290RTC_API void rtcTraversableForwardIntersect8Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCTraversable traversable, struct RTCRay8* ray, unsigned int instID, unsigned int primInstID);291292/* Forwards ray packet of size 16 inside user geometry callback. */293RTC_API void rtcTraversableForwardIntersect16(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCTraversable traversable, struct RTCRay16* ray, unsigned int instID);294295/* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */296RTC_API void rtcTraversableForwardIntersect16Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCTraversable traversable, struct RTCRay16* ray, unsigned int instID, unsigned int primInstID);297298299/* Tests a single ray for occlusion with the scene. */300RTC_SYCL_API void rtcTraversableOccluded1(RTCTraversable traversable, struct RTCRay* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);301302/* Tests a packet of 4 rays for occlusion occluded with the scene. */303RTC_API void rtcTraversableOccluded4(const int* valid, RTCTraversable traversable, struct RTCRay4* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);304305/* Tests a packet of 8 rays for occlusion with the scene. */306RTC_API void rtcTraversableOccluded8(const int* valid, RTCTraversable traversable, struct RTCRay8* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);307308/* Tests a packet of 16 rays for occlusion with the scene. */309RTC_API void rtcTraversableOccluded16(const int* valid, RTCTraversable traversable, struct RTCRay16* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT);310311312/* Forwards single occlusion ray inside user geometry callback. */313RTC_SYCL_API void rtcTraversableForwardOccluded1(const struct RTCOccludedFunctionNArguments* args, RTCTraversable traversable, struct RTCRay* ray, unsigned int instID);314315/* Forwards single occlusion ray inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */316RTC_SYCL_API void rtcTraversableForwardOccluded1Ex(const struct RTCOccludedFunctionNArguments* args, RTCTraversable traversable, struct RTCRay* ray, unsigned int instID, unsigned int instPrimID);317318/* Forwards occlusion ray packet of size 4 inside user geometry callback. */319RTC_API void rtcTraversableForwardOccluded4(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCTraversable traversable, struct RTCRay4* ray, unsigned int instID);320321/* Forwards occlusion ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */322RTC_API void rtcTraversableForwardOccluded4Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCTraversable traversable, struct RTCRay4* ray, unsigned int instID, unsigned int instPrimID);323324/* Forwards occlusion ray packet of size 8 inside user geometry callback. */325RTC_API void rtcTraversableForwardOccluded8(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCTraversable traversable, struct RTCRay8* ray, unsigned int instID);326327/* Forwards occlusion ray packet of size 8 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */328RTC_API void rtcTraversableForwardOccluded8Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCTraversable traversable, struct RTCRay8* ray, unsigned int instID, unsigned int instPrimID);329330/* Forwards occlusion ray packet of size 16 inside user geometry callback. */331RTC_API void rtcTraversableForwardOccluded16(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCTraversable traversable, struct RTCRay16* ray, unsigned int instID);332333/* Forwards occlusion ray packet of size 16 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */334RTC_API void rtcTraversableForwardOccluded16Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCTraversable traversable, struct RTCRay16* ray, unsigned int instID, unsigned int instPrimID);335336337/*! collision callback */338struct RTCCollision { unsigned int geomID0; unsigned int primID0; unsigned int geomID1; unsigned int primID1; };339typedef void (*RTCCollideFunc) (void* userPtr, struct RTCCollision* collisions, unsigned int num_collisions);340341/*! Performs collision detection of two scenes */342RTC_API void rtcCollide (RTCScene scene0, RTCScene scene1, RTCCollideFunc callback, void* userPtr);343344#if defined(__cplusplus)345346/* Helper for easily combining scene flags */347inline RTCSceneFlags operator|(RTCSceneFlags a, RTCSceneFlags b) {348return (RTCSceneFlags)((size_t)a | (size_t)b);349}350351#endif352353RTC_NAMESPACE_END354355356357