Sign in to follow this  
Dragon_Strike

decals depth test

Recommended Posts

Dragon_Strike    264
im trying to set some terrain decals however im having some problems with z fighting... if i set a high offset it looks wierd when u get closer and if i set a lower offset i get z fighting further away... is it possible to first render the main terrain and then render the decals over this while depth test against the rendered terrain is ignored? meaning... turn off depth test against the terrain while the decal itself is depth tested...? im using directx

Share this post


Link to post
Share on other sites
Zipster    2360
The other method you can try is positively biasing the near/far range in the perspective matrix before rendering the decals. It really doesn't take that much bias from a decent distance, maybe +0.001 or so. Since the range is moved farther away, the decal depths are brought closer, so that they're just slightly less than the terrain and the depth test passes, but not so much so that they render on top of anything else.

You're going to have to increase the bias/offset the farther away you get from the terrain using either method, since precision falls off dramatically and you need to counter-act that effect. But if you get too far away then the bias is going to cause the decals to render in front of or fight with other geometry.

Decals are just one of those things you have to tune to your particular application. There's no perfect way to do them, unless you actually modify the terrain texture to include the decal or use CSG to "splice" in a decal poly. I suppose if you were clever you might be able to work out a single-pass GPU solution, but I haven't thought about it that much. Usually the biasing works well enough and I move on.

Share this post


Link to post
Share on other sites
Naku    151
Do you need to be able to see them from far away?

If they're only small things like bullet holes etc, then you could just fade them out when you get further away.

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