• Create Account

### #Actualsimpler

Posted 24 October 2012 - 05:06 PM

Thanks for the answers! I got it working now with D3D11_MAP_WRITE_DISCARD but it's really slow since the entire terrain vertex buffer has to be built each frame when the terrain tool is used. It's a very small part of the terrain that needs to get updated so there got to be a better way to do this, being able to not use DISCARD would probably be the best solution. Then I only have to change the vertices that gets affected. Or do you have any other suggestions?

Right now I'm doing this every frame with the grid size being 257x257

// Get the vertices.
ID3D11DeviceContext* context = GetD3DContext();
D3D11_MAPPED_SUBRESOURCE resource;
HRESULT hr = context->Map(mPrimitive->GetVertices(), 0, D3D11_MAP_WRITE_DISCARD, 0, &resource);

Vertex* v = reinterpret_cast<Vertex*>(resource.pData);
for(UINT i = 0; i < m; ++i)
{
float z = halfDepth - i*dz;
for(UINT j = 0; j < n; ++j)
{
float x = -halfWidth + j*dx;
v[i*n+j].Pos = XMFLOAT3(x, GetHeight(x, z), z);//GetHeight(x, z)
v[i*n+j].Normal  = XMFLOAT3(0, 1, 0);
v[i*n+j].Tangent = XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
v[i*n+j].Tex.x  = j*du;
v[i*n+j].Tex.y  = i*dv;

//mVertices[i*n+j] = v[i*n+j];
}
}
context->Unmap(mPrimitive->GetVertices(), 0);


And it doesn't feel that optimal.

### #2simpler

Posted 24 October 2012 - 05:06 PM

Thanks for the answers! I got it working now with D3D11_MAP_WRITE_DISCARD but it's really slow since the entire terrain vertex buffer has to be built each frame when the terrain tool is used. It's a very small part of the terrain that needs to get updated so there got to be a better way to do this, being able to not use DISCARD would probably be the best solution. Then I only have to change the vertices that gets affected. Or do you have any other suggestions?

Right now I'm doing this every frame with the grid size being 257x257

// Create the vertices.
ID3D11DeviceContext* context = GetD3DContext();
D3D11_MAPPED_SUBRESOURCE resource;
HRESULT hr = context->Map(mPrimitive->GetVertices(), 0, D3D11_MAP_WRITE_DISCARD, 0, &resource);

Vertex* v = reinterpret_cast<Vertex*>(resource.pData);
for(UINT i = 0; i < m; ++i)
{
float z = halfDepth - i*dz;
for(UINT j = 0; j < n; ++j)
{
float x = -halfWidth + j*dx;
v[i*n+j].Pos = XMFLOAT3(x, GetHeight(x, z), z);//GetHeight(x, z)
v[i*n+j].Normal  = XMFLOAT3(0, 1, 0);
v[i*n+j].Tangent = XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
v[i*n+j].Tex.x  = j*du;
v[i*n+j].Tex.y  = i*dv;

//mVertices[i*n+j] = v[i*n+j];
}
}
context->Unmap(mPrimitive->GetVertices(), 0);


And it doesn't feel that optimal.

### #1simpler

Posted 24 October 2012 - 05:06 PM

Thanks for the answers! I got it working now with D3D11_MAP_WRITE_DISCARD but it's really slow since the entire terrain vertex buffer has to be built each frame when the terrain tool is used. It's a very small part of the terrain that needs to get updated so there got to be a better way to do this, being able to not use DISCARD would probably be the best solution. Then I only have to change the vertices that gets affected. Or do you have any other suggestions?

Right now I'm doing this with the grid size being 257x257

// Create the vertices.
ID3D11DeviceContext* context = GetD3DContext();
D3D11_MAPPED_SUBRESOURCE resource;
HRESULT hr = context->Map(mPrimitive->GetVertices(), 0, D3D11_MAP_WRITE_DISCARD, 0, &resource);

Vertex* v = reinterpret_cast<Vertex*>(resource.pData);
for(UINT i = 0; i < m; ++i)
{
float z = halfDepth - i*dz;
for(UINT j = 0; j < n; ++j)
{
float x = -halfWidth + j*dx;
v[i*n+j].Pos = XMFLOAT3(x, GetHeight(x, z), z);//GetHeight(x, z)
v[i*n+j].Normal  = XMFLOAT3(0, 1, 0);
v[i*n+j].Tangent = XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
v[i*n+j].Tex.x  = j*du;
v[i*n+j].Tex.y  = i*dv;

//mVertices[i*n+j] = v[i*n+j];
}
}
context->Unmap(mPrimitive->GetVertices(), 0);


And it doesn't feel that optimal.

PARTNERS