40
$\begingroup$

Is it possible? Is it platform specific? Does it rely on the graphics hardware? Why does the antialiasing slider under Preferences > Appearance > Graphics do nothing? I remember seeing some post-plotting solutions years before in MathGroup, but could not find it.

Edit

System is: HP EliteBook 8440p, integrated Intel HD Graphics, running Windows 7, 64bit

$\endgroup$
2
  • $\begingroup$ The slider works as advertised under OS X, so it is probably platform- and hardware-specific. $\endgroup$
    – acl
    Commented Jan 18, 2012 at 19:12
  • $\begingroup$ @acl It is hardware-specific, it's just that Macs always come with good enough graphics hardware. $\endgroup$
    – Szabolcs
    Commented Jan 18, 2012 at 19:27

3 Answers 3

42
$\begingroup$

This needs specific support from your graphics card. My own graphics card is very old, and does not support it, so the slider does nothing on my machine.


But the good news is that there are workarounds, and I even made an antialiasing palette (code at the end of the post -- evaluate it, pop out the palette, and if you prefer, save it using Palettes -> Install Palette...).

This is the core antialiasing function I use:

antialias[g_, n_: 3] := 
  ImageResize[Rasterize[g, "Image", ImageResolution -> n 72], Scaled[1/n]]

It simply renders a large image, and it downscales it. The results can be better than with a better graphics card's built-in antialiasing, so it's worth a look even if you have a good graphics card.

Problems with this method:

  • Fonts can be blurrier than what you'd like

  • With a high scaling factor, it may expose bugs in your graphics driver, and show some unusual results (I had problems with opacity in more complex graphics)

  • Tick marks don't scale properly (I think this is a bug), so they are barely visible on the antialiased version.


This is the palette code. Usage: select a 3D graphic and press the button. It'll insert an antialiased image below.

Begin["AA`"];

PaletteNotebook[DynamicModule[
  {n = 3},
  Column[{
    SetterBar[
     Dynamic[n], {2 -> "2\[Times]", 3 -> "3\[Times]", 
      4 -> "4\[Times]", 6 -> "6\[Times]"}, Appearance -> "Palette"],
    Tooltip[
     Button["Antialias", antialiasSelection[SelectedNotebook[], n], 
      Appearance -> "Palette"], 
     "Antialias selected graphics using the chosen scaling factor.\nA single 2D or 3D graphics box must be selected."]
    }],
  Initialization :> (
    antialias[g_, n_Integer: 3] := 
     ImageResize[Rasterize[g, "Image", ImageResolution -> n 72], 
      Scaled[1/n]];

    antialiasSelection[doc_, n_] := Module[{selection, result},
      selection = NotebookRead[doc];
      If[MatchQ[selection, _GraphicsBox | _Graphics3DBox],
       result = 
        ToBoxes@Image[antialias[ToExpression[selection], n], 
          Magnification -> 1];
       SelectionMove[doc, After, Cell];
       NotebookWrite[doc, result],

       Beep[]
       ]
      ]
    )
  ],
 TooltipBoxOptions -> {TooltipDelay -> Automatic}, 
 WindowTitle -> "Antialiasing"
 ]

End[];

Demonstration:

Mathematica graphics Mathematica graphics

$\endgroup$
8
  • 1
    $\begingroup$ @István, this time I have included the tooltips, so you can see that I'm listening :D $\endgroup$
    – Szabolcs
    Commented Jan 18, 2012 at 19:28
  • $\begingroup$ Many thanks, I really appreciate it! An informative gui is a good gui. $\endgroup$ Commented Jan 18, 2012 at 20:26
  • $\begingroup$ I wonder, can this code be applied in a post-way to Graphics3D objects automatically? Would that be too resource-consuming? $\endgroup$ Commented Jan 18, 2012 at 20:39
  • $\begingroup$ @István If we did that, Graphics3D objects would not be rotatable any more. But yes, I guess we could do that: render[g_Graphics3D] := antialias[g]; render[x_] := x; $PrePrint = render. (This needs improvement of course to handle Graphics3D inside List/Row/Column, etc., but it's enough to try if you like it.) $\endgroup$
    – Szabolcs
    Commented Jan 18, 2012 at 20:42
  • $\begingroup$ No, I was asking whether it is possible to postprocess Graphics3D and still maintain it in full 3D (rotateable). Now I know the answer, and that concludes our session. And the Oscar goes to.... $\endgroup$ Commented Jan 18, 2012 at 21:33
21
$\begingroup$

If you're running Mathematica in Linux, 3D antialiasing can be a bit tricky. Asking Wolfram support for a workaround, I got the following as an answer:

Unfortunately, anti-aliasing is not officially supported in the Mathematica front-end on Linux at this time. However, you may be able to enable it by setting the MATHEMATICA_GL_FBO environment variable to 1. Here is how to do this in bash:

export MATHEMATICA_GL_FBO=1

This should work on most late-model NVIDIA GPUs, assuming that you are using the proprietary NVIDIA drivers.

Note that the support also told me this is an experimental feature, but I have never experienced any problems with it, and am now using it for almost a year. I think worst case is it isn't supported by your graphics card and the workaround does nothing.

If you want to execute this command automatically when starting Mathematica, open /usr/local/bin/mathematica (or wherever you installed your executable to) and add the line at the very top. This is what my file looks like:

#!/bin/sh

# Linux antialiasing workaround, suggested by Wolfram support:
export MATHEMATICA_GL_FBO=1

#  Mathematica 8.0 Front End command file
#  Copyright 1988-2010 Wolfram Research, Inc.
#  Make certain that ${PATH} includes /usr/bin and /bin
PATH="/usr/bin:/bin:${PATH}"

...
$\endgroup$
5
  • $\begingroup$ Works in Linux (Fedora 19) with my Intel® HD Graphics 4400 video cheap (chip) $\endgroup$
    – alfC
    Commented Sep 24, 2013 at 19:29
  • 3
    $\begingroup$ Does Mathematica 10 support 3D antialiasing in Linux now? $\endgroup$ Commented Sep 18, 2014 at 8:07
  • $\begingroup$ After past success this trick doesn't work in Fedora 23/Gnome. $\endgroup$
    – alfC
    Commented Apr 7, 2016 at 4:55
  • $\begingroup$ This is a more robust solution: mathematica.stackexchange.com/a/101172/1963 $\endgroup$
    – alfC
    Commented Apr 7, 2016 at 5:00
  • $\begingroup$ Antialiasing does not seem to be any discernable effect in Windows 10 with dual GTX970 graphics boards. $\endgroup$ Commented Dec 31, 2018 at 17:36
9
$\begingroup$

If moving the slider doesn't have any visible effect on the graphic inside the preferences dialog, then 3D antialiasing is probably not supported on your computer. The level of support depends mainly on the graphics card and operating system. If you tell us more details, we might be able to say more.

I also know of situations where antialiasing works for opaque scenes, but turns off when there's transparency, but that doesn't sound like that's the case here.

$\endgroup$
2
  • $\begingroup$ I can confirm that antialiasing doesn't work when transparency is involved. One can see that it effects the axes but not the object. $\endgroup$
    – Dror
    Commented Mar 30, 2012 at 12:51
  • $\begingroup$ @Dror This will depend on your system, and you may get better results from using the BSPTree: mathematica.stackexchange.com/a/190 $\endgroup$ Commented Mar 30, 2012 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.