Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Direct3D Rendering Cookbook
  • Table Of Contents Toc
Direct3D Rendering Cookbook

Direct3D Rendering Cookbook

4.1 (10)
close
close
Direct3D Rendering Cookbook

Direct3D Rendering Cookbook

4.1 (10)

Overview of this book

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

Calculating an image's luminance histogram


In this recipe we will explore using a compute shader to gather characteristics from the source image and output to a buffer. The characteristic that we will be determining is the image's luminance histogram, that is, how many texels are there within the texture for each luminance value (mapped from 0.0-1.0 to 0-255).

We will also cover how to retrieve the data from the GPU and load it into an array that is accessible from the CPU.

How to do it…

We'll begin with the HLSL code necessary to calculate the histogram.

  1. The input continues to be a Texture2D SRV; however, this time our output UAV will be RWByteAddressBuffer.

    Texture2D<float4> input : register(t0);
    RWByteAddressBuffer outputByteBuffer : register(u0);
    #define THREADSX 32
    #define THREADSY 32
    // used for RGB/sRGB color models
    #define LUMINANCE_RGB float3(0.2125, 0.7154, 0.0721)
    #define LUMINANCE(_V) dot(_V.rgb, LUMINANCE_RGB)
  2. Our actual compute shader is quite simple:

    // Calculate the luminance...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Direct3D Rendering Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon