Adjusting the contrast and brightness
In this recipe we will adjust the contrast of the image by interpolating the color towards or away from gray, and adjusting the brightness by adding or removing the black color from the image. By moving the colors closer to gray (0.5, 0.5, 0.5), we are reducing the contrast, and by moving away in the positive direction we are increasing the contrast. Reducing the contrast by 100 percent will result in a totally gray image, while reducing by 200 percent, generates a negative image.
Getting ready
Begin with the resulting code from the previous recipe to adjust the color saturation levels, including the There's more… section for the interpolation of the source and target values.
How to do it…
First we will implement the contrast adjustment shader.
As we did in the Running a compute shader – desaturation (grayscale) recipe earlier in this chapter, add the following HLSL shader code to a string variable such as
hlslCode
. This will form our compute shader:Texture2D...