Camera Color to Transparent

Basically I’m taking a camera and overlaying it upon the main camera. I need to be able to set everything white (and it’s grey shades) to transparent. Ideally this would also have greys become partially transparent of solid black.

Mask

Base

Here’s just one quick and dirty way to do it. There are other fancier ways such as using post processing on the overlay camera, or using a custom shaders for the renderers in your overlay camera view. This method will do what you described by only adding a Quad to your scene.

  1. Create a RenderTexture and add it to the overlay camera
  2. Create a new Unlit Shader
  3. In the frag function of that shader you will see this line fixed4 col = tex2D(_MainTex, i.uv)–this is the color that is sampled from the main texture for a given pixel.
  4. Add something like col.a = 1 - col.rgb;–this sets the alpha value to the inverse of the brightness (red x green x blue) of the color.
  5. Add something like col.rgb = 0; --this makes the color 100% black. Since the gray tones will already be blended in partially, you want to use a solid black color to be blended in.
  6. Add this line in the SubShader (ie after the Tags, line ~10): Blend One OneMinusSrcAlpha --this will tell the shader to blend with whatever colors have already been drawn behind it.
  7. Create a quad in front of the main camera covering its view. You may want to make a script to position/scale the quad perfectly to fit your camera.
  8. Apply a new material using this shader to that quad. For the material’s main texture, use the RenderTexture that you linked to your overlay camera.

Now you should see the output of your overlay camera rendering to the quad with the transparent effect.

Dumb that I can’t post more than 2 imgs. This is what I’m shooting for: