# OpenGL [D3D] Showing wireframe over shaded geometry

This topic is 4196 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi All, To get good results, in OpenGL exists a function to offset the wireframe 'just a little bit' closer than the filled polygons. Can this be done with Direct3D? Thanks so much guys. Alberto

##### Share on other sites
When you say a just a little bit closer, you mean that it makes the wireframe draw above the filled polygons so that you see both the solid mesh and it's edges?
If so, then the problem is that since they both are at the same distance from the camera, Direct3D will not know who should be drawn (its called z-fighting or flimmering). There are many ways of solving this. One is to disable the Z-Buffer or disabling the Z-Writing temporarily and then Direct3D won't confuse between the depths. Another technique is to use the Z-Bias but I have suspicions about that one, it didn't seem to work last time I tried. You can also use stenciling to solve this but it's a bit more complicated; search for how to use 'decals' if you want to use this method.
Hope this helped,
Uri

##### Share on other sites
Decals?!?

I will try to fid something with google...

Thanks,

Alberto

##### Share on other sites
I think the "function to offset the wireframe 'just a little bit' closer than the filled polygons" is just Z-bias :)

You can do it in Direct3D by doing this :

float zBias = 0.01f; // your 'offset' value. Play with it until you get good results
pD3DDevice->SetRenderState(D3DRS_DEPTHBIAS, *(DWORD *)&zBias);

##### Share on other sites
Thanks a lot paic,

So I:

1) Set the zBias = 0.0f;
3) Set the zBias = 0.01f;
4) Draw wireframe triangles

Ok?

Alberto

##### Share on other sites
Read this MSDN page for further info. Depth biasing was tightened up as it was often a bit arbitrary what sort of offset was correct across multiple variations of GPU...

hth
Jack

##### Share on other sites
Thanks a lot Jack,

Looks like zBias doesn't work for lines... What if I need to outline a mesh of 4x4 = 16x2 = 32 triangle with 4+4+4+4 lines?!?

Alberto

##### Share on other sites
Another technique is to modify your projection matrix to push the near plane out a little which essentially brings all generated depth values back a bit. This would only be worth doing if you can batch your stuff such that all solid stuff is drawn and then modify proj matrix then render all wire stuff. It seems to work relatively well in practise.

##### Share on other sites
Mmmm... very nice, thanks.

##### Share on other sites
Quote:
 Original post by devdeptThanks a lot Jack,Looks like zBias doesn't work for lines... What if I need to outline a mesh of 4x4 = 16x2 = 32 triangle with 4+4+4+4 lines?!?Alberto

Couldn't you apply the depth bias to the solid object and leave the lines at the original depth?

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633678
• Total Posts
3013292
×