(Video inside) Weird transparency issue with procedurally generated mesh

Started by
6 comments, last by VanillaSnake21 5 years, 2 months ago

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?

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

Advertisement

Would posting more code help?

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

Are you doing anything to enable depth writing and testing? I don't see anything in your posted code? If not, that's probably the problem.

On 2/15/2019 at 11:28 PM, VanillaSnake21 said:

Any ideas why this might be happening?

Unfortunately no (I don't know Direct3D at all and I'm also not enough of a 3D graphics expert in general, I fear), but I noticed something which could perhaps be of help:

You wrote that the error depends on the camera angle, but I think it looks like it actually depends on the camera position: The tiles that are wrongly rendered over the "spikes" are always right of the current camera position. The pattern doesn't change when you rotate the camera, it changes when you move it. Apart from that, I think it's some kind of z-buffer (depth write/test) error, as Irusan has already stated. However, I have no idea what exactly is wrong. It looks really weird and unlike anything I've ever seen.

It seems you are dependant on the order of the triangles processed/drawn

Does it work if you turn off blending?

12 hours ago, Irusan, son of Arusan said:

Are you doing anything to enable depth writing and testing? I don't see anything in your posted code? If not, that's probably the problem.

Yes, this was it. I didn't have the depth buffer set in the output merger, thank you!

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

This topic is closed to new replies.

Advertisement