MRT can be used to simulate multiple consecutive camera loops in a single pass. To prevent feedback loops and ensure stability, the camera loops must be double-buffered.
Implementation Pattern
- Define Buffers: For $N$ simulated loops, create $2 imes N$ RenderTextures (one set for the main loop data, one set for the double-buffer/copy pass).
- Assign Cameras: Use
SetTargetBuffers on both the LoopCamera and the DBCamera (Double Buffer Camera) to point them to their respective sets of RenderTextures. - Shader Logic:
- The Main Loop Shader reads from the previous loop's textures and writes results to the MRT targets.
- The Double-Buffering Shader performs a simple data copy from the main textures to the double-buffer textures.
- Criss-Cross Textures: To complete the loop, feed the output textures of the first camera into the quad associated with the second camera, and vice-versa.
// Example setup for 3 simulated loops using 2 cameras
void Start()
{
// LoopCamera writes to RT0, RT1, RT2
LoopCamera.SetTargetBuffers(
new RenderBuffer[] { RT0.colorBuffer, RT1.colorBuffer, RT2.colorBuffer },
RT0.depthBuffer);
// DBCamera copies RT0, RT1, RT2 into the double buffers
DBCamera.SetTargetBuffers(
new RenderBuffer[] { RT0_DB.colorBuffer, RT1_DB.colorBuffer, RT2_DB.colorBuffer },
RT0_DB.depthBuffer);
}