I know the rayQuery feature is working, but it’s not hitting anything.
I checked with the shader loggers and it’s logging in the while(rayQueryProceedEXT(rayQuery)){} area.
I’ve also checked the Acceleration Structure and the mesh is there.
It’s working fine in the full raytracer.
vec3 CalcNormalDirLight(Vertex vertex, MaterialProperties material, mat3 TBN, vec3 normal, vec2 uv, int index)
{
vec3 LightPos = DLight[index].directionalLight.direction;
vec3 ViewPos = sceneData.CameraPos;
vec3 FragPos2 = vertex.Position;
if (material.NormalMapID != 0)
{
LightPos = TBN * DLight[index].directionalLight.direction;
ViewPos = TBN * sceneData.CameraPos;
FragPos2 = TBN * vertex.Position;;
}
vec3 ViewDir = normalize(ViewPos - FragPos2);
const vec3 lightDir = normalize(-LightPos);
const float diff = max(dot(normal, lightDir), 0.0);
const vec3 halfwayDir = normalize(lightDir + ViewDir);
const float spec = pow(max(dot(normal, halfwayDir), 0.0), material.Shininess);
vec3 ambient = DLight[index].directionalLight.ambient * material.Diffuse.rgb;
vec3 diffuse = DLight[index].directionalLight.diffuse * diff * material.Diffuse.rgb;
vec3 specular = DLight[index].directionalLight.specular * spec * material.Specular;
if (material.DiffuseMapID != 0)
{
ambient = DLight[index].directionalLight.ambient * vec3(texture(TextureMap[material.DiffuseMapID], uv));
diffuse = DLight[index].directionalLight.diffuse * diff * vec3(texture(TextureMap[material.DiffuseMapID], uv));
}
if (material.SpecularMapID != 0)
{
specular = DLight[index].directionalLight.specular * spec * vec3(texture(TextureMap[material.SpecularMapID], uv));
}
float LightDistance = length(LightPos - FragPos2);
vec3 result = ambient;
float tmin = 0.001;
float tmax = LightDistance;
vec3 origin = gl_WorldRayOriginEXT + gl_WorldRayDirectionEXT * gl_HitTEXT;
shadowed = true;
traceRayEXT(topLevelAS, gl_RayFlagsSkipClosestHitShaderEXT, 0xFF, 1, 0, 1, origin, tmin, lightDir, tmax, 1);
if (shadowed)
{
result += (diffuse + specular) * 0.3f;
}
else
{
result += (diffuse + specular) ;
}
return result;
}
But when I’m trying with ray querying in the raster shader, it’s getting no hits.
vec3 CalcNormalDirLight(MaterialProperties material, mat3 TBN, vec3 normal, vec2 uv, int index)
{
vec3 LightPos = DLight[index].directionalLight.direction;
vec3 ViewPos = sceneData.CameraPos;
vec3 FragPos2 = FragPos;
if (material.NormalMapID != 0)
{
LightPos = TBN * DLight[index].directionalLight.direction;
ViewPos = TBN * sceneData.CameraPos;
FragPos2 = TBN * FragPos;
}
vec3 ViewDir = normalize(ViewPos - FragPos2);
const vec3 lightDir = normalize(-LightPos);
const float diff = max(dot(normal, lightDir), 0.0);
const vec3 halfwayDir = normalize(lightDir + ViewDir);
const float spec = pow(max(dot(normal, halfwayDir), 0.0), material.Shininess);
vec3 ambient = DLight[index].directionalLight.ambient * material.Diffuse.rgb;
vec3 diffuse = DLight[index].directionalLight.diffuse * diff * material.Diffuse.rgb;
vec3 specular = DLight[index].directionalLight.specular * spec * material.Specular;
if (material.DiffuseMapID != 0)
{
ambient = DLight[index].directionalLight.ambient * vec3(texture(TextureMap[material.DiffuseMapID], uv));
diffuse = DLight[index].directionalLight.diffuse * diff * vec3(texture(TextureMap[material.DiffuseMapID], uv));
}
if (material.SpecularMapID != 0)
{
specular = DLight[index].directionalLight.specular * spec * vec3(texture(TextureMap[material.SpecularMapID], uv));
}
float LightDistance = length(LightPos - FragPos2);
vec3 result = ambient;
vec3 origin = FragPos;
vec3 direction = normalize(FragPos - LightPos);
float tMin = 0.001f;
float tMax = LightDistance ;
rayQueryEXT rayQuery;
rayQueryInitializeEXT(rayQuery, topLevelAS, gl_RayFlagsTerminateOnFirstHitEXT, 0xFF, origin, tMin, direction, tMax);
while(rayQueryProceedEXT(rayQuery))
{
}
if(rayQueryGetIntersectionTypeEXT(rayQuery, true) != gl_RayQueryCommittedIntersectionNoneEXT)
{
result += (diffuse + specular) * 0.3f;
}
else
{
result += (diffuse + specular);
}
return result;
}