Multisample AA Artifacts

Posts: 30
Joined: 2009.02
Post: #1
Hi, I'm having a strange issue with antialiasing using multisampling extensions. It happens independent of the number of samples (tried 2x-16x, all with the same result).

Here is the screenshot, it appears as 1 pixel borders around tiles and sprites, and appears to be 'wrapping' pixels from the opposite side around to the other side.

I've figured out this much:

The viewport is 640x480 pixels, but I'm setting it up with a coordinate system of 320x240, for convenience of 'double-sized' pixel movement. However, many things, such as shadows, lighting, and scrolling, move at a per-pixel (640x480) basis.

The artifacts only appear when scrolling (using glTranslatef) with floats. If I clamp them to integers (thus clamping it to double-sized pixels), the artifacts go away, but it isn't nearly as smooth. The shadows/lighting, which are always at full resolution, never seem to have a problem, it's only full screen scrolling that's an issue.

If anyone has any quick diagnoses, it would be appreciated. However, I literally added 2 lines of code to enable this, and it's really not that big of a deal, and totally unnecessary. I'm just going to remove it if there isn't a fairly simple solution. Maybe I need some extra junk in my texture parameters?

surface is an SDL_Surface*

gluBuild2DMipmaps(GL_TEXTURE_2D, 4, surface->w, surface->h, GL_RGBA,GL_UNSIGNED_BYTE, surface->pixels);
Quote this message in a reply
Posts: 1,487
Joined: 2002.09
Post: #2
Why not clamp to half pixels? Presumably that would also solve the problem and still give you pixel smooth scrolling.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Posts: 30
Joined: 2009.02
Post: #3
Man, talk about a brain fart. I can't believe I missed that.

I just clamped it to 0.5 steps, perfectly smooth and no artifacts. Thanks for the help!

Oh, to make this thread useful:
If you're using SDL and OpenGL, here is how to enable multisampling in 2 lines (and if the card doesn't support it, it just doesn't get turned on, but you can check GL_SAMPLE_BUFFERS_ARB and GL_SAMPLE_ARB to confirm):

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); //1 for 1 buffer. Not sure what use more than 1 is, but the option is there.
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); //Number of samples. 2x, 4x, 8x, 16x if you love GPU fan noise
Quote this message in a reply
Posts: 1,234
Joined: 2002.10
Post: #4
Why are you building mipmaps?
Quote this message in a reply
Posts: 30
Joined: 2009.02
Post: #5
I was planning on using lower-res versions of sprites for certain effects, I'm in the middle of a bunch of stuff, so that may or may not change. But yes, there is no reason right now I couldn't use glTexImage2D, but it doesn't really matter right now, I'l probably using 1MB of VRAM or something. Grin
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL ES 2.0, 2D Alpha Transparency Artifacts Macmenace 3 10,013 Mar 28, 2010 11:18 PM
Last Post: AnotherJake
  Shadow Mapping - Self-Shadowing Z-Fighting Artifacts Bachus 16 30,120 Feb 11, 2009 12:24 PM
Last Post: arekkusu
  Strange Artifacts In Heightfield Nick 9 5,255 Apr 16, 2006 05:58 AM
Last Post: SOUCHAN
  Multisample on NVIDIA GeForce 6800 archidea 1 3,591 Nov 8, 2005 12:22 PM
Last Post: OneSadCookie
  AGL and multisample AntiAliasing under X oxenos 5 4,682 Mar 14, 2003 11:28 AM
Last Post: oxenos