Portal Rendering with Stencil Buffer

Hi all, I’m trying to render a portal using stencil buffer/mask, NOT with the commonly-used SceneCapture component. The motive is:

  • The portan rendering should be identical with the world rendering including all lighting & shadow & post effects.
  • SceneCapture approach is too expensive (especially with the large render target) and with many visual discrepancies from the main rendering pass.

The approach I would like to take is essentially:

  1. Render the base scene while marking the stencil buffer for pixels of a portal.
  2. Render the portal scene only to the marked pixels from Pass 1.
  3. Apply postprocessing.

This will be much more efficient and clear than SceneCapture approach. Now the question is how to achieve it, obviously.

Q1. How can I customize ALL existing surface shaders to use a new stencil state? Do I need to duplicate all existing PSOes to include a new stencil state? Or is it enough to inject a new SetDepthStencilState somewhere? If latter, where is that somewhere going to be (in C++)?

Q2. How can I kick of the main rendering pass with a different camera angle? I imagine it’s a little deviation from the local split-screen, because that’s what the splitscreen is doing already. Which C++ codes should I be checking to get an idea?

Thanks for any tips and help!

I am also trying to figure out how to do this. I have never found a satisfactory answer. There was one person who I believe managed to make a modified version of the engine that could support this, but he lost his entire project, and he never told anyone how he did it. (I even emailed him with questions and never got a response back…)

I’ve been at my wit’s end for months. I sort of gave up even thinking it might be possible, but seeing how undesirable the alternatives are, I’ve been once again thinking about what it might take to get this to work.

Unfortunately, the chances of my being able to do this without help are just about nil.