Compute rendering latency

I’m working on some compute shader rendering, and it’s mostly successful, but I’m seeing some weird behavior when the camera moves or rotates.
When this happens, there is a mismatch in the standard rendering of the scene and my compute rendering, some sort of latency or smoothing issue. This can be seen in this playground:

Try panning the camera around, you’ll clearly see that something is not quite right.
Any idea what could be causing this? Is the compute shader not getting the new camera matrices quick enough? Or something else entirely?

I realized I’m rendering the scene twice in this example. Still, removing the 2nd render doesn’t fix the problem. I’ve also tried to make sure the compute renderer runs after all other objects have rendered, which also didn’t solve it.

If I had to guess, it looks like an off-by-one kind of issue with the camera matrices that are passed into the compute shader. But I haven’t used compute shaders much-- perhaps @Evgeni_Popov would know more.

(On a related note, I haven’t yet seen any compute shader examples that depend on camera matrices, nor any examples whose uniforms are updated as rapidly. It may be for a reason?)

This is an ordering problem with the depth renderer.

You should keep everything in the scene.render() function and use observers to inject your code in the right place. The depth renderer updates its texture on the first camera pass, so the onBeforeDrawPhaseObservable is a good place to inject your compute shader dispatches (this observable is notified after the camera render targets have been processed). onAfterRenderTargetsRenderObservable could also be a good place, but this observable is also notified after the scene-wide render target pass, so you’d need additional code to make sure your code is called by the right notification.

Here’s the fixed PG:

4 Likes