Shader output to a texture

I’m using a shader which has a base texture and a stencil which masks the base texture. I would like to draw the “result” of this masking to another texture where I want to be able to draw multiple times.

How am I supposed to do it? Is there a way to write the output to a third texture in the same shader so that I can access it’s data through getPixels32()?

This solved my problem:

Just need to pass in a material using the shader, so it will be taken into account when drawing to the destination texture.

Thanks,