Suppose that you have two overlapped regions and you want to avoid Z-fighting.
If you want to prevent Z-fighting, you can follow the approach reported below.
First of all, you should decide which entity you prefer to display on top (in this case I choose CircularRegion).
Next, you should create a new class "MyRegion" that derives from CircularRegion, and override Draw() and Render() methods.
class MyRegion : CircularRegion
{
public MyRegion(double x, double y, double radius)
: base(x, y, radius)
{
}
protected override void Draw(DrawParams data)
{
data.RenderContext.PushRasterizerState();
data.RenderContext.SetState(rasterizerStateType.CCW_PolygonFill_NoCullFace_PolygonOffset_Minus3Minus2);
base.Draw(data);
data.RenderContext.PopRasterizerState();
}
protected override void Render(RenderParams data)
{
data.RenderContext.PushRasterizerState();
data.RenderContext.SetState(rasterizerStateType.CCW_PolygonFill_NoCullFace_PolygonOffset_Minus3Minus2);
base.Render(data);
data.RenderContext.PopRasterizerState();
}
}
Finally, when you draw the two entities:
MyRegion circ = new MyRegion(80, 80, 30);
circ.ColorMethod = colorMethodType.byEntity;
circ.Color = Color.Red;
viewportLayout1.Entities.Add(circ);
RectangularRegion rect = new RectangularRegion(200, 200);
rect.Color = Color.Gray;
rect.ColorMethod = colorMethodType.byEntity;
viewportLayout1.Entities.Add(rect);
you will obtain the following result:
Previous versions of this article: Eyeshot 7
Comments
If a "Surface" is only single sided, and the drawing it done on the underside (i.e. derived class from `LinearPath`) facing outwards, Then this method will force the appearance to be flipped to the inside.
Please sign in to leave a comment.