Anapplicationcanhelpensurethatcoplanarpolygonsarerenderedproperlybyaddingabiastothez-valuesthatthesystemuseswhenrenderingthesetsofcoplanarpolygons.Toaddaz-biastoasetofpolygons,calltheSetRenderStatemethodjustbeforerenderingthem,settingtheStateparametertoD3DRS_DEPTHBIAS,andthevalueparametertoavaluebetween0-16inclusive.Ahigherz-biasvalueincreasesthelikelihoodthatthepolygonsyourenderwillbevisiblewhendisplayedwithothercoplanarpolygons.
Offset=m*D3DRS_SLOPESCALEDEPTHBIAS+D3DRS_DEPTHBIAS
wheremisthemaximumdepthslopeofthetrianglebeingrendered.
m=max(abs(deltaz/deltax),abs(deltaz/deltay))
TheunitsfortheD3DRS_DEPTHBIASandD3DRS_SLOPESCALEDEPTHBIASrenderstatesdependonwhetherz-bufferingorw-bufferingisenabled.Theapplicationmustprovidesuitablevalues.
Thebiasisnotappliedtoanylineandpointprimitive.However,thisbiasneedstobeappliedtotrianglesdrawninwireframemode.
//RenderStates
D3DRS_SLOPESCALEDEPTHBIAS,//Defaultstozero
D3DRS_DEPTHBIAS,//Defaultstozero
//Caps
D3DPRASTERCAPS_DEPTHBIAS
D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS