Game Development Community

Z Fighting issue with the Road Tool and the Terrain :)

by Jackie Hayes · in Torque 3D Professional · 05/17/2009 (12:28 pm) · 8 replies

Been looking at the z fighting issue with the road tool and made a very small change and so far it seems to be working correctly now.
In decalRoad.cpp - bool DecalRoad::prepRenderImage at about line 418 change MathUtils::getZBiasProjectionMatrix( 0.000132f, frustum, coreRI.projection ); to MathUtils::getZBiasProjectionMatrix( 0.001f, frustum, coreRI.projection );. It looks like the textures are being set to close to the surface of the terrain which is causing the problem. I just raised it up a little and no more z fighting. There is, however, a little z fighting when you are in the world editor mode. I have tried this on different terrains and so far it seems to be stable.

Not sure if this is the correct way of doing this but it seems to be working ok for me.

Hope this helps....:)

#1
05/17/2009 (4:32 pm)
Works perfectly for me, don't know if this is the 'right' fix, but it'll work until GG pushes something else out.

Thanks a lot Jackie
#2
05/17/2009 (5:07 pm)
Yeah, that seems to work fine. Well done.
#3
05/17/2009 (11:03 pm)
I guess there is no right fix for this problem unless the whole engine is modified to not translate the camera away from 0,0,0 but instead move the world into the opposite direction to prevent the ugly z precision issues we have been seeing since TGEAs start (there especially terrain and water further away that "fights for life" along shore lines. further away means anything thats about 4000 off from 0,0,0 )
#4
05/18/2009 (2:53 pm)
If you use a greater value for the z-bias like that, make sure to fly really close to the road, and check to make sure it doesn't "hover" above the terrain at all. Z fighting stuff is a pain.
#5
05/18/2009 (3:31 pm)
@Jackie - Thats the right way to fix that... use 0.005f (about 0.2 inches) instead and it will work solidly for games where meters are 1 to 1. There is still an issue with the bias not working in the world editor... this seems to be another bug... i'm tracking it now.

@Marc - Its just math... objectPos - cameraPos = cameraSpacePos. Changing it to objectPos - moveToCameraOffset = cameraSpacePos is not mathimatically different.

There are two issues with precision you generally run into in all game engines.

Zbuffer precision which results in the flicker from shorelines and the road decal issues. This is best controlled via adjustments to the near plane and/or adding bias values to your geometry. No change to how you translate objects to camera space (short of scaling up your world) will change your zbuffer precision.

Second is simulation precision. Torque like many games does most of its vehicle/player/physics simulation in world space. Some of the jitters you have there can be reduced by doing some key parts of the simulation math in object space, but you'll still eventually run into problems when transforming from object to camera space. The only fix there is to recenter your simulation periodically to avoid the loss in precision.
#6
05/18/2009 (3:32 pm)
I did check that when I was testing. I got level with the terrain and the road and moved up and down very slowly and honestly could not see any gaps in between the road and the terrain. I even tested it on a terrain that was mountainous and it seemed to conform pretty good. Looked kind of stupid but it worked.
#7
05/25/2009 (5:17 pm)
@Tom: thats clear that those two things are the same :)

I guess the optimal solution in this case would be a distance / height distance dependent value for the distance from ground. A fixed one likely will only work for fixed scenarios.
#8
05/25/2009 (8:49 pm)
There are a couple of other tricks... but in general... yes. :)