rtcore_geometry.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. };
  39. /* Interpolation modes for subdivision surfaces */
  40. enum RTCSubdivisionMode
  41. {
  42. RTC_SUBDIVISION_MODE_NO_BOUNDARY = 0,
  43. RTC_SUBDIVISION_MODE_SMOOTH_BOUNDARY = 1,
  44. RTC_SUBDIVISION_MODE_PIN_CORNERS = 2,
  45. RTC_SUBDIVISION_MODE_PIN_BOUNDARY = 3,
  46. RTC_SUBDIVISION_MODE_PIN_ALL = 4,
  47. };
  48. /* Curve segment flags */
  49. enum RTCCurveFlags
  50. {
  51. RTC_CURVE_FLAG_NEIGHBOR_LEFT = (1 << 0), // left segments exists
  52. RTC_CURVE_FLAG_NEIGHBOR_RIGHT = (1 << 1) // right segment exists
  53. };
  54. /* Arguments for RTCBoundsFunction */
  55. struct RTCBoundsFunctionArguments
  56. {
  57. void* geometryUserPtr;
  58. unsigned int primID;
  59. unsigned int timeStep;
  60. struct RTCBounds* bounds_o;
  61. };
  62. /* Bounding callback function */
  63. typedef void (*RTCBoundsFunction)(const struct RTCBoundsFunctionArguments* args);
  64. /* Arguments for RTCIntersectFunctionN */
  65. struct RTCIntersectFunctionNArguments
  66. {
  67. int* valid;
  68. void* geometryUserPtr;
  69. unsigned int primID;
  70. struct RTCIntersectContext* context;
  71. struct RTCRayHitN* rayhit;
  72. unsigned int N;
  73. unsigned int geomID;
  74. };
  75. /* Intersection callback function */
  76. typedef void (*RTCIntersectFunctionN)(const struct RTCIntersectFunctionNArguments* args);
  77. /* Arguments for RTCOccludedFunctionN */
  78. struct RTCOccludedFunctionNArguments
  79. {
  80. int* valid;
  81. void* geometryUserPtr;
  82. unsigned int primID;
  83. struct RTCIntersectContext* context;
  84. struct RTCRayN* ray;
  85. unsigned int N;
  86. unsigned int geomID;
  87. };
  88. /* Occlusion callback function */
  89. typedef void (*RTCOccludedFunctionN)(const struct RTCOccludedFunctionNArguments* args);
  90. /* Arguments for RTCDisplacementFunctionN */
  91. struct RTCDisplacementFunctionNArguments
  92. {
  93. void* geometryUserPtr;
  94. RTCGeometry geometry;
  95. unsigned int primID;
  96. unsigned int timeStep;
  97. const float* u;
  98. const float* v;
  99. const float* Ng_x;
  100. const float* Ng_y;
  101. const float* Ng_z;
  102. float* P_x;
  103. float* P_y;
  104. float* P_z;
  105. unsigned int N;
  106. };
  107. /* Displacement mapping callback function */
  108. typedef void (*RTCDisplacementFunctionN)(const struct RTCDisplacementFunctionNArguments* args);
  109. /* Creates a new geometry of specified type. */
  110. RTC_API RTCGeometry rtcNewGeometry(RTCDevice device, enum RTCGeometryType type);
  111. /* Retains the geometry (increments the reference count). */
  112. RTC_API void rtcRetainGeometry(RTCGeometry geometry);
  113. /* Releases the geometry (decrements the reference count) */
  114. RTC_API void rtcReleaseGeometry(RTCGeometry geometry);
  115. /* Commits the geometry. */
  116. RTC_API void rtcCommitGeometry(RTCGeometry geometry);
  117. /* Enables the geometry. */
  118. RTC_API void rtcEnableGeometry(RTCGeometry geometry);
  119. /* Disables the geometry. */
  120. RTC_API void rtcDisableGeometry(RTCGeometry geometry);
  121. /* Sets the number of motion blur time steps of the geometry. */
  122. RTC_API void rtcSetGeometryTimeStepCount(RTCGeometry geometry, unsigned int timeStepCount);
  123. /* Sets the motion blur time range of the geometry. */
  124. RTC_API void rtcSetGeometryTimeRange(RTCGeometry geometry, float startTime, float endTime);
  125. /* Sets the number of vertex attributes of the geometry. */
  126. RTC_API void rtcSetGeometryVertexAttributeCount(RTCGeometry geometry, unsigned int vertexAttributeCount);
  127. /* Sets the ray mask of the geometry. */
  128. RTC_API void rtcSetGeometryMask(RTCGeometry geometry, unsigned int mask);
  129. /* Sets the build quality of the geometry. */
  130. RTC_API void rtcSetGeometryBuildQuality(RTCGeometry geometry, enum RTCBuildQuality quality);
  131. /* Sets the maximal curve or point radius scale allowed by min-width feature. */
  132. RTC_API void rtcSetGeometryMaxRadiusScale(RTCGeometry geometry, float maxRadiusScale);
  133. /* Sets a geometry buffer. */
  134. 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);
  135. /* Sets a shared geometry buffer. */
  136. 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);
  137. /* Creates and sets a new geometry buffer. */
  138. RTC_API void* rtcSetNewGeometryBuffer(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot, enum RTCFormat format, size_t byteStride, size_t itemCount);
  139. /* Returns the pointer to the data of a buffer. */
  140. RTC_API void* rtcGetGeometryBufferData(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot);
  141. /* Updates a geometry buffer. */
  142. RTC_API void rtcUpdateGeometryBuffer(RTCGeometry geometry, enum RTCBufferType type, unsigned int slot);
  143. /* Sets the intersection filter callback function of the geometry. */
  144. RTC_API void rtcSetGeometryIntersectFilterFunction(RTCGeometry geometry, RTCFilterFunctionN filter);
  145. /* Sets the occlusion filter callback function of the geometry. */
  146. RTC_API void rtcSetGeometryOccludedFilterFunction(RTCGeometry geometry, RTCFilterFunctionN filter);
  147. /* Sets the user-defined data pointer of the geometry. */
  148. RTC_API void rtcSetGeometryUserData(RTCGeometry geometry, void* ptr);
  149. /* Gets the user-defined data pointer of the geometry. */
  150. RTC_API void* rtcGetGeometryUserData(RTCGeometry geometry);
  151. /* Set the point query callback function of a geometry. */
  152. RTC_API void rtcSetGeometryPointQueryFunction(RTCGeometry geometry, RTCPointQueryFunction pointQuery);
  153. /* Sets the number of primitives of a user geometry. */
  154. RTC_API void rtcSetGeometryUserPrimitiveCount(RTCGeometry geometry, unsigned int userPrimitiveCount);
  155. /* Sets the bounding callback function to calculate bounding boxes for user primitives. */
  156. RTC_API void rtcSetGeometryBoundsFunction(RTCGeometry geometry, RTCBoundsFunction bounds, void* userPtr);
  157. /* Set the intersect callback function of a user geometry. */
  158. RTC_API void rtcSetGeometryIntersectFunction(RTCGeometry geometry, RTCIntersectFunctionN intersect);
  159. /* Set the occlusion callback function of a user geometry. */
  160. RTC_API void rtcSetGeometryOccludedFunction(RTCGeometry geometry, RTCOccludedFunctionN occluded);
  161. /* Invokes the intersection filter from the intersection callback function. */
  162. RTC_API void rtcFilterIntersection(const struct RTCIntersectFunctionNArguments* args, const struct RTCFilterFunctionNArguments* filterArgs);
  163. /* Invokes the occlusion filter from the occlusion callback function. */
  164. RTC_API void rtcFilterOcclusion(const struct RTCOccludedFunctionNArguments* args, const struct RTCFilterFunctionNArguments* filterArgs);
  165. /* Sets the instanced scene of an instance geometry. */
  166. RTC_API void rtcSetGeometryInstancedScene(RTCGeometry geometry, RTCScene scene);
  167. /* Sets the transformation of an instance for the specified time step. */
  168. RTC_API void rtcSetGeometryTransform(RTCGeometry geometry, unsigned int timeStep, enum RTCFormat format, const void* xfm);
  169. /* Sets the transformation quaternion of an instance for the specified time step. */
  170. RTC_API void rtcSetGeometryTransformQuaternion(RTCGeometry geometry, unsigned int timeStep, const struct RTCQuaternionDecomposition* qd);
  171. /* Returns the interpolated transformation of an instance for the specified time. */
  172. RTC_API void rtcGetGeometryTransform(RTCGeometry geometry, float time, enum RTCFormat format, void* xfm);
  173. /* Sets the uniform tessellation rate of the geometry. */
  174. RTC_API void rtcSetGeometryTessellationRate(RTCGeometry geometry, float tessellationRate);
  175. /* Sets the number of topologies of a subdivision surface. */
  176. RTC_API void rtcSetGeometryTopologyCount(RTCGeometry geometry, unsigned int topologyCount);
  177. /* Sets the subdivision interpolation mode. */
  178. RTC_API void rtcSetGeometrySubdivisionMode(RTCGeometry geometry, unsigned int topologyID, enum RTCSubdivisionMode mode);
  179. /* Binds a vertex attribute to a topology of the geometry. */
  180. RTC_API void rtcSetGeometryVertexAttributeTopology(RTCGeometry geometry, unsigned int vertexAttributeID, unsigned int topologyID);
  181. /* Sets the displacement callback function of a subdivision surface. */
  182. RTC_API void rtcSetGeometryDisplacementFunction(RTCGeometry geometry, RTCDisplacementFunctionN displacement);
  183. /* Returns the first half edge of a face. */
  184. RTC_API unsigned int rtcGetGeometryFirstHalfEdge(RTCGeometry geometry, unsigned int faceID);
  185. /* Returns the face the half edge belongs to. */
  186. RTC_API unsigned int rtcGetGeometryFace(RTCGeometry geometry, unsigned int edgeID);
  187. /* Returns next half edge. */
  188. RTC_API unsigned int rtcGetGeometryNextHalfEdge(RTCGeometry geometry, unsigned int edgeID);
  189. /* Returns previous half edge. */
  190. RTC_API unsigned int rtcGetGeometryPreviousHalfEdge(RTCGeometry geometry, unsigned int edgeID);
  191. /* Returns opposite half edge. */
  192. RTC_API unsigned int rtcGetGeometryOppositeHalfEdge(RTCGeometry geometry, unsigned int topologyID, unsigned int edgeID);
  193. /* Arguments for rtcInterpolate */
  194. struct RTCInterpolateArguments
  195. {
  196. RTCGeometry geometry;
  197. unsigned int primID;
  198. float u;
  199. float v;
  200. enum RTCBufferType bufferType;
  201. unsigned int bufferSlot;
  202. float* P;
  203. float* dPdu;
  204. float* dPdv;
  205. float* ddPdudu;
  206. float* ddPdvdv;
  207. float* ddPdudv;
  208. unsigned int valueCount;
  209. };
  210. /* Interpolates vertex data to some u/v location and optionally calculates all derivatives. */
  211. RTC_API void rtcInterpolate(const struct RTCInterpolateArguments* args);
  212. /* Interpolates vertex data to some u/v location. */
  213. RTC_FORCEINLINE void rtcInterpolate0(RTCGeometry geometry, unsigned int primID, float u, float v, enum RTCBufferType bufferType, unsigned int bufferSlot, float* P, unsigned int valueCount)
  214. {
  215. struct RTCInterpolateArguments args;
  216. args.geometry = geometry;
  217. args.primID = primID;
  218. args.u = u;
  219. args.v = v;
  220. args.bufferType = bufferType;
  221. args.bufferSlot = bufferSlot;
  222. args.P = P;
  223. args.dPdu = NULL;
  224. args.dPdv = NULL;
  225. args.ddPdudu = NULL;
  226. args.ddPdvdv = NULL;
  227. args.ddPdudv = NULL;
  228. args.valueCount = valueCount;
  229. rtcInterpolate(&args);
  230. }
  231. /* Interpolates vertex data to some u/v location and calculates first order derivatives. */
  232. RTC_FORCEINLINE void rtcInterpolate1(RTCGeometry geometry, unsigned int primID, float u, float v, enum RTCBufferType bufferType, unsigned int bufferSlot,
  233. float* P, float* dPdu, float* dPdv, unsigned int valueCount)
  234. {
  235. struct RTCInterpolateArguments args;
  236. args.geometry = geometry;
  237. args.primID = primID;
  238. args.u = u;
  239. args.v = v;
  240. args.bufferType = bufferType;
  241. args.bufferSlot = bufferSlot;
  242. args.P = P;
  243. args.dPdu = dPdu;
  244. args.dPdv = dPdv;
  245. args.ddPdudu = NULL;
  246. args.ddPdvdv = NULL;
  247. args.ddPdudv = NULL;
  248. args.valueCount = valueCount;
  249. rtcInterpolate(&args);
  250. }
  251. /* Interpolates vertex data to some u/v location and calculates first and second order derivatives. */
  252. RTC_FORCEINLINE void rtcInterpolate2(RTCGeometry geometry, unsigned int primID, float u, float v, enum RTCBufferType bufferType, unsigned int bufferSlot,
  253. float* P, float* dPdu, float* dPdv, float* ddPdudu, float* ddPdvdv, float* ddPdudv, unsigned int valueCount)
  254. {
  255. struct RTCInterpolateArguments args;
  256. args.geometry = geometry;
  257. args.primID = primID;
  258. args.u = u;
  259. args.v = v;
  260. args.bufferType = bufferType;
  261. args.bufferSlot = bufferSlot;
  262. args.P = P;
  263. args.dPdu = dPdu;
  264. args.dPdv = dPdv;
  265. args.ddPdudu = ddPdudu;
  266. args.ddPdvdv = ddPdvdv;
  267. args.ddPdudv = ddPdudv;
  268. args.valueCount = valueCount;
  269. rtcInterpolate(&args);
  270. }
  271. /* Arguments for rtcInterpolateN */
  272. struct RTCInterpolateNArguments
  273. {
  274. RTCGeometry geometry;
  275. const void* valid;
  276. const unsigned int* primIDs;
  277. const float* u;
  278. const float* v;
  279. unsigned int N;
  280. enum RTCBufferType bufferType;
  281. unsigned int bufferSlot;
  282. float* P;
  283. float* dPdu;
  284. float* dPdv;
  285. float* ddPdudu;
  286. float* ddPdvdv;
  287. float* ddPdudv;
  288. unsigned int valueCount;
  289. };
  290. /* Interpolates vertex data to an array of u/v locations. */
  291. RTC_API void rtcInterpolateN(const struct RTCInterpolateNArguments* args);
  292. /* RTCGrid primitive for grid mesh */
  293. struct RTCGrid
  294. {
  295. unsigned int startVertexID;
  296. unsigned int stride;
  297. unsigned short width,height; // max is a 32k x 32k grid
  298. };
  299. RTC_NAMESPACE_END