Masking an overlay?

I’m looking to create an overlay with a portion cut out that has the natural rendering of the scene. This would be easy enough if the position of the object being highlighted were in one place, but the camera is movable.

So far I’ve found the solution seen [here][1], but it doesn’t really give me the option of a mutable center. To better illustrate what I am trying to achieve, please look at the images below. Here the scene has a blue overlay with the rounded rectangle cut out to show the region of interest. Each object is a different size, so the “hole” needs to be scalable:



I am working with the free version of Unity, so using something like GUI.DrawTexture is out of the question. Right now I’m just looking for a direction to head, so any suggestions would be appreciated.
[1]: Creating a Circular Progressbar / Timer - Unity Answers

I believe GUI.DrawTexture is available in the free version, though it doesn’t solve your problem directly.

We experimented with doing something similar to your question using a texture with a cutout that I dynamically resized to fit the object I wanted to highlight. The results were poor. With a soft edge, the results looked unprofessional. And a hard edge looked unprofessional if the texture had to be significantly stretched or compressed.

For our uses, the best solution turned out to be adjusting the Main Color of the materials in all the textures in scene. I would just darken all other objects, so the thing we wanted to highlight would pop out. Note this solution has the unfortunate side effect of breaking batching, and there are more performance friendly ways to make this darkening happen.

I do have an idea of how you might achieve this effect.

  • Turn all eight vertices of the Renderer.bounds for object into Screen coordinates.
  • Figure out the min/max for x and y out of the eight
  • Using a texture that is sized to be pixel perfect, set alpha to 0 for the pixels for the rect formed by the min/max values (plus a bit of padding).
  • Set the outline pixels to color/alpha as needed.
  • Display the texture in a pixel perfect way (there are several different possibilities).

Note a rectangle would be fairly easy. There were be more work for a rounded rect especially, if you wanted to anti-alias the corners.