As most of intermediate graphics programmers know, z-fighting can be a problem. That's why most game engines prevent this from happening by using a slope depth bias algorithm.
As there's no direct information on how this is performed, apart from microsoft's reference DirectX page, I wanted to ask whether anyone has any idea on how a vertex shader could be written to implement such a mechanism. I wrote a snippet, but it's not behaving as expected. Here it is (Cg vertex shader code):
out_position = mul(worldviewproj_matrix, in_position);
out_world_position = mul(world_matrix, in_position);
float Dz = camera_position.z - out_world_position.z;
float Dy = camera_position.y - out_world_position.y;
float Dx = camera_position.x - out_world_position.x;
float m = max( abs(Dz / Dy), abs(Dz / Dx));
float Offset = m * main_bias + main2_bias;
out_position.z -= Offset * 0.005;