Update scene.frag

Ray Query example: shader optimization

Calling rayQueryProceedEXT in a loop can prevent certain shader optimizations. By setting the TerminateOnFirstHit and SkipAABB flags, there is no scenario where rayQueryProceedEXT will return true, hence the loop can be removed. 

This way the implementation has a guarantee that the traversal can be completed without returning control to the shader, which improves performance.
This commit is contained in:
JoseEmilio-ARM 2022-04-07 15:35:38 +01:00 committed by GitHub
parent 4e6b4fe021
commit 3394928112
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,10 +25,10 @@ void main()
outFragColor = vec4(diffuse, 1.0);
rayQueryEXT rayQuery;
rayQueryInitializeEXT(rayQuery, topLevelAS, gl_RayFlagsTerminateOnFirstHitEXT, 0xFF, inWorldPos, 0.01, L, 1000.0);
rayQueryInitializeEXT(rayQuery, topLevelAS, gl_RayFlagsTerminateOnFirstHitEXT | gl_RayFlagsSkipAABBEXT, 0xFF, inWorldPos, 0.01, L, 1000.0);
// Start the ray traversal, rayQueryProceedEXT returns false if the traversal is complete
while (rayQueryProceedEXT(rayQuery)) { }
// Traverse the acceleration structure and store information about the first intersection (if any)
rayQueryProceedEXT(rayQuery);
// If the intersection has hit a triangle, the fragment is shadowed
if (rayQueryGetIntersectionTypeEXT(rayQuery, true) == gl_RayQueryCommittedIntersectionTriangleEXT ) {