glslang/Test/rayQuery-allOps.comp

223 lines
5.8 KiB
Plaintext
Raw Permalink Normal View History

2020-03-24 01:34:09 +00:00
#version 460
#extension GL_EXT_ray_query : enable
#extension GL_EXT_ray_flags_primitive_culling : enable
2022-06-09 00:29:38 +00:00
#extension GL_EXT_ray_tracing_position_fetch : enable
2020-03-24 01:34:09 +00:00
layout(primitive_culling);
2020-03-24 01:34:09 +00:00
struct Ray
{
vec3 pos;
float tmin;
vec3 dir;
float tmax;
};
layout(std430, set = 0, binding = 0) buffer Log
{
uint x;
uint y;
};
2020-03-26 22:51:18 +00:00
layout(binding = 1, set = 0) uniform accelerationStructureEXT rtas;
2020-03-24 01:34:09 +00:00
layout(std430, set = 0, binding = 2) buffer Rays { Ray rays[]; };
void doSomething()
{
x = 0;
y = 0;
}
Ray makeRayDesc()
{
Ray ray;
ray.pos= vec3(0,0,0);
ray.dir = vec3(1,0,0);
ray.tmin = 0.0f;
ray.tmax = 9999.0;
return ray;
}
void main()
{
Ray ray = makeRayDesc();
2020-03-24 01:34:09 +00:00
rayQueryEXT rayQuery;
rayQueryInitializeEXT(rayQuery, rtas, gl_RayFlagsNoneEXT, 0xFF, ray.pos, ray.tmin, ray.dir, ray.tmax);
2020-03-24 01:34:09 +00:00
mat4x3 _mat4x3;
mat3x4 _mat3x4;
while (rayQueryProceedEXT(rayQuery))
{
uint candidateType = rayQueryGetIntersectionTypeEXT(rayQuery, false);
switch(candidateType)
{
case gl_RayQueryCandidateIntersectionTriangleEXT:
rayQueryTerminateEXT(rayQuery);
_mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false);
_mat3x4 = transpose(_mat4x3);
rayQueryConfirmIntersectionEXT(rayQuery);
if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true))
{
doSomething();
}
if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).x == 0)
{
doSomething();
}
if (rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0)
{
doSomething();
}
if (rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0)
{
doSomething();
}
if (rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).x > 0)
{
doSomething();
}
if (rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0)
{
doSomething();
}
if (rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0)
{
doSomething();
}
if (rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f)
{
doSomething();
}
if (rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQuery, true) > 0)
{
doSomething();
}
break;
case gl_RayQueryCandidateIntersectionAABBEXT:
{
_mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false);
_mat3x4 = transpose(_mat4x3);
if (rayQueryGetIntersectionCandidateAABBOpaqueEXT(rayQuery))
{
doSomething();
}
float t = 0.5;
rayQueryGenerateIntersectionEXT(rayQuery, t);
rayQueryTerminateEXT(rayQuery);
break;
}
}
}
if(_mat3x4[0][0] == _mat4x3[0][0])
{
doSomething();
}
uint committedStatus = rayQueryGetIntersectionTypeEXT(rayQuery, true);
switch(committedStatus)
{
case gl_RayQueryCommittedIntersectionNoneEXT :
_mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, false);
_mat3x4 = transpose(_mat4x3);
break;
case gl_RayQueryCommittedIntersectionTriangleEXT :
_mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, true);
_mat3x4 = transpose(_mat4x3);
if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true))
{
doSomething();
}
if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).y == 0)
{
doSomething();
}
2022-06-09 00:29:38 +00:00
{
vec3 positions[3];
rayQueryGetIntersectionTriangleVertexPositionsEXT(rayQuery, true, positions);
if (positions[0].x < 0 && positions[2].y > 0)
{
doSomething();
}
}
2020-03-24 01:34:09 +00:00
break;
case gl_RayQueryCommittedIntersectionGeneratedEXT :
if(rayQueryGetIntersectionGeometryIndexEXT(rayQuery, true) > 0)
{
doSomething();
}
if(rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0)
{
doSomething();
}
if(rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0)
{
doSomething();
}
if(rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).z > 0)
{
doSomething();
}
if(rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0)
{
doSomething();
}
if(rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0)
{
doSomething();
}
if(rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f)
{
doSomething();
}
break;
}
if (_mat3x4[0][0] == _mat4x3[0][0])
{
doSomething();
}
if (rayQueryGetRayFlagsEXT(rayQuery) > gl_RayFlagsSkipTrianglesEXT)
2020-03-24 01:34:09 +00:00
{
doSomething();
}
if (rayQueryGetRayTMinEXT(rayQuery) > 0.0)
{
doSomething();
}
vec3 o = rayQueryGetWorldRayOriginEXT(rayQuery);
vec3 d = rayQueryGetWorldRayDirectionEXT(rayQuery);
if (o.x == d.z)
{
doSomething();
}
}