XNA Lerp

I’m going to start blogging things that I find useful, so that I can find them again when I need them. You might find them useful too, with a bit of luck.

Lerp is a new thing in XNA 3.0. It lets you find colours between other colours. You can use it for blending, so that you can create a smooth range of colours from one extreme to another.  It is very easy to use:

Color newColor = Color.Lerp( firstColor, secondColor, amount );

You give it the first colour, the second colour and the amount you want to travel between them, in the range 0-1. If the amount is small (close to 0) you will get mostly first colour. If the amount is large (close to 1) you will get mostly second colour.

I use it to make darker versions of a particular colour, so I can create fake lighting effects:

Color shadowColor = Color.Lerp( objectColor, Color.Black, 0.2f );

This produces a darker version of objectColor. To make it even darker, increase the value 0.2 to a larger one.

You can use this to produce tinting effects too.