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

Reading the G-Buffer


In this recipe, we will look at the HLSL shader code necessary to read from the G-Buffer's resources. We will then use the screen-aligned quad to implement a debug pixel shader for displaying information from the G-Buffer to screen.

Getting ready

We will follow on from where we left off with Filling the G-Buffer using the same G-Buffer layout as described in that recipe, and make use of the screen-aligned quad from Implementing a screen-aligned quad renderer.

How to do it…

First let's begin by outlining the HLSL code necessary to extract the attributes from the G-Buffer.

  1. We'll start by defining a structure to store the loaded G-Buffer attributes in, as shown in the following HLSL code snippet:

    // Structure for holding loaded G-Buffer attributes
    struct GBufferAttributes
    {
        float3 Position;
        float3 Normal;
        float3 Diffuse;
        float SpecularInt; // specular intensity
        float3 Emissive;
        float SpecularPower;
    };
    // Screen-aligned Quad PixelIn
    struct PixelIn
    {
      ...