locked
Possible to Disable full window Anti-Aliasing? RRS feed

  • Question

  • Hello all,

    I'm familiar with WPF's design philosophy regarding DIP's, and why most content in a WPF app uses anti-aliasing to smooth out fonts, control graphics, images, etc.  However, for our application we actually want a 3D viewport to be displayed with no anti-aliasing whatsoever.  Currently I use a Viewport3D for our content, and we have had people notice that it doesn't line up on perfect pixels; the blurry edges make it hard for our users, since the app is used for pixel-precise image layout. 

    Does anybody know if it is possible to disable the "whole-window" anti-aliasing that is going on?  I have read a few posts and articles about "SnapsToDevicePixels", but this only seems to work on content that goes through a Layout pass.  For 3D meshes using double coordinates, this doesn't seem like something that would follow that model ( and I don't see the Property on any of the 3D Geometry or Visual classes ).  However, Direct3D ( which is what WPF is built on, right? ) is certainly capable of rendering to a pixel-aligned bitmap target; is there any way of getting WPF to behave this way?

    If not, it sounds like my only option is to render a Win32 DirectX window, and then display that using HwndHost.  (I'm assuming that this would not be subject to the same default anti-aliasing that the rest of WPF is doing).  I would really love to avoid putting this big Interop layer in our application if possible, so I'm all ears to suggestions on how to avoid it.

    Thank you much for any advice!
    Friday, November 6, 2009 12:18 AM

Answers

  • In addition to disabling anti-aliasing with EdgeMode="Aliased", in .Net 4.0 we've added another attached property called UseLayoutRounding that will ensure your elements are all layed-out at whole-pixel positions with whole-pixel sizes, which lessens the need for anti-aliasing.  Using these two properties in combination should definitely give you the behavior you're looking for.
    Friday, November 6, 2009 11:48 PM

All replies

  • Try put RenderOptions.EdgeMode="Aliased" as attached property to the the control that you want to render in aliased mode
    http://slouge.wordpress.com
    Friday, November 6, 2009 7:33 AM
  • In addition to disabling anti-aliasing with EdgeMode="Aliased", in .Net 4.0 we've added another attached property called UseLayoutRounding that will ensure your elements are all layed-out at whole-pixel positions with whole-pixel sizes, which lessens the need for anti-aliasing.  Using these two properties in combination should definitely give you the behavior you're looking for.
    Friday, November 6, 2009 11:48 PM
  • Thank you for the replies guys,

    Unfortunately, I have not had any success with "RenderOptions.SetEdgeMode( EdgeMode.Aliased )".  To clarify, I am using a Viewport3D, with ModelVisual3D children whose content consists of a GeometryModel3D.  I have tried calling that function on all three objects, it does not prevent any part of the viewport from being anti-aliased.

    This makes sense though, doesn't it?  The EdgeMode property states: "Gets or sets the EdgeMode enumeration value for a non-text primitive that determines how its edges are rendered."  But in my case, this isn't just about the edges of a Control, this is the whole Viewport3D being antialiased.  The ModelVisual3D children don't go through a layout pass, and I wouldn't expect that they are affected by the same kind of edge control( is this incorrect? ) 

    There is what looks like a slight blur over the entire Window, including the viewport.  It's that "full-screen blur that I need to get rid of, including over the internals of my polygons.  Will the upcoming "UseLayoutRounding" affect 3D elements?  Or am I just using the EdgeMode property incorrectly?

    Thanks again for your advice!
    Monday, November 9, 2009 5:53 PM