2
votes

I have a 2D tile-based lighting system which is drawn onto a Render Target. I am also drawing a background which involves mountains, sun/moon, and clouds. There is also the unlit game; blocks, character, etc.

Here is the order in which everything is drawn:

1. Background
2. Game World
3. Lighting

The problem is that the LIGHTING is covering up the BACKGROUND when it's dark:

The moon and background is covered by darkness.

Although it's perfectly fine in the day because the light is full: The alpha of the light is 1, so the background is visible

You might ask, well, why don't you just blend each block, not drawing the lighting on a RenderTarget?

Because that would prevent me from performing smooth lighting, as seen in the pictures. To produce the smooth lighting, I draw squares of light onto a RenderTarget, perform a Gaussian blur and then draw that RenderTarget.

How about not drawing a square of light in empty spaces?

The light blurs onto any adjacent blocks, and not all objects in my game affected by lighting are square, so they would look like a sprite with a blurry square on top of it.

Light NOT being drawn in empty spaces: Light NOT being drawn in empty spaces

Light being drawn everywhere: Light being drawn everywhere

Is there any way to keep the background visible, or something else that would help my predicament?

1
I have no idea what you are actually asking, or what the screen shot is trying to show. - asawyer
The light darkens the background. - ben
I was about to ask the exact same question, this is a problem with stars and the moon in my game's background, they end up grayish when they should be bright because of the darkness of the lighting. - Cyral
Oh heeeeey I saw your smooth lighting question! Although actually I ended up using gaussian blur rather than the method described in your question's answer. - ben
well absence of light is darkening background? that seems right to me, but if you want to see something add ambient light and or use less strict blurring. Also shadows should not go underground ... it looks ugly that way. Btw what about do it like in real world (not darken color if no light but enhance intensity on presence of light) - Spektre

1 Answers

0
votes

I'd suggest you do the following:

  • Render lighting to rendertarget
  • Render scene to rendertarget (leave the background transparent)
  • Multiply scene with the lighting rendertarget
  • Render background to screen
  • Render scene (with the lighting already applied) to the screen

Because the background is added after applying the lighting, it will not be affected.