Direct3D Rendering Cookbook

Book description

For C# .NET developers this is the ultimate cookbook for Direct3D rendering in PC games. Covering all the latest innovations, it teaches everything from debugging to character animation, supported throughout by illustrations and sample code.

In Detail

The latest 3D graphics cards bring us amazing visuals in the latest games, from Indie to AAA titles. This is made possible on Microsoft® platforms including PC, Xbox consoles, and mobile devices thanks to Direct3D ? a component of the DirectX API dedicated to exposing 3D graphics hardware to programmers. Microsoft DirectX is the graphics technology powering all of today's hottest games. The latest version - DirectX 11 - features tessellation for film-like geometric detail, compute shaders for custom graphics effects, and improved multithreading for better hardware utilization. With it comes a number of fundamental game changing improvements to the way in which we render 3D graphics.

Direct3D Rendering Cookbook provides detailed .NET examples covering a wide range of advanced 3D rendering techniques available in Direct3D 11.2. With this book, you will learn how to use the new Visual Studio 2012 graphics content pipeline, how to perform character animation, how to use advanced hardware tessellation techniques, how to implement displacement mapping, perform image post-processing, and how to use compute shaders for general-purpose computing on GPUs.

After covering a few introductory topics about Direct3D 11.2 and working with the API using C# and SharpDX, we quickly ramp up to the implementation of a range of advanced rendering techniques, building upon the projects we create and the skills we learn in each subsequent chapter. Topics covered include using the new Visual Studio 2012 graphics content pipeline and graphics debugger, texture sampling, normal mapping, lighting and materials, loading meshes, character animation (vertex skinning), hardware tessellation, displacement mapping, using compute shaders for post-process effects, deferred rendering, and finally bringing all of this to Windows Store Apps for PC and mobile. After completing the recipes within Direct3D Rendering Cookbook, you will have an in-depth understanding of a range of advanced Direct3D rendering topics.

What You Will Learn

  • Set up a Direct3D application and perform real-time 3D rendering with C# and SharpDX
  • Learn techniques for debugging your Direct3D application
  • Render a 3D environment with lights, shapes, and materials
  • Explore character animation using bones and vertex skinning
  • Create additional surface detail using tessellation with displacement mapping and displacement decals
  • Implement image post-processing tasks within compute shaders
  • Use real-time deferred rendering techniques to implement improved shading for lighting and shadows
  • Learn to Program the graphics pipeline with shaders using HLSL implemented by Shader Model 5

