Jump to content
  • Advertisement
Sign in to follow this  
Florian22222

ID3D10Texture2D->Map issue

This topic is 2515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!

I want to read the color values from a texture(heightmap) to compute the height of my terrain. But the value is either incredibly high or 0.0f.
Here´s the code:

D3DX10_IMAGE_LOAD_INFO loadInfo;
ZeroMemory( &loadInfo, sizeof(D3DX10_IMAGE_LOAD_INFO) );
loadInfo.Format = DXGI_FORMAT_BC1_UNORM;
loadInfo.Height = m_Height;
loadInfo.Width = m_Width;
loadInfo.CpuAccessFlags = D3D10_CPU_ACCESS_READ;
loadInfo.Usage = D3D10_USAGE_STAGING;
loadInfo.MipLevels = 1;
ID3D10Resource *pResource;
D3DX10CreateTextureFromFile( m_pd3dDevice, m_HeightfieldTextureFilename, &loadInfo, NULL, &pResource, NULL );
m_pHeightfieldTexture = (ID3D10Texture2D *) pResource;
D3D10_MAPPED_TEXTURE2D mappedTexture;
m_pHeightfieldTexture->Map(D3D10CalcSubresource(0,0,1),D3D10_MAP_READ,0,&mappedTexture);
FLOAT* pTexels = (FLOAT*)mappedTexture.pData;
int verticesCount = 0;
for(UINT z = 0;z<=m_Height;z++)
{
UINT rowStart = z * mappedTexture.RowPitch/4;
for(UINT x = 0;x<=m_Width;x++)
{
float y = pTexels[rowStart + x*4 + 0] + pTexels[rowStart + x*4 + 1] + pTexels[rowStart + x*4 + 2];
/*float y = 0.0f;*/
m_pVertices[verticesCount].position = D3DXVECTOR3(x,y,z);
m_pVertices[verticesCount].texcoord = D3DXVECTOR2((float)x,(float)x);
verticesCount++;
}
}
m_pHeightfieldTexture->Unmap(0);
m_pHeightfieldTexture->Release();


Attached you´ll find a screenshot that shows what the result looks like.
I hope you can help me biggrin.png

Share this post


Link to post
Share on other sites
Advertisement
Your texture is using a compressed RGBA format (BC1), yet you're interpreting it as if it were 32-bit floats. You should just load it as a FLOAT format, since you're not even using it on the GPU.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!