A helping hand for bedroom coders throughout the land.
Gradient Mapping

Gradient mapping is a feature you will know about if you're a Photoshop user. The basic principle is to take an image, convert it to greyscale, then use each pixel's brightness as a lookup value from a texture1d. This texture1d in photoshop is generated from a built in gradient editor. To implement this in XNA using a pixel shader is a very straight forward task. Just generate out a 1d gradient texture (from your graphics package of choice). Now in the shader, as we are working with normalised values we can pass in the greyscale value of a pixel (which will be between 0 and 1) into the sampler lookup function which considers a textures width to be 1.The gradient map is then sampled based on the brightness of the image, which results in the process you can see below. Using gradients can be very useful for a range of tasks, so if you wanted to extend this system you could make some sort of gradient editor.

Download the sample


Posted Sat, Apr 24 2010 2:41 PM by Barnaby Smith
Filed under: , , ,

Comments

passing through... wrote re: Gradient Mapping
on Tue, May 18 2010 11:25 AM

Thank you for this. It helped me quickly implement a nice rendering of ghosted structures being built in the strategy game I am working on.