Table of contents

  1. Direct3D Rendering Cookbook
    1. Table of Contents
    2. Direct3D Rendering Cookbook
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Getting Started with Direct3D
      1. Introduction
        1. Components of Direct3D
          1. Device
          2. Device context
            1. Immediate context
            2. Deferred context
          3. Command lists
          4. Swap chains
          5. States
          6. Resources
            1. Textures
            2. Resource views
            3. Buffers
          7. Shaders and High Level Shader Language
        2. Stages of the programmable pipeline
          1. The graphics pipeline
            1. Input Assembler (IA) stage
            2. Vertex Shader (VS) stage
            3. Hull Shader (HS) stage
            4. Tessellator stage
            5. Domain Shader (DS) stage
            6. Geometry Shader (GS) stage
            7. Stream Output (SO) stage
            8. Rasterizer stage (RS)
            9. Pixel Shader (PS) stage
            10. Output Merger (OM) stage
          2. The dispatch pipeline
            1. Compute Shader (CS) stage
      2. Introducing Direct3D 11.1 and 11.2
        1. Direct3D 11.1 and DXGI 1.2 features
        2. Direct3D 11.2 and DXGI 1.3 features
      3. Building a Direct3D 11 application with C# and SharpDX
        1. Getting ready
        2. How to do it…
        3. How it works…
          1. Initialization
          2. Render loop
          3. Finalization
        4. There's more…
        5. See also
      4. Initializing a Direct3D 11.1/11.2 device and swap chain
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      5. Debugging your Direct3D application
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
    9. 2. Rendering with Direct3D
      1. Introduction
      2. Using the sample rendering framework
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. See also
      3. Creating device-dependent resources
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Creating size-dependent resources
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      5. Creating a Direct3D renderer class
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. See also
      6. Rendering primitives
        1. Getting ready
        2. How to do it…
        3. How it works…
          1. Resource Initialization
          2. Render loop
          3. Renderers
        4. There's more…
        5. See also
      7. Applying multisample anti-aliasing
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. See also
      8. Implementing texture sampling
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. See also
    10. 3. Rendering Meshes
      1. Introduction
      2. Rendering a cube and sphere
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      3. Preparing the vertex and constant buffers for materials and lighting
        1. Getting ready
        2. How to do it…
        3. How it works…
          1. Using C# structures with HLSL constant buffers
        4. See also
      4. Adding material and lighting
        1. Getting ready
        2. How to do it…
          1. Implementing diffuse shaders
          2. Implementing Phong shaders
          3. Implementing Blinn-Phong shaders
        3. How it works…
          1. UV mapping
          2. Lighting
        4. There's more…
        5. See also
      5. Using a right-handed coordinate system
        1. How to do it…
        2. How it works…
        3. See also
      6. Loading a static mesh from a file
        1. Getting ready
        2. How to do it…
          1. Mesh Renderer
        3. How it works…
        4. There's more…
        5. See also
    11. 4. Animating Meshes with Vertex Skinning
      1. Introduction
      2. Preparing the vertex shader and buffers for vertex skinning
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      3. Loading bones in the mesh renderer
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      4. Animating bones
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
    12. 5. Applying Hardware Tessellation
      1. Introduction
      2. Preparing the vertex shader and buffers for tessellation
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Tessellating a triangle and quad
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      4. Tessellating bicubic Bezier surfaces
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
          1. Parametric surfaces
        5. See also
      5. Refining meshes with Phong tessellation
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      6. Optimizing tessellation through back-face culling and dynamic Level-of-Detail
        1. Getting ready
        2. How to do it…
          1. Back-face culling using face normal vectors
          2. Back-face culling using vertex normal vectors
          3. Dynamic Level-of-Detail (LoD) near silhouettes
        3. How it works…
        4. There's more…
        5. See also
    13. 6. Adding Surface Detail with Normal and Displacement Mapping
      1. Introduction
      2. Referencing multiple textures in a material
        1. How to do it…
        2. How it works…
      3. Adding surface detail with normal mapping
        1. Getting ready
        2. How to do it...
        3. How it works…
        4. There's more…
        5. See also
      4. Adding surface detail with displacement mapping
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more…
        5. See also
      5. Implementing displacement decals
        1. Getting reading
        2. How to do it…
        3. How it works…
        4. There's more…
      6. Optimizing tessellation based on displacement decal (displacement adaptive tessellation)
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
    14. 7. Performing Image Processing Techniques
      1. Introduction
      2. Running a compute shader – desaturation (grayscale)
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      3. Adjusting the contrast and brightness
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      4. Implementing box blur using separable convolution filters
        1. How to do it…
        2. How it works…
        3. There's more…
      5. Implementing a Gaussian blur filter
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      6. Detecting edges with the Sobel edge-detection filter
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      7. Calculating an image's luminance histogram
        1. How to do it…
        2. How it works…
        3. There's more…
    15. 8. Incorporating Physics and Simulations
      1. Introduction
      2. Using a physics engine
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      3. Simulating ocean waves
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      4. Rendering particles
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
    16. 9. Rendering on Multiple Threads and Deferred Contexts
      1. Introduction
      2. Benchmarking multithreaded rendering
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      3. Implementing multithreaded dynamic cubic environment mapping
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      4. Implementing dual paraboloid environment mapping
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. See also
    17. 10. Implementing Deferred Rendering
      1. Introduction
      2. Filling the G-Buffer
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      3. Implementing a screen-aligned quad renderer
        1. How to do it…
        2. How it works…
        3. There's more…
        4. See also
      4. Reading the G-Buffer
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. See also
      5. Adding multiple lights
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      6. Incorporating multisample anti-aliasing
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
    18. 11. Integrating Direct3D with XAML and Windows 8.1
      1. Introduction
      2. Preparing the swap chain for a Windows Store app
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. See also
      3. Rendering to a CoreWindow
        1. How to do it…
        2. How it works…
        3. There's more…
        4. See also
      4. Rendering to an XAML SwapChainPanel
        1. How to do it…
        2. How it works…
        3. There's more…
        4. See also
      5. Loading and compiling resources asynchronously
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
    19. A. Further Reading
    20. Index

Product information

  • Title: Direct3D Rendering Cookbook
  • Author(s): Justin Stenning
  • Release date: January 2014
  • Publisher(s): Packt Publishing
  • ISBN: 9781849697101