Turn off antialiasing in polyLineVisual3D
When I draw a straight, slightly diagonal line using polyLineVisual3D it draws it with antialiasing. I don't want it drawn with antialiasing - I'd prefer to just have sharp staircasing. How do I turn off the antialiasing?

I've attached an enlarged screen capture that shows the antialiasing.

The code that generates this looks like:

                var polyLineVisual3D = new Ab3d.Visuals.PolyLineVisual3D()
                    Positions = simplePositionCollection,
                    LineColor = color,
                    LineThickness = thickness,   // =1
                    Transform = new TranslateTransform3D(-(aw / 2), (ah / 2), 0)  

Thanks in advance!
To support rendering thick lines (with LineThickness > 1), DXEngine uses geometry shader that takes the line positions and converted them into triangles (2 triangles for each line segment). After that the lines are rendered as any other 3D model.

This means that the anti-aliasing settings that are used to render all other 3D objects are also applied to line rendering.

Anti-aliasing amount in DXEngine is specified with your GraphicsProfile settings. If you are using HighQualityHardwareRendering (by default), then you have 8x anti-aliasing enabled.

To disable anti-aliasing you can use the following code (need to be executed before the DXViewportView is loaded):

var graphicsProfile = GraphicsProfile.HighQualityHardwareRendering.Clone();
graphicsProfile.PreferedMultisampleCount = 0;

MainDXViewportView.GraphicsProfiles = new GraphicsProfile[] { graphicsProfile };

The code clones the HighQualityHardwareRendering and resets the PreferedMultisampleCount to 0. Then the changed GraphicsProfile object is specified as the only possible GraphicsProfile.

If you will check the default value of the DXViewportView.GraphicsProfiles, you will see that the GraphicsProfiles array contains the following items:

This adds some fallback capabilities in case when hardware rendering is not supported on the system. I would recommend that if you change the GraphicsProfiles array, that you follow similar principe.

This described how to change anti-aliasing for the whole scene.

But it is also possible to disable anti-aliasing only for 3D lines.
To do this you need to do the following:

MainDXViewportView.DXScene.UseGeometryShaderFor3DLines = false;
MainDXViewportView.DXScene.RenderAntialiased3DLines = false;

The first line disable using geometry shader to render 3D lines. 3D lines are then rendered as simple DirectX lines. A drawback of this is that without using geometry shader you will not be able to change line thickness - all the 3D lines will be rendered with thickness = 1.

The second line that set RenderAntialiased3DLines to false instructs DirectX that when rendering lines, the lines should not be anti-aliased (this works only when UseGeometryShaderFor3DLines is false).

Disabling gemetry shader and anti-aliasing also improves performance of line rendering.

If you would like to set those two properties before the first frame is rendered you can use the following code:

MainDXViewportView.DXSceneDeviceCreated += delegate(object sender, EventArgs args)
    // Called after DXScene and DXDevice were initialized and before SceneNodes are created
    if (MainDXViewportView.DXScene != null) // DXScene can be null in case of WPF rendering
        MainDXViewportView.DXScene.UseGeometryShaderFor3DLines = false;
        MainDXViewportView.DXScene.RenderAntialiased3DLines = false;
Andrej Benedik

Forum Jump:

Users browsing this thread:
1 Guest(s)