rtcore_geometry.h 14 KB

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