Graphics Reference
In-Depth Information
// Store the height/width to the param manager
D3D11_TEXTURE2D_DESC d = mjDHeightMapTexture->rn_pTexture2dConfig->GetTextureDesc();
Vector4f vTexDim = Vector4f (
static_cast<float>(d. Width)
, static_cast<float>(d. Height)
, static_cast<float>(TERRAIN_X_LEN)
, static_cast<float>(TERRAIN_Z_LEN)
);
m_pRendererll->m_pParamMgr->SetVectorParameter( L"heightMapDimensions", &vTexDim );
// Create the SRV
ShaderResourceParameterDXll* pHeightMapTexParam = new ShaderResourceParameterDXllQj
pHeightMapTexParam->SetParameterData( &m_pHeightMapTexture->m_iResourceSRV ) ;
pHeightMapTexParam- >SetName( std::wstring( L"texHeightMap" ) );
II Map it to the param manager
m_pRendererll->m_pParamMgr->SetShaderResourceParameter
( L"texHeightMap"j m_pHeightMapTexture );
// Create a sampler
D3D11_SAMPLER_DESC sampDesc;
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
sampDesc. BorderColor[0] =
sampDesc.BorderColorfl] =
sampDesc. BorderColor[2] =
sampDesc. BorderColor[3] = 0;
sampDesc. ComparisonFunc = D3D11_C0MPARIS0N_ALWAYS;
sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sampDesc. MaxAnisotropy = 16 ;
sampDesc. MaxLOD = D3D11_FL0AT32_MAX;
sampDesc. MinLOD = 0.0fj
sampDesc. MipLODBias = 0.0f;
int samplerState = m_pRendererll->CreateSamplerState( SsampDesc );
// Set it to the param manager
m_pRendererll->m_pParamMgr->SetSamplerParameter( L"smpHeightMap", SsamplerState );
Listing 9.3. Loading the heightmap as a texture.
Care needs to be taken when matching the size of the heightmap to the geometry be-
ing created. Keeping the heightmap 4-8 times larger than the underlying geometry typically
works well. If it is less than this, the tessellation introduces very little new detail, and if it is
much higher, this can lead to quite substantial differences between neighboring LODs. This
consideration about sampling rate is a general one for tessellation—if extra generated geom-
etry has no higher-frequency data to represent, there is little if any benefit in adding it. The ex-
ample code for this uses a 512x512 monochrome texture for rendering a grid of 32x32 tiles.
Assuming successful execution of the previously described code, the application has
now created all of the resources required for rendering.
Search WWH ::




Custom Search