I am learning to build a ray tracing pipeline. however, the generated ray is always missed even when I use negative normal as ray direction. I checked my ray tracing pipeline in Nsight Graphics, I can not found any wrong item. This problem is stucking me for a long time, is anyone able to find something what I did wrong?
- payload struct
struct hitPayload
{
vec2 HitInfo;
};
- ray generation shader
layout(location = 0) rayPayloadEXT hitPayload hitLoad;
layout(binding = 0, rgba8) uniform image2D uWorldNormalImage;
layout(binding = 1, r8) uniform image2D uAoImage; // Output AO image
layout(binding = 2) uniform accelerationStructureEXT scene; // Built AS
layout(binding = 3, rgba32f) uniform image2D uWorldPositonImage;
void main()
{
ivec2 size = imageSize(uAoImage);
ivec2 pixel = ivec2(gl_LaunchIDEXT.xy);
vec3 worldPos = imageLoad(uWorldPositonImage, pixel).xyz;
if(worldPos == vec3(0.0)){
return;
}
vec3 normal = imageLoad(uWorldNormalImage, pixel).xyz;
normal = normalize(normal*2.0 - 1.0);
vec3 direction = -normal;
hitLoad.HitInfo = vec2(0.0);
traceRayEXT(
scene, // Acceleration structure
gl_RayFlagsOpaqueEXT,
0xFF, // 8-bit instance mask
0, // SBT record offset
0, // SBT record stride for offset
0, // Miss index
worldPos, // Ray origin
0.0, // Minimun t-value
direction, // Ray direction
1000.0, // Maximum t-value
0 // Location of payload
);
imageStore(uAoImage, pixel, vec4(hitLoad.HitInfo.y));
}
- closest hit shader
layout(location = 0) rayPayloadInEXT hitPayload hitLoad;
void main()
{
hitLoad.HitInfo[1] = 1.0;
}
- miss shader
layout(location = 0) rayPayloadInEXT hitPayload hitLoad;
void main()
{
hitLoad.HitInfo[0] = 1.0;
}
The above code should always trigger hit, but the uAoImage
is always black.
The below screenshots are from Nsight graphics, I can not find any abnormal thing.
I found a weird thing
I use Nsight graphics to caputre C++ replay, and the closest-hit is triggered in replay capture. The below screen shot is the uAoImage
in replay capture.
In my native code, I didn’t have the middle revision of uAoImage
.