Search Unity

Highlighting sprites with secondary camera

Discussion in 'General Graphics' started by Kaven01, Nov 1, 2019.

  1. Kaven01

    Kaven01

    Joined:
    Nov 22, 2017
    Posts:
    18
    So I have probably a very basic question, I have googled a lot, but I can't find solution. I have 2D scene composed of sprites, and I want some sprites to be visually highlighted by outline. After googling, it seemed to me that I should
    1) Create two layers, say "normal" and "highlighted". Every sprite will be in "normal" layer, but highlighted ones in "highlighted".
    2) Set main camera's culling mask to render only "normal", and create secondary camera with higher depth that renders only "highlighted".
    3) I downloaded this component - https://github.com/keijiro/SpriteOutlineFx - and added it to secondary camera. It is quite simple - in OnRenderImage() it blits source bitmap to destination using special material that creates outline around nontransparent pixels (determined by alpha).

    It sort of works - secondary camera renders only "highlighted" sprites, and draws outline around them correctly (so I am sure that downloaded material/shader works as it should). Problem is that result doesn't merge with underlying main camera. If secondary camera clears to skydome or solid color, it overwrites image of main camera. I see correctly highlighted sprites, but on blue/transparent backhground. If secondary camera clears only depth buffer or nothing at all, the main camera's image is not overwritten, but outline is drawn around everything. not just around "highlighted" sprites. Probably because when blitting with outlining material, the source already has full image rendered by main camera.

    Question - what should I do to outline highlighted sprites correctly? What am I missing about compositing camera image? Or is there a better way to do the highlighting?
     
  2. Deleted User

    Deleted User

    Guest

  3. Kaven01

    Kaven01

    Joined:
    Nov 22, 2017
    Posts:
    18
    It will be used to mark active object. Generally there are several entrances to next level, and you will have to choose one ... and because it will run on appleTV, you cannot click or tap on it. You have to first select the right one by cycling among them, and then confirm choice.

    There are more ways to do the highlight - by changing color of sprite (as they did in the link you provided), or moving some additional marker sprite over it. I can do that, but original idea was to make object outlined (or outlined with fade, so that it would look like outer glow). The object to be highlighted consists of several animated sprites, so the outline can't be done by single pre-made bitmap.