No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Bindings.hlsl 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef _UNIFIEDRAYTRACING_BINDINGS_HLSL_
  2. #define _UNIFIEDRAYTRACING_BINDINGS_HLSL_
  3. #if defined(UNIFIED_RT_BACKEND_COMPUTE)
  4. #define GROUP_SIZE (UNIFIED_RT_GROUP_SIZE_X*UNIFIED_RT_GROUP_SIZE_Y)
  5. #include "Packages/com.unity.rendering.light-transport/Runtime/UnifiedRayTracing/Compute/RadeonRays/kernels/trace_ray.hlsl"
  6. #endif
  7. namespace UnifiedRT {
  8. struct Ray
  9. {
  10. float3 origin;
  11. float tMin;
  12. float3 direction;
  13. float tMax;
  14. };
  15. struct Hit
  16. {
  17. uint instanceID;
  18. uint primitiveIndex;
  19. float2 uvBarycentrics;
  20. float hitDistance;
  21. bool isFrontFace;
  22. bool IsValid()
  23. {
  24. return instanceID != -1;
  25. }
  26. static Hit Invalid()
  27. {
  28. Hit hit;
  29. hit.instanceID = -1;
  30. return hit;
  31. }
  32. };
  33. struct InstanceData
  34. {
  35. float4x4 localToWorld;
  36. float4x4 previousLocalToWorld;
  37. float4x4 localToWorldNormals;
  38. uint userInstanceID;
  39. uint instanceMask;
  40. uint userMaterialID;
  41. uint geometryIndex;
  42. };
  43. struct DispatchInfo
  44. {
  45. uint3 dispatchThreadID;
  46. uint localThreadIndex;
  47. uint3 dispatchDimensionsInThreads;
  48. uint globalThreadIndex;
  49. };
  50. struct RayTracingAccelStruct
  51. {
  52. #if defined(UNIFIED_RT_BACKEND_HARDWARE)
  53. RaytracingAccelerationStructure accelStruct;
  54. #elif defined(UNIFIED_RT_BACKEND_COMPUTE)
  55. StructuredBuffer<BvhNode> bvh;
  56. StructuredBuffer<BvhNode> bottom_bvhs;
  57. StructuredBuffer<InstanceInfo> instance_infos;
  58. StructuredBuffer<uint> indexBuffer;
  59. StructuredBuffer<uint> vertexBuffer;
  60. int vertexStride;
  61. #else
  62. #pragma message("Error, you must define either UNIFIED_RT_BACKEND_HARDWARE or UNIFIED_RT_BACKEND_COMPUTE")
  63. #endif
  64. };
  65. #if defined(UNIFIED_RT_BACKEND_HARDWARE)
  66. RayTracingAccelStruct GetAccelStruct(RaytracingAccelerationStructure accelStruct)
  67. {
  68. RayTracingAccelStruct res;
  69. res.accelStruct = accelStruct;
  70. return res;
  71. }
  72. #define UNIFIED_RT_DECLARE_ACCEL_STRUCT(name) RaytracingAccelerationStructure name##accelStruct
  73. #define UNIFIED_RT_GET_ACCEL_STRUCT(name) UnifiedRT::GetAccelStruct(name##accelStruct)
  74. #elif defined(UNIFIED_RT_BACKEND_COMPUTE)
  75. RayTracingAccelStruct GetAccelStruct(
  76. StructuredBuffer<BvhNode> bvh,
  77. StructuredBuffer<BvhNode> bottomBvhs,
  78. StructuredBuffer<InstanceInfo> instanceInfos,
  79. StructuredBuffer<uint> indexBuffer,
  80. StructuredBuffer<uint> vertexBuffer,
  81. int vertexStride)
  82. {
  83. RayTracingAccelStruct res;
  84. res.bvh = bvh;
  85. res.bottom_bvhs = bottomBvhs;
  86. res.instance_infos = instanceInfos;
  87. res.indexBuffer = indexBuffer;
  88. res.vertexBuffer = vertexBuffer;
  89. res.vertexStride = vertexStride;
  90. return res;
  91. }
  92. #define UNIFIED_RT_DECLARE_ACCEL_STRUCT(name) StructuredBuffer<BvhNode> name##bvh; StructuredBuffer<BvhNode> name##bottomBvhs; StructuredBuffer<InstanceInfo> name##instanceInfos; StructuredBuffer<uint> name##indexBuffer; StructuredBuffer<uint> name##vertexBuffer; int name##vertexStride
  93. #define UNIFIED_RT_GET_ACCEL_STRUCT(name) UnifiedRT::GetAccelStruct(name##bvh, name##bottomBvhs, name##instanceInfos, name##indexBuffer, name##vertexBuffer, name##vertexStride)
  94. #endif
  95. } // namespace UnifiedRT
  96. #if defined(UNIFIED_RT_BACKEND_COMPUTE)
  97. RWStructuredBuffer<uint> g_stack;
  98. #endif
  99. #endif // UNIFIEDRAYTRACING_BINDINGS_HLSL