iDevGames Forums
Multisample AA Artifacts - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Multisample AA Artifacts (/thread-855.html)

Multisample AA Artifacts - metacollin - Aug 14, 2009 02:52 PM

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);

Multisample AA Artifacts - Skorche - Aug 14, 2009 03:13 PM

Why not clamp to half pixels? Presumably that would also solve the problem and still give you pixel smooth scrolling.

Multisample AA Artifacts - metacollin - Aug 14, 2009 03:31 PM

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

Multisample AA Artifacts - arekkusu - Aug 14, 2009 06:52 PM

Why are you building mipmaps?

Multisample AA Artifacts - metacollin - Aug 14, 2009 07:11 PM

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