Bug in order-independent transparency rendering with multiple cameras

Hi folks,
I have to use order-independent transparency rendering (depth peeling) because of multiple intersecting semi-opaque objects. Everything works nicely until I add a second camera to the mix.

Here’s a PG.

In my special case, I could use a completely different scene for the second camera and somehow draw this viewport into the first main scene. Would that be a feasible workaround?

Cheers as always! :pray:

Update: Using a second scene fixes the issue as shown here.

Yes, there are limits to the use of OIT, and using multiple cameras in a scene is one of them.

I’m glad you found a workaround!

Do you see any chance for a solution with the same scene? We wanted to use multiple cameras for the same scene at some point…

It seems like setting the viewport is causing the issue. Even with just one camera, the OIT rendering breaks when setting the viewport. Maybe the clearing (depth or stencil?) is not done correctly for altered viewports.

Here’s a single camera setup (the other scene & camera is just for the GUI rendering) using OIT where you can change the viewport: PG

It seems like the buffers required for the OIT rendering are not shifted and scaled according to the viewport. This could also explain why the multi-camera setup (with its different viewports) does not behave correctly.

You’re right, the viewport was not taken into account, this PR will fix the problem:

However, rendering with OIT still does not work for multiple cameras (even with full-sized viewports) if two or more cameras render transparent meshes with OIT.

I think that’s because the final composition step does not work if done multiple times in the same frame. Let’s cc @CraigFeldspar for his opinion, as he is the daddy of the feature!

Here’s a simple repro for reference:

The blobs on the left are rendered by the second camera and are ok, whereas the ones on the right are rendered by the first camera and are not ok.

2 Likes

Thanks a lot @Evgeni_Popov for fixing this first issue. Let’s hope that @CraigFeldspar can fix the remainders.

I did another test where I use a single camera, but render it twice with different viewports: PG

Thanks to your fix,@Evgeni_Popov, the viewports work nicely.
Interestingly, the second render call works correctly, but the first still shows the known issues. So it’s not even related to having two cameras. Without looking into the code I have the feeling that some initialization of (depth?) buffers go wrong when rendering multiple times.