View Full Version : Inverting a 2D polygon drawing area

06-06-2013, 04:13 PM
Hi there,
I'm working on a simple 2D lighting system. I'm attempting to make a cone 'light' area, wherein the objects within are drawn normally. Outside of this cone of light, a black overlay with 0.5f alpha will be drawn, causing all drawn objects outside the cone to appear darker. Imagine a torch in 2D. See the below diagram:

So the way I was thinking of going about this was to somehow specify an inverse cone of light, and draw it with an alpha level of 0.5f and a black color after drawing my objects, like a dark semi-transparent overlay. That should work in theory, but I have no idea how to specify this inverted cone of light!

Any help would be much appreciated.

An alternative would be just as good, as I'm not sure I'm going down the right path here. I have experimented with different blending modes, with no luck.

Thanks in advance!

06-07-2013, 05:11 AM
Aren't you able to do proper lighting in shaders and just assign all unlit objects a default medium gray ambient intensity?

carsten neumann
06-07-2013, 09:04 AM
Alternatively, write to the stencil buffer (but not the color/depth buffers) when drawing the light cone. Then draw the full screen overlay and only write to the color buffer where the stencil buffer is zero.