Make the aperture earn its pixels.
A render-target texture is rectangular; a portal opening does not have to be. Compare an unmasked quad with a stencil-written ellipse, then invert the test to make the outside visible. The capture pass is kept separate so the mask remains a main-frame composition contract.
Preparing paired targets, an ellipse mask, and the stencil-enabled renderer...
- renderer
- -
- targets
- -
- passes
- -
- mask
- -
- stencil
- -
- calls
- -
- frame ms
- -
- resources
- -
The stencil mask writes reference 1 before the portal surface tests it; the surface clears the stencil buffer after its draw.
WebGLRenderer({ stencil: true })canvas attachmentcolorWrite = falsemask writes no colorstencilFunc = Alwaysmask writes reference 1stencilFunc = Equal / NotEqualsurface tests aperturerenderer.clearStencil()between portal surfacesThe render targets are color/depth attachments only. Stencil is used by the main canvas composition pass, while captures temporarily hide the portal assembly and restore renderer state.
The aperture outline is a visual helper only; the actual mask material writes the stencil attachment without writing color.
Derived from the official clipping stencil example, portal example, and current Material, WebGLRenderer, RenderTarget, and MaskPass docs.