Book Image

Direct3D Rendering Cookbook

By : Justin Stenning, Justin Stenning
Book Image

Direct3D Rendering Cookbook

By: Justin Stenning, Justin Stenning

Overview of this book

Table of Contents (19 chapters)
Direct3D Rendering Cookbook
About the Author
About the Reviewers
Further Reading

Preparing the vertex and constant buffers for materials and lighting

In this recipe, we will update the vertex and pixel shader structures and our constant buffers to provide additional information that our vertex shader and pixel shader need to be able to perform material and lighting operations.

After extending our per object constant buffer to support the transformation of the normal vector and position into world space, we will also add a per frame constant buffer that will contain our camera position and light configuration. How to create C# structures that reflect the HLSL constant buffers is also covered.

Our vertex shader input structure will be changed to accept the normal vector and UV coordinates from the previous recipe, and then update the pixel shader input structure to receive the normal vector transformed to world space in addition to the world space position and the UV coordinates.

As our shaders are becoming more complex, we will split them into multiple files; to support...