Neslisah Torosdagli | 2fb45de | 2020-03-23 21:34:09 -0400 | [diff] [blame] | 1 | #version 460 |
| 2 | #extension GL_NV_ray_tracing : enable |
| 3 | #extension GL_EXT_ray_query : enable |
| 4 | |
| 5 | struct Ray |
| 6 | { |
| 7 | vec3 pos; |
| 8 | float tmin; |
| 9 | vec3 dir; |
| 10 | float tmax; |
| 11 | }; |
| 12 | |
| 13 | layout(std430, set = 0, binding = 0) buffer Log |
| 14 | { |
| 15 | uint x; |
| 16 | uint y; |
| 17 | }; |
| 18 | |
Neslisah Torosdagli | 915f119 | 2020-03-26 18:51:18 -0400 | [diff] [blame^] | 19 | layout(binding = 1, set = 0) uniform accelerationStructureEXT rtas; |
Neslisah Torosdagli | 2fb45de | 2020-03-23 21:34:09 -0400 | [diff] [blame] | 20 | layout(std430, set = 0, binding = 2) buffer Rays { Ray rays[]; }; |
| 21 | |
| 22 | void doSomething() |
| 23 | { |
| 24 | x = 0; |
| 25 | y = 0; |
| 26 | } |
| 27 | |
| 28 | uint launchIndex() |
| 29 | { |
| 30 | return gl_LaunchIDNV.z*gl_LaunchSizeNV.x*gl_LaunchSizeNV.y + gl_LaunchIDNV.y*gl_LaunchSizeNV.x + gl_LaunchIDNV.x; |
| 31 | } |
| 32 | |
| 33 | void main() |
| 34 | { |
| 35 | uint index = launchIndex(); |
| 36 | Ray ray = rays[index]; |
| 37 | rayQueryEXT rayQuery; |
| 38 | |
| 39 | bool committed_true = true; |
| 40 | bool committed_false = false; |
| 41 | |
Neslisah Torosdagli | 7f689be | 2020-03-23 23:09:44 -0400 | [diff] [blame] | 42 | rayQueryInitializeEXT(rayQuery, rtas, gl_RayFlagsOpaqueEXT, gl_RayFlagsCullBackFacingTrianglesEXT, ray.pos, ray.tmin, ray.dir, ray.tmax); |
Neslisah Torosdagli | 2fb45de | 2020-03-23 21:34:09 -0400 | [diff] [blame] | 43 | while (rayQueryProceedEXT(rayQuery)) |
| 44 | { |
| 45 | mat4x3 mat_o2w; |
| 46 | mat4x3 mat_w2o; |
| 47 | |
| 48 | uint candidateType = rayQueryGetIntersectionTypeEXT(rayQuery, committed_false); |
| 49 | if (candidateType == gl_RayQueryCandidateIntersectionTriangleEXT) |
| 50 | { |
| 51 | rayQueryTerminateEXT(rayQuery); |
| 52 | |
| 53 | mat_o2w = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, committed_false); |
| 54 | mat_w2o = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, committed_false); |
| 55 | |
| 56 | rayQueryConfirmIntersectionEXT(rayQuery); |
| 57 | |
| 58 | if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, committed_true)) |
| 59 | { |
| 60 | doSomething(); |
| 61 | } |
| 62 | if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, committed_true).x == 0) |
| 63 | { |
| 64 | doSomething(); |
| 65 | } |
| 66 | if (rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, committed_true) > 0) |
| 67 | { |
| 68 | doSomething(); |
| 69 | } |
| 70 | if (rayQueryGetIntersectionInstanceIdEXT(rayQuery, committed_true) > 0) |
| 71 | { |
| 72 | doSomething(); |
| 73 | } |
| 74 | if (rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, committed_true).x > 0) |
| 75 | { |
| 76 | doSomething(); |
| 77 | } |
| 78 | if (rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, committed_true).x > 0) |
| 79 | { |
| 80 | doSomething(); |
| 81 | } |
| 82 | if (rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, committed_true) > 0) |
| 83 | { |
| 84 | doSomething(); |
| 85 | } |
| 86 | if (rayQueryGetIntersectionTEXT(rayQuery, committed_true) > 0.f) |
| 87 | { |
| 88 | doSomething(); |
| 89 | } |
| 90 | if (rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQuery, committed_true) > 0) |
| 91 | { |
| 92 | doSomething(); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | uint committedStatus = rayQueryGetIntersectionTypeEXT(rayQuery, committed_true); |
| 98 | if (committedStatus == gl_RayQueryCommittedIntersectionGeneratedEXT) |
| 99 | { |
| 100 | if (rayQueryGetIntersectionGeometryIndexEXT(rayQuery, committed_true) > 0) |
| 101 | { |
| 102 | doSomething(); |
| 103 | } |
| 104 | } |
| 105 | } |