Making a specific color in a texture transparent at runtime. [SOLVED ]

So, i’m playing around with a project where I can exert a lot of control over color palettes in the game. I’ve got my camera filtering things into a restricted 5-color palette, which I can change dynamically with scripts.

One thing I wanted to try was for different objects in the game world to have different color palettes. For instance, the world could be in grayscale, while highlighted elements could be in shades of purple, and both of those color palettes could be independently dynamically altered.

What I’ve tried so far is to have two cameras, each with a different palette set to it - Camera 1 viewing the world in grayscale tones, Camera 2 viewing a set of colors, including black. I’ve also set the latter, colored camera to see all the background materials in the world as matte black - so the image it see is just a black screen with certain objects highlighted in color. This works fine, and Camera 2 renders out to a RenderTexture.

Where I’m getting stuck is in trying to overlay the colored Camera 2 view over the grayscale Camera 1 worldview. It seems like there should be an easy way to “punch out” the black pixels, and overlay the rest as a GUI, but I can’t find anything. Specific pixel operations are too costly, as I have to first convert the RenderTexture from Camera 2 into a Texture2D in order to get and set pixels, and that cuts the framerate to a third of where it is normally.

Is there any simple way to turn all of those black pixel transparent, or simply to not render them when I overlay them on the camera image as a GUI? Is there another way to get this effect?

Here are images that might help visualize this:
Camera 1 sees this:

Camera 2 sees this:

And, ideally, I’m aiming for this as a final image: (this was made in Photoshop using the above two grabs)

Found a workaround. Not exactly what I wanted, but close enough. I used additive mixing rather than alpha, and because my underlying layer is light enough, the effect was close.

Rather than using code, I made a new material using the RenderTexture along with an additive particle shader. I applied that texture to a canvas gameobject, so it would be drawn as a GUI element on top of the screen.