I'm having a weird issue with what appears to be transparency, but I'm not sure exactly what's causing it. Parts of the mesh get hidden by other parts of the mesh that are supposed to be behind it, however it only happens at certain camera angles. Here is a brief video of that happening.
The towers get hidden by the floor at certain angles of the camera.
Here is some code from the rasterizer states and the mesh generation.
D3D10_RASTERIZER_DESC rasterizerState;
rasterizerState.CullMode = D3D10_CULL_BACK;
rasterizerState.FillMode = D3D10_FILL_SOLID;
rasterizerState.FrontCounterClockwise = false;
//....
D3D10_BLEND_DESC BlendState;
ZeroMemory(&BlendState, sizeof(D3D10_BLEND_DESC));
BlendState.BlendEnable[0] = TRUE;
BlendState.SrcBlend = D3D10_BLEND_SRC_ALPHA;
BlendState.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
BlendState.BlendOp = D3D10_BLEND_OP_ADD;
BlendState.SrcBlendAlpha = D3D10_BLEND_ZERO;
BlendState.DestBlendAlpha = D3D10_BLEND_ZERO;
BlendState.BlendOpAlpha = D3D10_BLEND_OP_ADD;
BlendState.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
struct MeshVertex
{
XMFLOAT3 pos;
XMFLOAT2 uv;
};
//allocate space for the mesh
MeshVertex* floorMesh = new MeshVertex[bmpWidth*bmpHeight];
//load the height map texture
SoftwareBitmap::Bitmap heightMap(pathToHeightmap);
int bmpHeight = heightMap.GetHeight();
int bmpWidth = heightMap.GetWidth();
//set vertecies in a grid and trasnfer height data to vertex's y value
UCHAR* source_mem = (UCHAR*)heightMap.GetData();
for (int xdim = 0; xdim < bmpWidth; xdim++)
{
for (int zdim = 0; zdim < bmpHeight; zdim++)
{
float height = source_mem[xdim + zdim*heightMap.GetPitch()];
float color = (height)/ 255.0f;
floorMesh[xdim + zdim*bmpWidth] = { XMFLOAT3((float)xdim, height , (float)zdim), XMFLOAT2(float(xdim)/ bmpWidth, float(zdim)/ bmpHeight)};
}
}
Any ideas why this might be happening?