Graphics Reference
In-Depth Information
Getting ready
For this recipe, we will start with the project from the previous recipe, Benchmarking
multithreaded rendering . The scene file named Scene.fbx , used in the example
screenshots, is available from the companion source download for this topic. The completed
project can also be found in the companion source named Ch09_02DynamicCubeMapping .
How to do it…
We will begin by creating the necessary HLSL code to generate and consume our cube maps.
Generating the cube map will involve creating a new vertex shader ( VS_CubeMap ), geometry
shader ( GS_CubeMap ), and pixel shader ( PS_CubeMap ); to consume cube maps, we will
update the PerMaterial constant buffer and each pixel shader.
1.
Firstly, we will update the PerMaterial constant buffer in Shaders\Common.hlsl
to include a flag indicating whether a material is reflective and how reflective it is.
This will be used by the pixel shaders.
cbuffer PerMaterial : register (b2)
{...
bool IsReflective;
float ReflectionAmount;
...};
Remember that HLSL structures are 16-byte aligned.
2.
Create a new HLSL source file named Shaders\CubeMap.hlsl , and ensure that
it has the correct encoding as described in Chapter 2 , Rendering with Direct3D .
Add the following include directive to use our existing constant buffers, vertex,
and pixel structures:
#include "Common.hlsl"
3.
Add the following per environment map constant buffer to be updated using the
fifth buffer slot, and define the geometry shader input to be the same as the pixel
shader input:
// Cube map ViewProjections for each face
cbuffer PerEnvironmentMap : register(b4) {
float4x4 CubeFaceViewProj[6];
};
// Use the PixelShaderInput as GeometryShaderInput
#define GeometryShaderInput PixelShaderInput
 
Search WWH ::




Custom Search