How-to create a green-screen like effect with two cameras

I’d like to have the output from another camera be overlayed on top of the main camera, but only where it’s a certain color.

Basically, if there’s an unlit, solid color, pink object in view on the main camera, I’d like to overlay what the second camera can see on top of that portion of the screen.

I’m looking at the overlay shader and I think I need to use the Graphics.Blit function inside of an OnRenderImage, but I’m stuck there.

I’d really appreciate if someone could confirm that I’m on the right track and it would be especially helpful if anyone knew where some example code that did what I’m after is. Thanks!

Just to update my progress a little, I’m attempting to use a screen effect frag shader. It seems like if I could look at each pixel from the main camera, determine if it’s a certain color (bright pink), then - if not: output same color, if so: replace it with the color from the same pixel coord on a second camera.

I can’t seem to figure out how to reference a second camera inside the shader, though.

I’ve solved this:

My setup ended up being really simple. The script attached to the main camera asks for a color, 2nd camera and a shader. (The color is whatever should get the greenscreen effect in the main camera output) and sets up a temporary texture and writes the output of the 2nd camera to it every render frame. Then passes that texture to the shader. In the shader, in the frag function, I check each pixel to see if it’s the specified color, if it is, leave it alone, if not, replace it with the pixel from the supplied texture (which is the other camera).