DirectX11 with z-fight help framework (or why is D3D11_RASTERIZER_DESC.DepthBias an INT?)

I am trying to use the DepthBias property in the rasterizer state in DirectX 11 ( D3D11_RASTERIZER_DESC ) to help with the z-fight that occurs when rendering in wireframe mode over solid polygons (overlaying) and it seems that setting it to any value does not change anything to result. But I noticed something strange ... the value is defined as INT , not FLOAT . It doesn't make sense to me, but it still doesn't work properly. How to set this value correctly if it is an INT , which should be interpreted as UNORM in the shader pipeline?

That's what I'm doing:

  • Show all geometry
  • Install a rasterizer to render in the wireframe
  • Repeat all geometry again

I clearly see the frame overlay, but the z-fight is terrible. I tried setting DepthBias to a lot of different values, such as 0.000001 , 0.1 , 1 , 10 , 1000 and all minus equivalents, still no results ... obviously, I know when you throw a float as a whole, all decimals are truncated. .. meh?

 D3D11_RASTERIZER_DESC RasterizerDesc; ZeroMemory(&RasterizerDesc, sizeof(RasterizerDesc)); RasterizerDesc.FillMode = D3D11_FILL_WIREFRAME; RasterizerDesc.CullMode = D3D11_CULL_BACK; RasterizerDesc.FrontCounterClockwise = FALSE; RasterizerDesc.DepthBias = ??? RasterizerDesc.SlopeScaledDepthBias = 0.0f; RasterizerDesc.DepthBiasClamp = 0.0f; RasterizerDesc.DepthClipEnable = TRUE; RasterizerDesc.ScissorEnable = FALSE; RasterizerDesc.MultisampleEnable = FALSE; RasterizerDesc.AntialiasedLineEnable = FALSE; 

How did you find DepthBias how to install DepthBias ? Or maybe this is a bug in DirectX (which I doubt), or maybe there is a better way to achieve this than using DepthBias ?

Thanks!

+4
source share
2 answers

http://msdn.microsoft.com/en-us/library/windows/desktop/cc308048(v=vs.85).aspx

Depending on whether your depth buffer is uniform or floating point, the value of the number changes. In most cases, you are simply looking for the smallest possible value that gets rid of your z-battle, and not any particular value. Small values ​​represent a small offset, large values ​​represent a large offset, but how this equates to a shift depends on the format of the depth buffer.

As for the values ​​you tried, anything less than 1 would round up to zero and have no effect. 1, 10, 1000 may simply not be enough to solve the problem. In the case of the D24 UNORM depth buffer, this formula assumes that a depth offset of 1000 will shift the depth by: 1000 * (1/2 ^ 24), which is equal to 0.0000596, not a very significant shift under z-buffering conditions.

Does a large value of 100,000 or 1,000,000 capture a z-battle?

+9
source

If someone cares, I made myself a macro to make it easier. Note that this macro will only work if you use the 32-bit floating-point buffer format. A different macro may be required if you use a different depth buffer format.

 #define DEPTH_BIAS_D32_FLOAT(d) (d/(1/pow(2,23))) 

Thus, you can simply set the depth offset using standard values, for example:

 RasterizerDesc.DepthBias = DEPTH_BIAS_D32_FLOAT(-0.00001); 
0
source

Source: https://habr.com/ru/post/1487125/


All Articles