2 #extension GL_EXT_ray_query : enable
3 #extension GL_EXT_ray_flags_primitive_culling : enable
5 layout(primitive_culling);
14 layout(std430, set = 0, binding = 0) buffer Log
20 layout(binding = 1, set = 0) uniform accelerationStructureEXT rtas;
21 layout(std430, set = 0, binding = 2) buffer Rays { Ray rays[]; };
33 ray.dir = vec3(1,0,0);
41 Ray ray = makeRayDesc();
43 rayQueryInitializeEXT(rayQuery, rtas, gl_RayFlagsNoneEXT, 0xFF, ray.pos, ray.tmin, ray.dir, ray.tmax);
48 while (rayQueryProceedEXT(rayQuery))
50 uint candidateType = rayQueryGetIntersectionTypeEXT(rayQuery, false);
53 case gl_RayQueryCandidateIntersectionTriangleEXT:
55 rayQueryTerminateEXT(rayQuery);
56 _mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false);
57 _mat3x4 = transpose(_mat4x3);
58 rayQueryConfirmIntersectionEXT(rayQuery);
60 if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true))
65 if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).x == 0)
70 if (rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0)
75 if (rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0)
80 if (rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).x > 0)
85 if (rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0)
90 if (rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0)
95 if (rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f)
100 if (rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQuery, true) > 0)
106 case gl_RayQueryCandidateIntersectionAABBEXT:
108 _mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false);
109 _mat3x4 = transpose(_mat4x3);
110 if (rayQueryGetIntersectionCandidateAABBOpaqueEXT(rayQuery))
116 rayQueryGenerateIntersectionEXT(rayQuery, t);
117 rayQueryTerminateEXT(rayQuery);
123 if(_mat3x4[0][0] == _mat4x3[0][0])
128 uint committedStatus = rayQueryGetIntersectionTypeEXT(rayQuery, true);
130 switch(committedStatus)
132 case gl_RayQueryCommittedIntersectionNoneEXT :
133 _mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, false);
134 _mat3x4 = transpose(_mat4x3);
137 case gl_RayQueryCommittedIntersectionTriangleEXT :
138 _mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, true);
139 _mat3x4 = transpose(_mat4x3);
141 if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true))
146 if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).y == 0)
152 case gl_RayQueryCommittedIntersectionGeneratedEXT :
154 if(rayQueryGetIntersectionGeometryIndexEXT(rayQuery, true) > 0)
159 if(rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0)
164 if(rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0)
169 if(rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).z > 0)
174 if(rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0)
179 if(rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0)
184 if(rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f)
191 if (_mat3x4[0][0] == _mat4x3[0][0])
196 if (rayQueryGetRayFlagsEXT(rayQuery) > gl_RayFlagsSkipTrianglesEXT)
201 if (rayQueryGetRayTMinEXT(rayQuery) > 0.0)
206 vec3 o = rayQueryGetWorldRayOriginEXT(rayQuery);
207 vec3 d = rayQueryGetWorldRayDirectionEXT(rayQuery);