|
| 1 | +struct RayDesc_ { |
| 2 | + uint flags; |
| 3 | + uint cull_mask; |
| 4 | + float tmin; |
| 5 | + float tmax; |
| 6 | + float3 origin; |
| 7 | + int _pad5_0; |
| 8 | + float3 dir; |
| 9 | + int _end_pad_0; |
| 10 | +}; |
| 11 | + |
| 12 | +struct RayIntersection { |
| 13 | + uint kind; |
| 14 | + float t; |
| 15 | + uint instance_custom_data; |
| 16 | + uint instance_index; |
| 17 | + uint sbt_record_offset; |
| 18 | + uint geometry_index; |
| 19 | + uint primitive_index; |
| 20 | + float2 barycentrics; |
| 21 | + bool front_face; |
| 22 | + int _pad9_0; |
| 23 | + int _pad9_1; |
| 24 | + row_major float4x3 object_to_world; |
| 25 | + int _pad10_0; |
| 26 | + row_major float4x3 world_to_object; |
| 27 | + int _end_pad_0; |
| 28 | +}; |
| 29 | + |
| 30 | +RayDesc RayDescFromRayDesc_(RayDesc_ arg0) { |
| 31 | + RayDesc ret = (RayDesc)0; |
| 32 | + ret.Origin = arg0.origin; |
| 33 | + ret.TMin = arg0.tmin; |
| 34 | + ret.Direction = arg0.dir; |
| 35 | + ret.TMax = arg0.tmax; |
| 36 | + return ret; |
| 37 | +} |
| 38 | + |
| 39 | +RaytracingAccelerationStructure acc_struct : register(t0); |
| 40 | + |
| 41 | +RayDesc_ ConstructRayDesc_(uint arg0, uint arg1, float arg2, float arg3, float3 arg4, float3 arg5) { |
| 42 | + RayDesc_ ret = (RayDesc_)0; |
| 43 | + ret.flags = arg0; |
| 44 | + ret.cull_mask = arg1; |
| 45 | + ret.tmin = arg2; |
| 46 | + ret.tmax = arg3; |
| 47 | + ret.origin = arg4; |
| 48 | + ret.dir = arg5; |
| 49 | + return ret; |
| 50 | +} |
| 51 | + |
| 52 | +RayIntersection GetCandidateIntersection(RayQuery<RAY_FLAG_NONE> rq) { |
| 53 | + RayIntersection ret = (RayIntersection)0; |
| 54 | + CANDIDATE_TYPE kind = rq.CandidateType(); |
| 55 | + if (kind == CANDIDATE_NON_OPAQUE_TRIANGLE) { |
| 56 | + ret.kind = 1; |
| 57 | + ret.t = rq.CandidateTriangleRayT(); |
| 58 | + ret.barycentrics = rq.CandidateTriangleBarycentrics(); |
| 59 | + ret.front_face = rq.CandidateTriangleFrontFace(); |
| 60 | + } else { |
| 61 | + ret.kind = 3; |
| 62 | + } |
| 63 | + ret.instance_custom_data = rq.CandidateInstanceID(); |
| 64 | + ret.instance_index = rq.CandidateInstanceIndex(); |
| 65 | + ret.sbt_record_offset = rq.CandidateInstanceContributionToHitGroupIndex(); |
| 66 | + ret.geometry_index = rq.CandidateGeometryIndex(); |
| 67 | + ret.primitive_index = rq.CandidatePrimitiveIndex(); |
| 68 | + ret.object_to_world = rq.CandidateObjectToWorld4x3(); |
| 69 | + ret.world_to_object = rq.CandidateWorldToObject4x3(); |
| 70 | + return ret; |
| 71 | +} |
| 72 | + |
| 73 | +[numthreads(1, 1, 1)] |
| 74 | +void main_candidate() |
| 75 | +{ |
| 76 | + RayQuery<RAY_FLAG_NONE> rq_1; |
| 77 | + |
| 78 | + float3 pos = (0.0).xxx; |
| 79 | + float3 dir = float3(0.0, 1.0, 0.0); |
| 80 | + rq_1.TraceRayInline(acc_struct, ConstructRayDesc_(4u, 255u, 0.1, 100.0, pos, dir).flags, ConstructRayDesc_(4u, 255u, 0.1, 100.0, pos, dir).cull_mask, RayDescFromRayDesc_(ConstructRayDesc_(4u, 255u, 0.1, 100.0, pos, dir))); |
| 81 | + RayIntersection intersection = GetCandidateIntersection(rq_1); |
| 82 | + if ((intersection.kind == 3u)) { |
| 83 | + rq_1.CommitProceduralPrimitiveHit(10.0); |
| 84 | + return; |
| 85 | + } else { |
| 86 | + if ((intersection.kind == 1u)) { |
| 87 | + rq_1.CommitNonOpaqueTriangleHit(); |
| 88 | + return; |
| 89 | + } else { |
| 90 | + rq_1.Abort(); |
| 91 | + return; |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments