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
- Create two layers, say “normal” and “highlighted”. Every sprite will be in “normal” layer, but highlighted ones in “highlighted”.
- Set main camera’s culling mask to render only “normal”, and create secondary camera with higher depth that renders only “highlighted”.
- I downloaded this component - GitHub - keijiro/SpriteOutlineFx: Outline image effect for 2D sprites. - 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?