triangle culling in close proximity to other triangles?

Started by
9 comments, last by ddengster 7 years, 11 months ago

As you can see in the image, when my object partially intersects the ground, the triangles get culled (backface culling is on), which shouldnt happen. My best guess as to why this happens is that directx culls entire triangles when it detects a portion of the triangle behind another. Is this true, and how can i render these triangles even such that backface culling is still turned on?

Advertisement

Hello,

haha, it would probably help if I knew what I was looking at ;)

But have you ruled out the possibility of inverted normals on the mesh, with BF culling that would certainly create the issue of triangles not appearing...

Marcus Hansen

My best guess as to why this happens is that directx culls entire triangles when it detects a portion of the triangle behind another. Is this true, and how can i render these triangles even such that backface culling is still turned on?

It's not true. Depth testing happens on a per-pixel basis and is unrelated to backface culling.

It could be "z-fighting", which is where there's not enough precision in the depth buffer to properly tell which pixel is in front of each other. What is the format of your depth buffer resource, and what's the 'near' and 'far' values used in your projection matrix?

My best guess as to why this happens is that directx culls entire triangles when it detects a portion of the triangle behind another. Is this true, and how can i render these triangles even such that backface culling is still turned on?

It's not true. Depth testing happens on a per-pixel basis and is unrelated to backface culling.

It could be "z-fighting", which is where there's not enough precision in the depth buffer to properly tell which pixel is in front of each other. What is the format of your depth buffer resource, and what's the 'near' and 'far' values used in your projection matrix?

I'm using DXGI_FORMAT_D24_UNORM_S8_UINT.

Near - far distance is: 0.1 to 250, i tweaked it and still got the bugged results

Im going to guess it is a depth buffer issue. I would also run it through PIX or Nsight.to get more information.

Also, is that the Fruity Loops logo?

Post a screenshot of what it looks like when it doesn't intersect the ground (and presumably no triangles are erroneously culled).

the model is meant to a rock. the one in the middle is the rock floating in the air, the rest are touching the ground

At first I ruled out Depth Buffer issue, because as Hodge mentioned, Depth testing occurs at a per pixel level, not a per primitive level, so back face culling shouldn't be involved.

However, in the picture you just posted I do see what seems to be Z Fighting on your last rock.

A few questions,

1. Can we see your depth buffer creation code, preferably all the way up to you bind it to the Output Merger.

2. Are the Rock Models completely perpendicular to the ground model, or is the camera pitched at a 45d (0.78 in radians), or is the camera looking straight down the Y-Axis?

Marcus Hansen

At first I ruled out Depth Buffer issue, because as Hodge mentioned, Depth testing occurs at a per pixel level, not a per primitive level, so back face culling shouldn't be involved.

However, in the picture you just posted I do see what seems to be Z Fighting on your last rock.

A few questions,

1. Can we see your depth buffer creation code, preferably all the way up to you bind it to the Output Merger.

2. Are the Rock Models completely perpendicular to the ground model, or is the camera pitched at a 45d (0.78 in radians), or is the camera looking straight down the Y-Axis?

Marcus Hansen

1)


/************** Setup ************/
// Create depth stencils
  D3D11_TEXTURE2D_DESC descDepth;
  ZeroMemory(&descDepth, sizeof(D3D11_TEXTURE2D_DESC));
  descDepth.Width = texture2ddesc.Width;
  descDepth.Height = texture2ddesc.Height;
  descDepth.MipLevels = 1;
  descDepth.ArraySize = 1;
  descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; //24 bits for depth, 8 bits for stencil
  descDepth.SampleDesc.Count = 1;
  descDepth.SampleDesc.Quality = 0;
  descDepth.Usage = D3D11_USAGE_DEFAULT;
  descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
  descDepth.CPUAccessFlags = 0;
  descDepth.MiscFlags = 0;

  //maincontext->mDepthStencilTexture is of type ID3D11Texture2D*
  hr = GetDevice()->CreateTexture2D(&descDepth, NULL, &maincontext->mDepthStencilTexture);
  if (hr != S_OK)
  {
    ASSERTLOGC(0, "Failed to create DepthStencil for swap chain");
    return false;
  }

  // Create the depth stencil view
  D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
  ZeroMemory(&descDSV, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));
  descDSV.Format = descDepth.Format;
  descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
  descDSV.Texture2D.MipSlice = 0;
  
  //maincontext->mDepthStencilView ID3D11DepthStencilView
  hr = GetDevice()->CreateDepthStencilView(maincontext->mDepthStencilTexture, &descDSV, &maincontext->mDepthStencilView);
  if(hr != S_OK)
  {
    ASSERTLOGC(0, "Failed to create DepthStencilView for swap chain");
    return false;
  }

/************** Binding code ************/
mContext->OMSetRenderTargets(1, &mFrameBufferRT, mDepthStencilView);

2) My camera is not looking straight down, but slight downwards. the rock models are on a flat xz plane.

Also, the rocks flicker a little as I zoom the camera in and out, so it's probably z-fighting like you guys said.

Do you set clip distance in your shader?

Also check that your vertex shader emits correct value (in no nan)

This topic is closed to new replies.

Advertisement