2 #extension GL_NV_ray_tracing : enable
3 #extension GL_EXT_ray_query : enable
13 layout(std430, set = 0, binding = 0) buffer Log
19 layout(binding = 1, set = 0) uniform accelerationStructureEXT rtas;
20 layout(std430, set = 0, binding = 2) buffer Rays { Ray rays[]; };
32 ray.dir = vec3(1,0,0);
40 Ray ray = makeRayDesc();
42 rayQueryInitializeEXT(rayQuery, rtas, gl_RayFlagsNoneEXT, 0xFF, ray.pos, ray.tmin, ray.dir, ray.tmax);
47 while (rayQueryProceedEXT(rayQuery))
49 uint candidateType = rayQueryGetIntersectionTypeEXT(rayQuery, false);
52 case gl_RayQueryCandidateIntersectionTriangleEXT:
54 rayQueryTerminateEXT(rayQuery);
55 _mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false);
56 _mat3x4 = transpose(_mat4x3);
57 rayQueryConfirmIntersectionEXT(rayQuery);
59 if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true))
64 if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).x == 0)
69 if (rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0)
74 if (rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0)
79 if (rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).x > 0)
84 if (rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0)
89 if (rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0)
94 if (rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f)
99 if (rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQuery, true) > 0)
105 case gl_RayQueryCandidateIntersectionAABBEXT:
107 _mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false);
108 _mat3x4 = transpose(_mat4x3);
109 if (rayQueryGetIntersectionCandidateAABBOpaqueEXT(rayQuery))
115 rayQueryGenerateIntersectionEXT(rayQuery, t);
116 rayQueryTerminateEXT(rayQuery);
122 if(_mat3x4[0][0] == _mat4x3[0][0])
127 uint committedStatus = rayQueryGetIntersectionTypeEXT(rayQuery, true);
129 switch(committedStatus)
131 case gl_RayQueryCommittedIntersectionNoneEXT :
132 _mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, false);
133 _mat3x4 = transpose(_mat4x3);
136 case gl_RayQueryCommittedIntersectionTriangleEXT :
137 _mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, true);
138 _mat3x4 = transpose(_mat4x3);
140 if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true))
145 if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).y == 0)
151 case gl_RayQueryCommittedIntersectionGeneratedEXT :
153 if(rayQueryGetIntersectionGeometryIndexEXT(rayQuery, true) > 0)
158 if(rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0)
163 if(rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0)
168 if(rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).z > 0)
173 if(rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0)
178 if(rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0)
183 if(rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f)
190 if (_mat3x4[0][0] == _mat4x3[0][0])
195 if (rayQueryGetRayFlagsEXT(rayQuery) > 0)
200 if (rayQueryGetRayTMinEXT(rayQuery) > 0.0)
205 vec3 o = rayQueryGetWorldRayOriginEXT(rayQuery);
206 vec3 d = rayQueryGetWorldRayDirectionEXT(rayQuery);