2
\$\begingroup\$

I am working on a lighting system for my game. Instead of lighting each tile completely with only one color, I want to create a gradient on that tile so to make the lighting look more dynamic and nicer.

I am using C# and Monogame (DirectX). Each tile is drawn as a Texture2D with this call:

spriteBatch.Draw(
    Block.getBlockByID(blockID).getTexture(side),
    new Rectangle(x * 28 - offx, y * 28 - offy, 28, 28),
    color
);

The first parameter gets the texture to use and the second one places the texture down. The third one is a pre-calculated Color which shades the texture that color. How can I replace that Color with a gradient?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ you could probably use a shader for that \$\endgroup\$ Oct 11, 2014 at 13:58
  • \$\begingroup\$ Yeah, I don't have any experience with shaders, all I really do know is that they change the pixels on the screen etc. \$\endgroup\$
    – Zambonie
    Oct 11, 2014 at 20:29
  • \$\begingroup\$ Just use a regular texture that you draw on the whole screen. Have it completely black, and play on the alpha value to have more or less shadow in corresponding areas (0 -> no shadow 1-> pure black). Use linear interpolation to have smooth shadows, and you're done. \$\endgroup\$ Oct 11, 2014 at 23:14

1 Answer 1

2
\$\begingroup\$

The easiest thing would be to create a gradient in Photoshop/Paint.NET/GIMP/whatever you use and blend that with your tile(s).

If you want a more procedural approach, then take a look at Color.Lerp. A gradient with that method is simple. The first color parameter is the light shade, the second is the final dark shade and the progress is the row/column of the texture data (depending on vertical/horizontal application of gradient) from 0 to width/height.

\$\endgroup\$

You must log in to answer this question.

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