Brak opisu
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.

TraceRaysAndFetchAttributes.hlsl 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "Packages/com.unity.rendering.light-transport/Runtime/UnifiedRayTracing/FetchGeometry.hlsl"
  2. #include "Packages/com.unity.rendering.light-transport/Runtime/UnifiedRayTracing/TraceRay.hlsl"
  3. UNIFIED_RT_DECLARE_ACCEL_STRUCT(_AccelStruct);
  4. struct RayWithFlags
  5. {
  6. float3 origin;
  7. float tMin;
  8. float3 direction;
  9. float tMax;
  10. uint culling;
  11. uint instanceMask;
  12. uint padding;
  13. uint padding2;
  14. };
  15. StructuredBuffer<RayWithFlags> _Rays;
  16. RWStructuredBuffer<UnifiedRT::Hit> _Hits;
  17. RWStructuredBuffer<UnifiedRT::HitGeomAttributes> _HitAttributes;
  18. void RayGenExecute(UnifiedRT::DispatchInfo dispatchInfo)
  19. {
  20. RayWithFlags rayWithFlags = _Rays[dispatchInfo.globalThreadIndex];
  21. UnifiedRT::Ray ray;
  22. ray.origin = rayWithFlags.origin;
  23. ray.direction = rayWithFlags.direction;
  24. ray.tMin = rayWithFlags.tMin;
  25. ray.tMax = rayWithFlags.tMax;
  26. UnifiedRT::RayTracingAccelStruct accelStruct = UNIFIED_RT_GET_ACCEL_STRUCT(_AccelStruct);
  27. UnifiedRT::Hit hitResult = UnifiedRT::TraceRayClosestHit(dispatchInfo, accelStruct, rayWithFlags.instanceMask, ray, rayWithFlags.culling);
  28. if (hitResult.IsValid())
  29. {
  30. UnifiedRT::HitGeomAttributes hitAttribs = UnifiedRT::FetchHitGeomAttributes(hitResult);
  31. _HitAttributes[dispatchInfo.globalThreadIndex] = hitAttribs;
  32. }
  33. else
  34. {
  35. _HitAttributes[dispatchInfo.globalThreadIndex] = (UnifiedRT::HitGeomAttributes)0;
  36. }
  37. _Hits[dispatchInfo.globalThreadIndex] = hitResult;
  38. }