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:

    new Rectangle(x * 28 - offx, y * 28 - offy, 28, 28),

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?

  • 1
    \$\begingroup\$ you could probably use a shader for that \$\endgroup\$ – ratchet freak Oct 11 '14 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 '14 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\$ – GameAlchemist Oct 11 '14 at 23:14

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.