Fei Yang
Fei Yang

Reputation: 11

VKRay/DXR: What information do you store in your "Payload" structure?

This will be an important design decision in my next ray-tracing project.

We know that the "Payload" structure is used for passing data from the closest-hit shader to the raygen shader. For a recursive PBRT system, basically, I have 2 options here:

  1. Use it to store the ray-surface interaction information of the hit-point (be it a BRDF or a BSDF)
  2. Use it to store the information of the next ray to trace

The 1st option is intuitive. There is a universal representation of ray-surface interaction. The closest-shaders returns that information to raygen shader, and the information is processed uniformly in the raygen shader to modify the integrated color and generate the next ray. A problem of this design is that the BSDF representation can be big and complicated in a PBRT system. For VKRay/DXR, we want the Payload to be as small as possible.

The 2nd option leaves the evaluation of ray-surface interaction to the closest-hit shaders. Each of the closest-hit shader can have its own representation of ray-surface interaction, which can be extremely simple (depending on the geometry representation). In this case, Payload stores the evaluated results, such as the information of the next ray to trace. A possible issue is that the closest-hit shaders are the diverged parts in the execution flow, would them be less efficient than the raygen shader?

Which one do you prefer, and why?

Upvotes: 0

Views: 261

Answers (1)

Rob
Rob

Reputation: 116

The short answer is it depends on it will depend on the hardware your running on and it's worth experimenting with. What we can say is method 1 will certainly have less memory footprint and probably have better ray gathering and better caching, but may also have higher bandwidth due to the increased payload size. Another advantage of method 1 is that you will not be limited by recursion depth.

Of course, method 2 is more flexible from a design perspective. Adding a new material/object would involve adding a new shader without modifying the raygen shader/payload definition.

If you are going for method 1 then you may also want to look into using "ray queries" which will bypass the need for a closest-hit shader altogether. You will effectively end op with a very bulky raygen shader. It may be less flexible but it should be faster.

Upvotes: 2

Related Questions