What is the best way for rendering diffused reflections / multi ray generation inside recursion

I’m looking to do computations of diffused reflections. The simple case,

  1. The camera produces rays pointing at a diffuse wall.
  2. The value is the sum of the rays coming in from all directions into that point (attenuated by direction)

What would be the best way to approach the problem?

One idea is to map the camera to the wall, collect the intersection points in a buffer and then re-run the program for all pixels * all angles, but it’s not clear what is a good way to combine results as this either requires an insane amount of memory or a lot of atomic operations. It is also difficult in this way to handle multi level bounces

Another is to send multiple rays in the same direction and then bounce them randomly, but again, there is a question as to what is a good way to combine the result. It would either mean a lot of runs or a lot of memory or a lot of atomics.

Is there a way to do the first or a combination of the first and the second recursively, i.e generate the second jump rays from the first set without storing them into a buffer and re-running?

Thanks for any advice

The path tracing example inside the OptiX SDK does it with many runs.

As a rule of thumb, when working on the same GPU you use for display, then do less work more often to avoid Windows OS timeouts and to keep the system more interactive.

Continually render the whole frame and shoot cosine weighted paths into the hemisphere above the hit points to integrate diffuse reflection.
The end result is accumulated at the end of the ray generation program into a float4 RT_INPUT_OUTPUT buffer.
That ray generation program is working iteratively, so it needs very little stack space.
Each ray (per current path) calculates its next origin and direction when it hits something.

Yes, that needs enormous amounts of rays, because you randomly follow only one path per pixel on each launch.
There are more refined light transport algorithms which converge faster.