How to Use a Rectangular Stencil When Drawing to a Render Target?

Hi everyone,

I’m trying to draw to a render target, but I need to stencil out certain areas to restrict where the drawing occurs. Specifically, the stenciled area is always a rectangle, and I want to ensure that only pixels inside this rectangle are affected by the draw operation. Pixels outside the rectangle should remain unchanged.

For example, doing this:

Should result this:

I’m using C++.

I’ve considered drawing to another render target which is sized just that stencil area, but since I cannot directly copy a render target’s content to another render target, I’m trying to figure out this way.

Thanks in advance!

Using a custom FCanvasBaseRenderItem and calling RHICmdList.SetScissorRect before DrawParameters.RenderData->BatchedElements.Draw will do that.

To use the custom canvas render item, you need to replace the function address of FCanvas::GetBatchedElements with yours, but that’s out of this scope.