Sign in to follow this  
sirob

Depth bias troubles.

Recommended Posts

sirob    1181
Hi again, I'm trying to render a decal on my rendered terrain, and having a bit trouble with the depth bias. I can render one or 2 quads, and they draw nicely (only very small artifacts in their seams). However, when I try to draw 4 quads, only the 4th quad has artifacts on it (this might be due to different slopes on the quads, not too sure yet). I've tried playing around with the depth bias, but even pushing it as high as 15 doesn't make a difference, nor does D3DRS_SLOPESCALEDEPTHBIAS. So, what do I do? any ideas? Heres an image: Image Hosted by ImageShack.us [EDIT] Gonna add some of my code, too:
	m_Device->SetTexture(0, 0);
	m_Device->SetRenderState(D3DRS_ZFUNC, D3DCMP_GREATEREQUAL);
	DWORD bias = 14;
	m_Device->SetRenderState(D3DRS_DEPTHBIAS, bias); 
	m_Device->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, bias);
	m_Device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, size * size * 2, Vertices, sizeof(TerrainVertex));
	bias = 0;
	m_Device->SetRenderState(D3DRS_DEPTHBIAS, bias);
	m_Device->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, bias);
	m_Device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);

Share this post


Link to post
Share on other sites
paic    645
Hi,

From my experience, I never achieved good result on terrain using the normal depth bias. After a lot of tweaking, here is the setting that gives me good results :

float bias = -0.6f;
m_pd3dDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *(DWORD *)&bias);


(for terrains, depth bias should not be used, only slope depth bias)

Edit : I didn't notice : the depth bias should be a float, and passed in the SetRenderState method using the dirty trick *(DWORD *)& (provided by the DirectX doc ! ^^)
You're passing 14 as a DWORD already, and I don't think the internal representation of a float = 14.0 and a dword = 14 is the same ^^ So I assume the depth bias value is set to a strange value.

Share this post


Link to post
Share on other sites
sirob    1181
Hi, thanks for replying!

You are correct, they are both a float value, which is unfortunatly only mentioned about the zbias and not the slope one, and only in one place.

I thought it might be a float, but it said "Defaults to 0", not 0.0f, so I thought it might be a DWORD.

Anyhow, I tried your value, -0.6, and well, I'm having a small issue with it. When looking directly from above, I get rectangular holes in the decal. Heres an image:
Image Hosted by ImageShack.us

This only happens when looking straight down. I'm also worried about using a negative value when the docs state you should use a value between 0 and 16 (inclusive! :)).

Any info on that? I'll keep testing when I have some more time...

Again, thanks for the reply!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this