rtcore_geometry.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "rtcore_buffer.h"
  5. #include "rtcore_quaternion.h"
  6. RTC_NAMESPACE_BEGIN
  7. /* Opaque scene type */
  8. typedef struct RTCSceneTy* RTCScene;
  9. /* Opaque geometry type */
  10. typedef struct RTCGeometryTy* RTCGeometry;
  11. /* Types of geometries */
  12. enum RTCGeometryType
  13. {
  14. RTC_GEOMETRY_TYPE_TRIANGLE = 0, // triangle mesh
  15. RTC_GEOMETRY_TYPE_QUAD = 1, // quad (triangle pair) mesh
  16. RTC_GEOMETRY_TYPE_GRID = 2, // grid mesh
  17. RTC_GEOMETRY_TYPE_SUBDIVISION = 8, // Catmull-Clark subdivision surface
  18. RTC_GEOMETRY_TYPE_CONE_LINEAR_CURVE = 15, // Cone linear curves - discontinuous at edge boundaries
  19. RTC_GEOMETRY_TYPE_ROUND_LINEAR_CURVE = 16, // Round (rounded cone like) linear curves
  20. RTC_GEOMETRY_TYPE_FLAT_LINEAR_CURVE = 17, // flat (ribbon-like) linear curves
  21. RTC_GEOMETRY_TYPE_ROUND_BEZIER_CURVE = 24, // round (tube-like) Bezier curves
  22. RTC_GEOMETRY_TYPE_FLAT_BEZIER_CURVE = 25, // flat (ribbon-like) Bezier curves
  23. RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BEZIER_CURVE = 26, // flat normal-oriented Bezier curves
  24. RTC_GEOMETRY_TYPE_ROUND_BSPLINE_CURVE = 32, // round (tube-like) B-spline curves
  25. RTC_GEOMETRY_TYPE_FLAT_BSPLINE_CURVE = 33, // flat (ribbon-like) B-spline curves
  26. RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BSPLINE_CURVE = 34, // flat normal-oriented B-spline curves
  27. RTC_GEOMETRY_TYPE_ROUND_HERMITE_CURVE = 40, // round (tube-like) Hermite curves
  28. RTC_GEOMETRY_TYPE_FLAT_HERMITE_CURVE = 41, // flat (ribbon-like) Hermite curves
  29. RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_HERMITE_CURVE = 42, // flat normal-oriented Hermite curves
  30. RTC_GEOMETRY_TYPE_SPHERE_POINT = 50,
  31. RTC_GEOMETRY_TYPE_DISC_POINT = 51,
  32. RTC_GEOMETRY_TYPE_ORIENTED_DISC_POINT = 52,
  33. RTC_GEOMETRY_TYPE_ROUND_CATMULL_ROM_CURVE = 58, // round (tube-like) Catmull-Rom curves
  34. RTC_GEOMETRY_TYPE_FLAT_CATMULL_ROM_CURVE = 59, // flat (ribbon-like) Catmull-Rom curves
  35. RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_CATMULL_ROM_CURVE = 60, // flat normal-oriented Catmull-Rom curves
  36. RTC_GEOMETRY_TYPE_USER = 120, // user-defined geometry
  37. RTC_GEOMETRY_TYPE_INSTANCE = 121, // scene instance
  38. RTC_GEOMETRY_TYPE_INSTANCE_ARRAY = 122, // scene instance array
  39. };
  40. /* Interpolation modes for subdivision surfaces */
  41. enum RTCSubdivisionMode
  42. {
  43. RTC_SUBDIVISION_MODE_NO_BOUNDARY = 0,
  44. RTC_SUBDIVISION_MODE_SMOOTH_BOUNDARY = 1,
  45. RTC_SUBDIVISION_MODE_PIN_CORNERS = 2,
  46. RTC_SUBDIVISION_MODE_PIN_BOUNDARY = 3,
  47. RTC_SUBDIVISION_MODE_PIN_ALL = 4,
  48. };
  49. /* Curve segment flags */
  50. enum RTCCurveFlags
  51. {
  52. RTC_CURVE_FLAG_NEIGHBOR_LEFT = (1 << 0), // left segments exists
  53. RTC_CURVE_FLAG_NEIGHBOR_RIGHT = (1 << 1) // right segment exists
  54. };
  55. /* Arguments for RTCBoundsFunction */
  56. struct RTCBoundsFunctionArguments
  57. {
  58. void* geometryUserPtr;
  59. unsigned int primID;
  60. unsigned int timeStep;
  61. struct RTCBounds* bounds_o;
  62. };
  63. /* Bounding callback function */
  64. typedef void (*RTCBoundsFunction)(const struct RTCBoundsFunctionArguments* args);
  65. /* Arguments for RTCIntersectFunctionN */
  66. struct RTCIntersectFunctionNArguments
  67. {
  68. int* valid;
  69. void* geometryUserPtr;
  70. unsigned int primID;
  71. struct RTCRayQueryContext* context;
  72. struct RTCRayHitN* rayhit;
  73. unsigned int N;
  74. unsigned int geomID;
  75. };
  76. /* Arguments for RTCOccludedFunctionN */
  77. struct RTCOccludedFunctionNArguments
  78. {
  79. int* valid;
  80. void* geometryUserPtr;
  81. unsigned int primID;
  82. struct RTCRayQueryContext* context;
  83. struct RTCRayN* ray;
  84. unsigned int N;
  85. unsigned int geomID;
  86. };
  87. /* Arguments for RTCDisplacementFunctionN */
  88. struct RTCDisplacementFunctionNArguments
  89. {
  90. void* geometryUserPtr;
  91. RTCGeometry geometry;
  92. unsigned int primID;
  93. unsigned int timeStep;
  94. const float* u;
  95. const float* v;
  96. const float* Ng_x;
  97. const float* Ng_y;
  98. const float* Ng_z;
  99. float* P_x;
  100. float* P_y;
  101. float* P_z;
  102. unsigned int N;
  103. };
  104. /* Displacement mapping callback function */
  105. typedef void (*RTCDisplacementFunctionN)(const struct RTCDisplacementFunctionNArguments* args);
  106. /* Creates a new geometry of specified type. */
  107. RTC_API RTCGeometry rtcNewGeometry(RTCDevice device, enum RTCGeometryType type);
  108. /* Retains the geometry (increments the reference count). */
  109. RTC_API void rtcRetainGeometry(RTCGeometry geometry);
  110. /* Releases the geometry (decrements the reference count) */
  111. RTC_API void rtcReleaseGeometry(RTCGeometry geometry);
  112. /* Commits the geometry. */
  113. RTC_API void rtcCommitGeometry(RTCGeometry geometry);
  114. /* Enables the geometry. */
  115. RTC_API void rtcEnableGeometry(RTCGeometry geometry);
  116. /* Disables the geometry. */
  117. RTC_API void rtcDisableGeometry(RTCGeometry geometry);
  118. /* Sets the number of motion blur time steps of the geometry. */
  119. RTC_API void rtcSetGeometryTimeStepCount(RTCGeometry geometry, unsigned int timeStepCount);
  120. /* Sets the motion blur time range of the geometry. */
  121. RTC_API void rtcSetGeometryTimeRange(RTCGeometry geometry, float startTime, float endTime);
  122. /* Sets the number of vertex attributes of the geometry. */
  123. RTC_API void rtcSetGeometryVertexAttributeCount(RTCGeometry geometry, unsigned int vertexAttributeCount);
  124. /* Sets the ray mask of the geometry. */
  125. RTC_API void rtcSetGeometryMask(RTCGeometry geometry, unsigned int mask);
  126. /* Sets the build quality of the geometry. */
  127. RTC_API void rtcSetGeometryBuildQuality(RTCGeometry geometry, enum RTCBuildQuality quality);
  128. /* Sets the maximal curve or point radius scale allowed by min-width feature. */
  129. RTC_API void rtcSetGeometryMaxRadiusScale(RTCGeometry geometry, float maxRadiusScale);
  130. /* Sets a geometry buffer. */
  131. RTC_API void rtcSetGeometryBuffer(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot, enum RTCFormat format, RTCBuffer buffer, size_t byteOffset, size_t byteStride, size_t itemCount);
  132. /* Sets a shared geometry buffer. */
  133. RTC_API void rtcSetSharedGeometryBuffer(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot, enum RTCFormat format, const void* ptr, size_t byteOffset, size_t byteStride, size_t itemCount);
  134. /* Creates and sets a new geometry buffer. */
  135. RTC_API void* rtcSetNewGeometryBuffer(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot, enum RTCFormat format, size_t byteStride, size_t itemCount);
  136. /* Returns the pointer to the data of a buffer. */
  137. RTC_API void* rtcGetGeometryBufferData(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot);
  138. /* Updates a geometry buffer. */
  139. RTC_API void rtcUpdateGeometryBuffer(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot);
  140. /* Sets the intersection filter callback function of the geometry. */
  141. RTC_API void rtcSetGeometryIntersectFilterFunction(RTCGeometry geometry, RTCFilterFunctionN filter);
  142. /* Sets the occlusion filter callback function of the geometry. */
  143. RTC_API void rtcSetGeometryOccludedFilterFunction(RTCGeometry geometry, RTCFilterFunctionN filter);
  144. /* Enables argument version of intersection or occlusion filter function. */
  145. RTC_API void rtcSetGeometryEnableFilterFunctionFromArguments(RTCGeometry geometry, bool enable);
  146. /* Sets the user-defined data pointer of the geometry. */
  147. RTC_API void rtcSetGeometryUserData(RTCGeometry geometry, void* ptr);
  148. /* Gets the user-defined data pointer of the geometry. */
  149. RTC_API void* rtcGetGeometryUserData(RTCGeometry geometry);
  150. /* Set the point query callback function of a geometry. */
  151. RTC_API void rtcSetGeometryPointQueryFunction(RTCGeometry geometry, RTCPointQueryFunction pointQuery);
  152. /* Sets the number of primitives of a user geometry. */
  153. RTC_API void rtcSetGeometryUserPrimitiveCount(RTCGeometry geometry, unsigned int userPrimitiveCount);
  154. /* Sets the bounding callback function to calculate bounding boxes for user primitives. */
  155. RTC_API void rtcSetGeometryBoundsFunction(RTCGeometry geometry, RTCBoundsFunction bounds, void* userPtr);
  156. /* Set the intersect callback function of a user geometry. */
  157. RTC_API void rtcSetGeometryIntersectFunction(RTCGeometry geometry, RTCIntersectFunctionN intersect);
  158. /* Set the occlusion callback function of a user geometry. */
  159. RTC_API void rtcSetGeometryOccludedFunction(RTCGeometry geometry, RTCOccludedFunctionN occluded);
  160. /* Invokes the intersection filter from the intersection callback function. */
  161. RTC_SYCL_API void rtcInvokeIntersectFilterFromGeometry(const struct RTCIntersectFunctionNArguments* args, const struct RTCFilterFunctionNArguments* filterArgs);
  162. /* Invokes the occlusion filter from the occlusion callback function. */
  163. RTC_SYCL_API void rtcInvokeOccludedFilterFromGeometry(const struct RTCOccludedFunctionNArguments* args, const struct RTCFilterFunctionNArguments* filterArgs);
  164. /* Sets the instanced scene of an instance geometry. */
  165. RTC_API void rtcSetGeometryInstancedScene(RTCGeometry geometry, RTCScene scene);
  166. /* Sets the instanced scenes of an instance array geometry. */
  167. RTC_API void rtcSetGeometryInstancedScenes(RTCGeometry geometry, RTCScene* scenes, size_t numScenes);
  168. /* Sets the transformation of an instance for the specified time step. */
  169. RTC_API void rtcSetGeometryTransform(RTCGeometry geometry, unsigned int timeStep, enum RTCFormat format, const void* xfm);
  170. /* Sets the transformation quaternion of an instance for the specified time step. */
  171. RTC_API void rtcSetGeometryTransformQuaternion(RTCGeometry geometry, unsigned int timeStep, const struct RTCQuaternionDecomposition* qd);
  172. /* Returns the interpolated transformation of an instance for the specified time. */
  173. RTC_API void rtcGetGeometryTransform(RTCGeometry geometry, float time, enum RTCFormat format, void* xfm);
  174. /*
  175. * Returns the interpolated transformation of the instPrimID'th instance of an
  176. * instance array for the specified time. If geometry is an regular instance,
  177. * instPrimID must be 0.
  178. */
  179. RTC_API void rtcGetGeometryTransformEx(RTCGeometry geometry, unsigned int instPrimID, float time, enum RTCFormat format, void* xfm);
  180. /* Sets the uniform tessellation rate of the geometry. */
  181. RTC_API void rtcSetGeometryTessellationRate(RTCGeometry geometry, float tessellationRate);
  182. /* Sets the number of topologies of a subdivision surface. */
  183. RTC_API void rtcSetGeometryTopologyCount(RTCGeometry geometry, unsigned int topologyCount);
  184. /* Sets the subdivision interpolation mode. */
  185. RTC_API void rtcSetGeometrySubdivisionMode(RTCGeometry geometry, unsigned int topologyID, enum RTCSubdivisionMode mode);
  186. /* Binds a vertex attribute to a topology of the geometry. */
  187. RTC_API void rtcSetGeometryVertexAttributeTopology(RTCGeometry geometry, unsigned int vertexAttributeID, unsigned int topologyID);
  188. /* Sets the displacement callback function of a subdivision surface. */
  189. RTC_API void rtcSetGeometryDisplacementFunction(RTCGeometry geometry, RTCDisplacementFunctionN displacement);
  190. /* Returns the first half edge of a face. */
  191. RTC_API unsigned int rtcGetGeometryFirstHalfEdge(RTCGeometry geometry, unsigned int faceID);
  192. /* Returns the face the half edge belongs to. */
  193. RTC_API unsigned int rtcGetGeometryFace(RTCGeometry geometry, unsigned int edgeID);
  194. /* Returns next half edge. */
  195. RTC_API unsigned int rtcGetGeometryNextHalfEdge(RTCGeometry geometry, unsigned int edgeID);
  196. /* Returns previous half edge. */
  197. RTC_API unsigned int rtcGetGeometryPreviousHalfEdge(RTCGeometry geometry, unsigned int edgeID);
  198. /* Returns opposite half edge. */
  199. RTC_API unsigned int rtcGetGeometryOppositeHalfEdge(RTCGeometry geometry, unsigned int topologyID, unsigned int edgeID);
  200. /* Arguments for rtcInterpolate */
  201. struct RTCInterpolateArguments
  202. {
  203. RTCGeometry geometry;
  204. unsigned int primID;
  205. float u;
  206. float v;
  207. enum RTCBufferType bufferType;
  208. unsigned int bufferSlot;
  209. float* P;
  210. float* dPdu;
  211. float* dPdv;
  212. float* ddPdudu;
  213. float* ddPdvdv;
  214. float* ddPdudv;
  215. unsigned int valueCount;
  216. };
  217. /* Interpolates vertex data to some u/v location and optionally calculates all derivatives. */
  218. RTC_API void rtcInterpolate(const struct RTCInterpolateArguments* args);
  219. /* Interpolates vertex data to some u/v location. */
  220. RTC_FORCEINLINE void rtcInterpolate0(RTCGeometry geometry, unsigned int primID, float u, float v, enum RTCBufferType bufferType, unsigned int bufferSlot, float* P, unsigned int valueCount)
  221. {
  222. struct RTCInterpolateArguments args;
  223. args.geometry = geometry;
  224. args.primID = primID;
  225. args.u = u;
  226. args.v = v;
  227. args.bufferType = bufferType;
  228. args.bufferSlot = bufferSlot;
  229. args.P = P;
  230. args.dPdu = NULL;
  231. args.dPdv = NULL;
  232. args.ddPdudu = NULL;
  233. args.ddPdvdv = NULL;
  234. args.ddPdudv = NULL;
  235. args.valueCount = valueCount;
  236. rtcInterpolate(&args);
  237. }
  238. /* Interpolates vertex data to some u/v location and calculates first order derivatives. */
  239. RTC_FORCEINLINE void rtcInterpolate1(RTCGeometry geometry, unsigned int primID, float u, float v, enum RTCBufferType bufferType, unsigned int bufferSlot,
  240. float* P, float* dPdu, float* dPdv, unsigned int valueCount)
  241. {
  242. struct RTCInterpolateArguments args;
  243. args.geometry = geometry;
  244. args.primID = primID;
  245. args.u = u;
  246. args.v = v;
  247. args.bufferType = bufferType;
  248. args.bufferSlot = bufferSlot;
  249. args.P = P;
  250. args.dPdu = dPdu;
  251. args.dPdv = dPdv;
  252. args.ddPdudu = NULL;
  253. args.ddPdvdv = NULL;
  254. args.ddPdudv = NULL;
  255. args.valueCount = valueCount;
  256. rtcInterpolate(&args);
  257. }
  258. /* Interpolates vertex data to some u/v location and calculates first and second order derivatives. */
  259. RTC_FORCEINLINE void rtcInterpolate2(RTCGeometry geometry, unsigned int primID, float u, float v, enum RTCBufferType bufferType, unsigned int bufferSlot,
  260. float* P, float* dPdu, float* dPdv, float* ddPdudu, float* ddPdvdv, float* ddPdudv, unsigned int valueCount)
  261. {
  262. struct RTCInterpolateArguments args;
  263. args.geometry = geometry;
  264. args.primID = primID;
  265. args.u = u;
  266. args.v = v;
  267. args.bufferType = bufferType;
  268. args.bufferSlot = bufferSlot;
  269. args.P = P;
  270. args.dPdu = dPdu;
  271. args.dPdv = dPdv;
  272. args.ddPdudu = ddPdudu;
  273. args.ddPdvdv = ddPdvdv;
  274. args.ddPdudv = ddPdudv;
  275. args.valueCount = valueCount;
  276. rtcInterpolate(&args);
  277. }
  278. /* Arguments for rtcInterpolateN */
  279. struct RTCInterpolateNArguments
  280. {
  281. RTCGeometry geometry;
  282. const void* valid;
  283. const unsigned int* primIDs;
  284. const float* u;
  285. const float* v;
  286. unsigned int N;
  287. enum RTCBufferType bufferType;
  288. unsigned int bufferSlot;
  289. float* P;
  290. float* dPdu;
  291. float* dPdv;
  292. float* ddPdudu;
  293. float* ddPdvdv;
  294. float* ddPdudv;
  295. unsigned int valueCount;
  296. };
  297. /* Interpolates vertex data to an array of u/v locations. */
  298. RTC_API void rtcInterpolateN(const struct RTCInterpolateNArguments* args);
  299. /* RTCGrid primitive for grid mesh */
  300. struct RTCGrid
  301. {
  302. unsigned int startVertexID;
  303. unsigned int stride;
  304. unsigned short width,height; // max is a 32k x 32k grid
  305. };
  306. RTC_NAMESPACE_END