|
| 1 | + |
| 2 | +//TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -use-dxil -profile sm_6_5 -render-feature ray-query |
| 3 | +//TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query |
| 4 | + |
| 5 | +//TEST_INPUT: set scene = AccelerationStructure |
| 6 | +uniform RaytracingAccelerationStructure scene; |
| 7 | + |
| 8 | +struct Ray |
| 9 | +{ |
| 10 | + float3 origin; |
| 11 | + float tMin; |
| 12 | + float3 dir; |
| 13 | + float tMax; |
| 14 | + |
| 15 | + /** |
| 16 | + * Initializes a ray. |
| 17 | + */ |
| 18 | + __init(float3 origin, float3 dir, float tMin = 0.f, float tMax = 10000.0) |
| 19 | + { |
| 20 | + this.origin = origin; |
| 21 | + this.dir = dir; |
| 22 | + this.tMin = tMin; |
| 23 | + this.tMax = tMax; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Convert to DXR RayDesc. |
| 28 | + */ |
| 29 | + RayDesc toRayDesc() { return { origin, tMin, dir, tMax }; } |
| 30 | + |
| 31 | + /** |
| 32 | + * Evaluate position on the ray. |
| 33 | + * @param[in] t Ray parameter. |
| 34 | + * @return Returns evaluated position. |
| 35 | + */ |
| 36 | + float3 eval(float t) { return origin + t * dir; } |
| 37 | +}; |
| 38 | + |
| 39 | +RaytracingAccelerationStructure sceneBVH; |
| 40 | + |
| 41 | +// TODO: remove force inline here will result in an error. |
| 42 | +[ForceInline] |
| 43 | +bool traceSceneVisibilityRayImpl<let Flags : int>(const bool useAlphaTest, inout RayQuery<Flags> q, const Ray ray, uint rayFlags, uint instanceInclusionMask) |
| 44 | +{ |
| 45 | + var rayDesc = ray.toRayDesc(); |
| 46 | + q.TraceRayInline( |
| 47 | + scene, |
| 48 | + rayFlags, |
| 49 | + 0xff, |
| 50 | + rayDesc); |
| 51 | + q.Proceed(); |
| 52 | + if (q.CommittedStatus() == COMMITTED_TRIANGLE_HIT) |
| 53 | + { |
| 54 | + q.CommittedRayT(); |
| 55 | + return true; |
| 56 | + } |
| 57 | + return false; |
| 58 | +} |
| 59 | + |
| 60 | +bool traceSceneVisibilityRay<let UseAlphaTest : int>(const Ray ray, uint rayFlags, uint instanceInclusionMask) |
| 61 | +{ |
| 62 | + RayQuery rayQuery; |
| 63 | + return traceSceneVisibilityRayImpl(false, rayQuery, ray, rayFlags, instanceInclusionMask); |
| 64 | +} |
| 65 | + |
| 66 | +//TEST_INPUT:set outputBuffer = out ubuffer(data=[0], stride=4) |
| 67 | +RWStructuredBuffer<float> outputBuffer; |
| 68 | + |
| 69 | +[shader("compute")] |
| 70 | +[numthreads(1, 1, 1)] |
| 71 | +void computeMain( |
| 72 | + uint3 threadIdx: SV_DispatchThreadID) |
| 73 | +{ |
| 74 | + Ray ray = Ray(float3(0.1, 0.1, 0.0), float3(0, 0, 1), 0.1); |
| 75 | + if (traceSceneVisibilityRay<0>(ray, 0, 0xffff)) |
| 76 | + outputBuffer[threadIdx.x] = 1.0; |
| 77 | +} |
0 commit comments