I think I found a solution to the portal problem. I changed it so that when the stencil shader seals off a portal it clears the alpha channel to zero (but keeps RGB intact as before). That changes the scene color buffer to look like this (note that RGB data for the sky is still there):
That in turn allows the linear depth shader to do this:
Code: Select all
float depth = texture(ColorTexture, uv).a != 0.0 ? texture(DepthTexture, uv).x : 1.0;
The end result is that anything behind a sealed portal will appear to be far far away not cause any incorrect ambient occlusion. We can even run the SSAO pass multiple times this way (for each entered portal), or only do it for the main camera.