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

Implementing displacement decals


In this recipe, we will be creating a displacement decal in order to add dynamic detail to a mesh on the GPU in real-time. This technique combines hardware tessellation and displacement to implement local mesh deformations such as footsteps, bullet holes, and craters.

Getting reading

We are using three new textures that are available in the downloaded content for this recipe, Crater_Diffuse.png, Crater_Displacement.png, and Crater_Normal.png. The completed project can be found in the companion code Ch06_02DisplacementDecals.

How to do it…

We will begin by creating our new Shaders\CommonDecal.hlsl HLSL shader file. This will introduce a new constant buffer to hold the necessary information that will be applied to our decal, include the texture references we need, and house the functions to calculate our decal's displacement:

  1. First, create a new HLSL file, Shaders\CommonDecal.hlsl; be sure to change the encoding or copy an existing HLSL file and clear the contents...