3
\$\begingroup\$

I'm trying to make a searchlight-style punchout mask effect in Unity 2D. This is the effect I'm looking for:

Animated searchlight mask over map

That animation is made in Fireworks, using a white to black gradient circle masked on top of the map image below it. Here's a single frame for closer viewing.

How can I create this effect in Unity?

So far, I have a separate camera that only renders the white circle using a culling mask, but I'm not sure what to do from there.

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

Why not use built in support for lighting in Unity? Spot light would do exactly the effect you need. Unity 2D "mode" is a bit tricky conserning the lighting:

You'll need to add a material to your sprites for this which uses the Sprites Diffuse shader. As standard, sprites don't support lighting as we expect users to use them unlit and use lighting baked into the sprite design itself.

Simply make a material, assign it to the sprite, and choose the Sprites Diffuse shader from the material.

and also, from the linked thread:

Resurrecting this thread for anyone still looking for solutions for the binary lighting thing, just figured it out myself. Two important things to check:

1) Is the light's render mode set to "Important"? This should fix the issues with scaled stuff.

2) Are you using scaling or rotation to flip your sprites? Sprite renderers work like textured planes, they only receive light on one side. If you rotate the characters to mirror their direction then the renderer is suddenly facing away from the light, but if you just scale the object by -1 you can flip the character without flipping the renderer's normal.

\$\endgroup\$
0
\$\begingroup\$

The simplest way by far is this: create a transparent sprite with your circle "cut out", and opaque black along the sides. Then put in on top layer above everything else.

You might also want to attach 8 fully opaque black sprites to all sides of the circle, so that areas completely outside of it are masked too.

This would only work if you need to mask the entire screen (or entire screen except some layers such as UI). If you have some more complex configuration in mind, I'd look at a custom shader to render the mask. You only need to put a single quad over your masked area, and then in the shader change alpha to what you need, where you need it.

\$\endgroup\$
1
  • \$\begingroup\$ I ended up having to render the lights onto one camera, then using a render texture from FXLab painted onto a quad attached to the main camera, with a custom shader that converted luminosity to alpha. i.imgur.com/aMiVNze.png \$\endgroup\$
    – Mr Dreigon
    Aug 8, 2014 at 15:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .