2
\$\begingroup\$

I'm working on a lighting system for a tile-based game.

What I want to do is draw my tiles to the screen, then draw a single Texture2D object (my light map) over top of them. However, doing it in two steps results in the tiles looking "painted" and washed out.

To get this effect working, I called Texture2D.GetData() and then used that Color as the blending color when calling SpriteBatch.Draw() on each tile, which results in them being "tinted" correctly. This works, but it's a fair bit slower, and won't scale up for huge maps/view areas.

So, is it possible to use a BlendState object to do what I am doing above?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Additive blending should do what you are trying to achieve. \$\endgroup\$ Nov 23, 2015 at 0:27
  • \$\begingroup\$ I've tried all of the built-in BlendState objects, but they don't produce the results I'm trying for. In the third image, the areas that aren't lit up end up black - if I used additive blending, then Black (0,0,0) wouldn't affect the final image, and it just ends up looking like pic related: i.imgur.com/DVrKnW4.png \$\endgroup\$
    – Kyle Baran
    Nov 23, 2015 at 1:15
  • \$\begingroup\$ Turns out I did need additive blending, but also to adjust a few other blend settings too. Thanks! \$\endgroup\$
    – Kyle Baran
    Nov 23, 2015 at 4:05

1 Answer 1

1
\$\begingroup\$

I found the solution I was looking for. Since my light map used transparency, I simply used:

ColorSourceBlend = Blend.Zero;
ColorDestinationBlend = Blend.SourceAlpha;
ColorBlendFunction = BlendFunction.Add;

Had to adjust a few things to support it, but it works great.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Don't forget to mark your answer as accepted, so other users can see at a glance through the search results that the problem is solved. \$\endgroup\$
    – DMGregory
    Mar 23, 2016 at 13:16

You must log in to answer this question.

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