This question was created in reference to: [Creating a line trace GPU raytraced compute [Content removed]
As this thread has been marked permanently closed, so also following up also in a new thread.
[@Sam [Content removed] (EPS Partner) - Many thanks for your code here - having implemented it, I’m getting similar inconsistent results so I’ve uploaded a MVP project with the relevant code in a GPUCompute plugin to help.
Incorrect hit points - The shader is returning a valid hit however the hit point is incorrect and doesn’t appear to correlate with the geometry in the scene.
Inconsistent Results- I’m getting inconsistent hit results which appear to be view dependent (eg same inputs for line trace produces different results depending upon the view in editor).
I’ve attached a screenshot illustrating this (thin red trace lines = miss) as well as the sample project. Map has a simple editor utility actor with a BP function which can be called in editor through the actors properties bar.
thanks for providing your plugin code. I ran the project and confirmed your observations w.r.t. view dependent results. Hardcoding the ray’s origin and direction in the shader still produces different view dependent hit results, which is very puzzling. I also noticed that when the camera is far away from the scene (about 4000 units from the ray origin), the shader will only return misses.
The screenshot you posted may be due to the coordinate systems of the scene and the ray tracing system not matching up, but I have not been able to verify that.
I’ve looked into other ray tracing examples in the engine code to verify the correctness, but unfortunately could not pinpoint the cause of these issues.
If you want, I can escalate this case to Epic, so someone with deeper knowledge of Unreal’s ray tracing system can have a look.
I visualised the TLAS with Nvidia NSight Graphics (this is a useful tool to debug ray tracing issues) and confirmed that the scene geometry is actually represented by the TLAS, however I could not explain why the view dependent hits. I will pass this case back to Epic for further investigation.
I appreciate your taking the time to have a lengthy discussion with our support partner and the effort you put into sharing your line tracing project code. Unfortunately, the code you gave me has been too time-consuming to decipher, so I have only the following suggestions to help you identify and resolve your issue.
First, could you check if your line tracing code is correct by setting up a simpler test scene that can help you verify your assumptions? A scene that contains a single flat plane, located in world space at (1, 0, 0), would already suffice. Then, strip down the line tracing shader only to have the bare minimum of functionality to trace a single line and store the result in a UAV. Fix the ray starting position to the world space origin (0, 0, 0) and the ray direction to point towards the plane (also (1, 0, 0)). Once that is done, set a breakpoint or use log statements in your C++ code where you perform the GPU readback to verify that the values are correct. The ray query shader should return a hit position of (1, 0, 0) in this case.
Assuming the setup yields a reasonable output, you can then gradually introduce more complexity to your testing scene setup and build out the shader to dynamically process ray origins from an SRV or Uniform Buffer, etc. Please review our implementation of hardware ray tracing shaders in Engine\Shaders\Private\RayTracing. Specifically, the RayTracingCommon.ush shader header file is a good starting point for understanding how the engine implements the DX12 specification for hardware ray tracing.
Please let me know if you have any further questions about this, and if you encounter any issues that suggest a bug on the engine side.