Book Image

Direct3D Rendering Cookbook

Book Image

Direct3D Rendering Cookbook

Overview of this book

Table of Contents (19 chapters)
Direct3D Rendering Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Further Reading
Index

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.

  1. 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...