rtcore_geometry.isph 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. #ifndef __EMBREE_GEOMETRY_ISPH__
  17. #define __EMBREE_GEOMETRY_ISPH__
  18. #include "rtcore_buffer.isph"
  19. /* Opaque scene type */
  20. typedef uniform struct RTCSceneTy* uniform RTCScene;
  21. /* Opaque geometry type */
  22. typedef uniform struct RTCGeometryTy* uniform 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* uniform geometryUserPtr;
  65. uniform unsigned int primID;
  66. uniform unsigned int timeStep;
  67. uniform RTCBounds* uniform bounds_o;
  68. };
  69. /* Bounding callback function */
  70. typedef unmasked void (*RTCBoundsFunction)(const struct RTCBoundsFunctionArguments* uniform args);
  71. /* Arguments for RTCIntersectFunctionN */
  72. struct RTCIntersectFunctionNArguments
  73. {
  74. uniform int* uniform valid;
  75. void* uniform geometryUserPtr;
  76. uniform unsigned int primID;
  77. uniform RTCIntersectContext* uniform context;
  78. RTCRayHitN* uniform rayhit;
  79. uniform unsigned int N;
  80. };
  81. /* Intersection callback function */
  82. typedef unmasked void (*RTCIntersectFunctionN)(const struct RTCIntersectFunctionNArguments* uniform args);
  83. /* Arguments for RTCOccludedFunctionN */
  84. struct RTCOccludedFunctionNArguments
  85. {
  86. uniform int* uniform valid;
  87. void* uniform geometryUserPtr;
  88. uniform unsigned int primID;
  89. uniform RTCIntersectContext* uniform context;
  90. RTCRayN* uniform ray;
  91. uniform unsigned int N;
  92. };
  93. /* Occlusion callback function */
  94. typedef unmasked void (*RTCOccludedFunctionN)(const struct RTCOccludedFunctionNArguments* uniform args);
  95. /* Arguments for RTCDisplacementFunctionN */
  96. struct RTCDisplacementFunctionNArguments
  97. {
  98. void* uniform geometryUserPtr;
  99. RTCGeometry geometry;
  100. uniform unsigned int primID;
  101. uniform unsigned int timeStep;
  102. uniform const float* uniform u;
  103. uniform const float* uniform v;
  104. uniform const float* uniform Ng_x;
  105. uniform const float* uniform Ng_y;
  106. uniform const float* uniform Ng_z;
  107. uniform float* uniform P_x;
  108. uniform float* uniform P_y;
  109. uniform float* uniform P_z;
  110. uniform unsigned int N;
  111. };
  112. /* Displacement mapping callback function */
  113. typedef unmasked void (*RTCDisplacementFunctionN)(const struct RTCDisplacementFunctionNArguments* uniform args);
  114. /* Creates a new geometry of specified type. */
  115. RTC_API RTCGeometry rtcNewGeometry(RTCDevice device, uniform 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, uniform unsigned int timeStepCount);
  128. /* Sets the motion blur time range of the geometry. */
  129. RTC_API void rtcSetGeometryTimeRange(RTCGeometry geometry, uniform float startTime, uniform float endTime);
  130. /* Sets the number of vertex attributes of the geometry. */
  131. RTC_API void rtcSetGeometryVertexAttributeCount(RTCGeometry geometry, uniform unsigned int vertexAttributeCount);
  132. /* Sets the ray mask of the geometry. */
  133. RTC_API void rtcSetGeometryMask(RTCGeometry geometry, uniform unsigned int mask);
  134. /* Sets the build quality of the geometry. */
  135. RTC_API void rtcSetGeometryBuildQuality(RTCGeometry geometry, uniform RTCBuildQuality quality);
  136. /* Sets a geometry buffer. */
  137. RTC_API void rtcSetGeometryBuffer(RTCGeometry geometry, uniform RTCBufferType type, uniform unsigned int slot, uniform RTCFormat format, uniform RTCBuffer buffer, uniform uintptr_t byteOffset, uniform uintptr_t byteStride, uniform uintptr_t itemCount);
  138. /* Sets a shared geometry buffer. */
  139. RTC_API void rtcSetSharedGeometryBuffer(RTCGeometry geometry, uniform RTCBufferType type, uniform unsigned int slot, uniform RTCFormat format, const void* uniform ptr, uniform uintptr_t byteOffset, uniform uintptr_t byteStride, uniform uintptr_t itemCount);
  140. /* Creates and sets a new geometry buffer. */
  141. RTC_API void* uniform rtcSetNewGeometryBuffer(RTCGeometry geometry, uniform RTCBufferType type, uniform unsigned int slot, uniform RTCFormat format, uniform uintptr_t byteStride, uniform uintptr_t itemCount);
  142. /* Returns the pointer to the data of a buffer. */
  143. RTC_API void* uniform rtcGetGeometryBufferData(RTCGeometry geometry, uniform RTCBufferType type, uniform unsigned int slot);
  144. /* Updates a geometry buffer. */
  145. RTC_API void rtcUpdateGeometryBuffer(RTCGeometry geometry, uniform RTCBufferType type, uniform unsigned int slot);
  146. /* Sets the intersection filter callback function of the geometry. */
  147. RTC_API void rtcSetGeometryIntersectFilterFunction(RTCGeometry geometry, uniform RTCFilterFunctionN filter);
  148. /* Sets the occlusion filter callback function of the geometry. */
  149. RTC_API void rtcSetGeometryOccludedFilterFunction(RTCGeometry geometry, uniform RTCFilterFunctionN filter);
  150. /* Sets the user-defined data pointer of the geometry. */
  151. RTC_API void rtcSetGeometryUserData(RTCGeometry geometry, void* uniform ptr);
  152. /* Gets the user-defined data pointer of the geometry. */
  153. RTC_API void* uniform rtcGetGeometryUserData(RTCGeometry geometry);
  154. /* Sets the number of primitives of a user geometry. */
  155. RTC_API void rtcSetGeometryUserPrimitiveCount(RTCGeometry geometry, uniform unsigned int userPrimitiveCount);
  156. /* Sets the bounding callback function to calculate bounding boxes for user primitives. */
  157. RTC_API void rtcSetGeometryBoundsFunction(RTCGeometry geometry, uniform RTCBoundsFunction bounds, void* uniform userPtr);
  158. /* Set the intersect callback function of a user geometry. */
  159. RTC_API void rtcSetGeometryIntersectFunction(RTCGeometry geometry, uniform RTCIntersectFunctionN intersect);
  160. /* Set the occlusion callback function of a user geometry. */
  161. RTC_API void rtcSetGeometryOccludedFunction(RTCGeometry geometry, uniform RTCOccludedFunctionN occluded);
  162. /* Invokes the intersection filter from the intersection callback function. */
  163. RTC_API void rtcFilterIntersection(const uniform struct RTCIntersectFunctionNArguments* uniform args, const uniform RTCFilterFunctionNArguments* uniform filterArgs);
  164. /* Invokes the occlusion filter from the occlusion callback function. */
  165. RTC_API void rtcFilterOcclusion(const uniform struct RTCOccludedFunctionNArguments* uniform args, const uniform RTCFilterFunctionNArguments* uniform 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, uniform unsigned int timeStep, uniform RTCFormat format, const void* uniform xfm);
  170. /* Returns the interpolated transformation of an instance for the specified time. */
  171. RTC_API void rtcGetGeometryTransform(RTCGeometry geometry, uniform float time, uniform RTCFormat format, void* uniform xfm);
  172. /* Sets the uniform tessellation rate of the geometry. */
  173. RTC_API void rtcSetGeometryTessellationRate(RTCGeometry geometry, uniform float tessellationRate);
  174. /* Sets the number of topologies of a subdivision surface. */
  175. RTC_API void rtcSetGeometryTopologyCount(RTCGeometry geometry, uniform unsigned int topologyCount);
  176. /* Sets the subdivision interpolation mode. */
  177. RTC_API void rtcSetGeometrySubdivisionMode(RTCGeometry geometry, uniform unsigned int topologyID, uniform RTCSubdivisionMode mode);
  178. /* Binds a vertex attribute to a topology of the geometry. */
  179. RTC_API void rtcSetGeometryVertexAttributeTopology(RTCGeometry geometry, uniform unsigned int vertexAttributeID, uniform unsigned int topologyID);
  180. /* Sets the displacement callback function of a subdivision surface. */
  181. RTC_API void rtcSetGeometryDisplacementFunction(RTCGeometry geometry, uniform RTCDisplacementFunctionN displacement);
  182. /* Returns the first half edge of a face. */
  183. RTC_API uniform unsigned int rtcGetGeometryFirstHalfEdge(RTCGeometry geometry, uniform unsigned int faceID);
  184. /* Returns the face the half edge belongs to. */
  185. RTC_API uniform unsigned int rtcGetGeometryFace(RTCGeometry geometry, uniform unsigned int edgeID);
  186. /* Returns next half edge. */
  187. RTC_API uniform unsigned int rtcGetGeometryNextHalfEdge(RTCGeometry geometry, uniform unsigned int edgeID);
  188. /* Returns previous half edge. */
  189. RTC_API uniform unsigned int rtcGetGeometryPreviousHalfEdge(RTCGeometry geometry, uniform unsigned int edgeID);
  190. /* Returns opposite half edge. */
  191. RTC_API uniform unsigned int rtcGetGeometryOppositeHalfEdge(RTCGeometry geometry, uniform unsigned int topologyID, uniform 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. 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 RTCInterpolateArguments* uniform args);
  211. /* Arguments for rtcInterpolateN */
  212. struct RTCInterpolateNArguments
  213. {
  214. RTCGeometry geometry;
  215. const void* valid;
  216. const unsigned int* primIDs;
  217. const float* u;
  218. const float* v;
  219. unsigned int N;
  220. RTCBufferType bufferType;
  221. unsigned int bufferSlot;
  222. float* P;
  223. float* dPdu;
  224. float* dPdv;
  225. float* ddPdudu;
  226. float* ddPdvdv;
  227. float* ddPdudv;
  228. unsigned int valueCount;
  229. };
  230. /* Interpolates vertex data to an array of u/v locations and calculates all derivatives. */
  231. RTC_API void rtcInterpolateN(const RTCInterpolateNArguments* uniform args);
  232. /* Interpolates vertex data to an array of u/v locations. */
  233. RTC_FORCEINLINE void rtcInterpolateV0(RTCGeometry geometry, varying unsigned int primID, varying float u, varying float v,
  234. uniform RTCBufferType bufferType, uniform unsigned int bufferSlot,
  235. varying float* uniform P,
  236. uniform unsigned int valueCount)
  237. {
  238. varying bool mask = __mask;
  239. unmasked {
  240. varying int imask = mask ? -1 : 0;
  241. }
  242. uniform RTCInterpolateNArguments args;
  243. args.geometry = geometry;
  244. args.valid = (const void* uniform)&imask;
  245. args.primIDs = (const uniform unsigned int* uniform)&primID;
  246. args.u = (const uniform float* uniform)&u;
  247. args.v = (const uniform float* uniform)&v;
  248. args.N = sizeof(varying float)/4;
  249. args.bufferType = bufferType;
  250. args.bufferSlot = bufferSlot;
  251. args.P = (uniform float* uniform)P;
  252. args.dPdu = NULL;
  253. args.dPdv = NULL;
  254. args.ddPdudu = NULL;
  255. args.ddPdvdv = NULL;
  256. args.ddPdudv = NULL;
  257. args.valueCount = valueCount;
  258. rtcInterpolateN(&args);
  259. }
  260. /* Interpolates vertex data to an array of u/v locations and calculates first order derivatives. */
  261. RTC_FORCEINLINE void rtcInterpolateV1(RTCGeometry geometry, varying unsigned int primID, varying float u, varying float v,
  262. uniform RTCBufferType bufferType, uniform unsigned int bufferSlot,
  263. varying float* uniform P, varying float* uniform dPdu, varying float* uniform dPdv,
  264. uniform unsigned int valueCount)
  265. {
  266. varying bool mask = __mask;
  267. unmasked {
  268. varying int imask = mask ? -1 : 0;
  269. }
  270. uniform RTCInterpolateNArguments args;
  271. args.geometry = geometry;
  272. args.valid = (const void* uniform)&imask;
  273. args.primIDs = (const uniform unsigned int* uniform)&primID;
  274. args.u = (const uniform float* uniform)&u;
  275. args.v = (const uniform float* uniform)&v;
  276. args.N = sizeof(varying float)/4;
  277. args.bufferType = bufferType;
  278. args.bufferSlot = bufferSlot;
  279. args.P = (uniform float* uniform)P;
  280. args.dPdu = (uniform float* uniform)dPdu;
  281. args.dPdv = (uniform float* uniform)dPdv;
  282. args.ddPdudu = NULL;
  283. args.ddPdvdv = NULL;
  284. args.ddPdudv = NULL;
  285. args.valueCount = valueCount;
  286. rtcInterpolateN(&args);
  287. }
  288. /* Interpolates vertex data to an array of u/v locations and calculates first and second order derivatives. */
  289. RTC_FORCEINLINE void rtcInterpolateV2(RTCGeometry geometry, varying unsigned int primID, varying float u, varying float v,
  290. uniform RTCBufferType bufferType, uniform unsigned int bufferSlot,
  291. varying float* uniform P, varying float* uniform dPdu, varying float* uniform dPdv,
  292. varying float* uniform ddPdudu, varying float* uniform ddPdvdv, varying float* uniform ddPdudv,
  293. uniform unsigned int valueCount)
  294. {
  295. varying bool mask = __mask;
  296. unmasked {
  297. varying int imask = mask ? -1 : 0;
  298. }
  299. uniform RTCInterpolateNArguments args;
  300. args.geometry = geometry;
  301. args.valid = (const void* uniform)&imask;
  302. args.primIDs = (const uniform unsigned int* uniform)&primID;
  303. args.u = (const uniform float* uniform)&u;
  304. args.v = (const uniform float* uniform)&v;
  305. args.N = sizeof(varying float)/4;
  306. args.bufferType = bufferType;
  307. args.bufferSlot = bufferSlot;
  308. args.P = (uniform float* uniform)P;
  309. args.dPdu = (uniform float* uniform)dPdu;
  310. args.dPdv = (uniform float* uniform)dPdv;
  311. args.ddPdudu = (uniform float* uniform)ddPdudu;
  312. args.ddPdvdv = (uniform float* uniform)ddPdvdv;
  313. args.ddPdudv = (uniform float* uniform)ddPdudv;
  314. args.valueCount = valueCount;
  315. rtcInterpolateN(&args);
  316. }
  317. /* RTCGrid primitive for grid mesh */
  318. struct RTCGrid
  319. {
  320. unsigned int startVertexID;
  321. unsigned int stride;
  322. int16 width,height; // max is a 32k x 32k grid
  323. };
  324. #endif