1#version 460 2#extension GL_NV_ray_tracing : enable 3#extension GL_EXT_ray_query : enable 4 5struct Ray 6{ 7 vec3 pos; 8 float tmin; 9 vec3 dir; 10 float tmax; 11}; 12 13layout(std430, set = 0, binding = 0) buffer Log 14{ 15 uint x; 16 uint y; 17}; 18 19layout(binding = 1, set = 0) uniform accelerationStructureEXT rtas; 20layout(std430, set = 0, binding = 2) buffer Rays { Ray rays[]; }; 21 22void doSomething() 23{ 24 x = 0; 25 y = 0; 26} 27 28Ray makeRayDesc() 29{ 30 Ray ray; 31 ray.pos= vec3(0,0,0); 32 ray.dir = vec3(1,0,0); 33 ray.tmin = 0.0f; 34 ray.tmax = 9999.0; 35 return ray; 36} 37 38void main() 39{ 40 Ray ray = makeRayDesc(); 41 rayQueryEXT rayQuery; 42 rayQueryInitializeEXT(rayQuery, rtas, gl_RayFlagsNoneEXT, 0xFF, ray.pos, ray.tmin, ray.dir, ray.tmax); 43 44 mat4x3 _mat4x3; 45 mat3x4 _mat3x4; 46 47 while (rayQueryProceedEXT(rayQuery)) 48 { 49 uint candidateType = rayQueryGetIntersectionTypeEXT(rayQuery, false); 50 switch(candidateType) 51 { 52 case gl_RayQueryCandidateIntersectionTriangleEXT: 53 54 rayQueryTerminateEXT(rayQuery); 55 _mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false); 56 _mat3x4 = transpose(_mat4x3); 57 rayQueryConfirmIntersectionEXT(rayQuery); 58 59 if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true)) 60 { 61 doSomething(); 62 } 63 64 if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).x == 0) 65 { 66 doSomething(); 67 } 68 69 if (rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0) 70 { 71 doSomething(); 72 } 73 74 if (rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0) 75 { 76 doSomething(); 77 } 78 79 if (rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).x > 0) 80 { 81 doSomething(); 82 } 83 84 if (rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0) 85 { 86 doSomething(); 87 } 88 89 if (rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0) 90 { 91 doSomething(); 92 } 93 94 if (rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f) 95 { 96 doSomething(); 97 } 98 99 if (rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQuery, true) > 0) 100 { 101 doSomething(); 102 } 103 break; 104 105 case gl_RayQueryCandidateIntersectionAABBEXT: 106 { 107 _mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false); 108 _mat3x4 = transpose(_mat4x3); 109 if (rayQueryGetIntersectionCandidateAABBOpaqueEXT(rayQuery)) 110 { 111 doSomething(); 112 } 113 114 float t = 0.5; 115 rayQueryGenerateIntersectionEXT(rayQuery, t); 116 rayQueryTerminateEXT(rayQuery); 117 break; 118 } 119 } 120 } 121 122 if(_mat3x4[0][0] == _mat4x3[0][0]) 123 { 124 doSomething(); 125 } 126 127 uint committedStatus = rayQueryGetIntersectionTypeEXT(rayQuery, true); 128 129 switch(committedStatus) 130 { 131 case gl_RayQueryCommittedIntersectionNoneEXT : 132 _mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, false); 133 _mat3x4 = transpose(_mat4x3); 134 break; 135 136 case gl_RayQueryCommittedIntersectionTriangleEXT : 137 _mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, true); 138 _mat3x4 = transpose(_mat4x3); 139 140 if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true)) 141 { 142 doSomething(); 143 } 144 145 if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).y == 0) 146 { 147 doSomething(); 148 } 149 break; 150 151 case gl_RayQueryCommittedIntersectionGeneratedEXT : 152 153 if(rayQueryGetIntersectionGeometryIndexEXT(rayQuery, true) > 0) 154 { 155 doSomething(); 156 } 157 158 if(rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0) 159 { 160 doSomething(); 161 } 162 163 if(rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0) 164 { 165 doSomething(); 166 } 167 168 if(rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).z > 0) 169 { 170 doSomething(); 171 } 172 173 if(rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0) 174 { 175 doSomething(); 176 } 177 178 if(rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0) 179 { 180 doSomething(); 181 } 182 183 if(rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f) 184 { 185 doSomething(); 186 } 187 break; 188 } 189 190 if (_mat3x4[0][0] == _mat4x3[0][0]) 191 { 192 doSomething(); 193 } 194 195 if (rayQueryGetRayFlagsEXT(rayQuery) > 0) 196 { 197 doSomething(); 198 } 199 200 if (rayQueryGetRayTMinEXT(rayQuery) > 0.0) 201 { 202 doSomething(); 203 } 204 205 vec3 o = rayQueryGetWorldRayOriginEXT(rayQuery); 206 vec3 d = rayQueryGetWorldRayDirectionEXT(rayQuery); 207 208 if (o.x == d.z) 209 { 210 doSomething(); 211 } 212} 213