Graphics Reference
In-Depth Information
vertex and index buffers and texture resources representing the inputs to the pipeline, and
all remaining functionality will be implemented in HLSL shaders.
Tn this case, the vertex shader will be responsible for transforming model-space ge-
ometry into world-space and nothing else. The majority of the work will be done in the
hull shader constant function, which determines the LOD for the current patch, using the
patch being rendered, as well as its four immediate neighbors. The main hull shader stage
will then act as a simple pass-through of the four corner vertices for the current patch. The
domain shader will then take the tessellated points and will implement displacement map-
ping to generate the actual terrain geometry that will finally be rasterized.
Here are the steps for implementing the interlocking terrain tiles algorithm.
Step 1: Creating the Input Data
Three sources of input data need to be created for this algorithm to work: a vertex buffer,
and index buffer, and heightmap texture.
Listing 9.1 creates the vertex buffer. It is very straightforward, as it is simply a grid of
points that bounds new geometry generated in the space between these points.
// Set up the actual resource
SAFE_RELEASE( m_pTerrainGeometry );
m_pTerrainGeometry = new GeometryDXll( );
// Create the vertex data
VertexElementDXll *pPositions
= new VertexElementDXll ( 3, (TERRAIN_X_LEN + 1) * (TERRAIN_Z_LEN + 1) );
pPositions->m_SemanticName = "CONTR0L_P0INT_P0SITI0N";
pPositions->m_uiSemanticIndex = 0;
pPositions->m_Format = DXGI_FORMAT_R32G32B32_FLOAT;
pPositions->m_uiInputSlot = 0;
pPositions->m_uiAlignedByteOffset = 0;
pPositions->m_InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
pPositions->m_uiInstanceDataStepRate = 0;
VertexElementDXll *pTexCoords
= new VertexElementDX11 ( 2, (TERRAIN_X_LEN + 1) * (TERRAIN_Z_LEN + 1) );
pTexCoords->m_SemanticName = "C0NTR0L_P0INT_TEXC00RD";
pTexCoords->m_uiSemanticIndex = 0;
pTexCoords->m_Format = DXGI_FORMAT_R32G32_FLOAT;
pTexCoords->m_uiInputSlot = 0;
pTexCoords->m_uiAlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
pTexCoords->m_InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
pTexCoords->m_uiInstanceDataStepRate = 0;
Vector3f *pPosData = pPositions->Get3f ( 0 );
Vector2f *pTCData = pTexCoords->Get2f ( 0 );
float fWidth = static_cast< float >( TERRAIN_X_LEN );
Search WWH ::




Custom Search