• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
  • entries
    83
  • comments
    0
  • views
    65149

Texture aliasing

Sign in to follow this  
Followers 0
shawnhar

572 views

Aliasing can occur any time you resample a texture, for instance to scale it, rotate it, or map it onto a 3D model. Thanks to our friend the Nyquist threshold, the resulting problems get worse the lower a frequency you sample at, ie. the smaller you shrink it.

Check out this awesome 32x32 test image:

2705.Untitled_5F00_15AECA6E.png

Zoomed 4x so you can see in detail:

0652.image_5F00_5C2BBA76.png

This test code draws six copies, first with no transform, then rotated, followed by straight and rotated versions at half and quarter size:

spriteBatch.Begin(0, null, SamplerState.PointClamp, null, null); spriteBatch.Draw(testTexture, new Vector2(20, 24), null, Color.White, 0, new Vector2(16, 16), 1, 0, 0); spriteBatch.Draw(testTexture, new Vector2(60, 24), null, Color.White, 1, new Vector2(16, 16), 1, 0, 0); spriteBatch.Draw(testTexture, new Vector2(95, 24), null, Color.White, 0, new Vector2(16, 16), 0.5f, 0, 0); spriteBatch.Draw(testTexture, new Vector2(120, 24), null, Color.White, 1, new Vector2(16, 16), 0.5f, 0, 0); spriteBatch.Draw(testTexture, new Vector2(140, 24), null, Color.White, 0, new Vector2(16, 16), 0.25f, 0, 0); spriteBatch.Draw(testTexture, new Vector2(155, 24), null, Color.White, 1, new Vector2(16, 16), 0.25f, 0, 0); spriteBatch.End();

Note the use of SamplerState.PointClamp, which turns off the antialiasing SpriteBatch would normally apply by default.

Resulting image:

5432.image_5F00_3C10ADB9.png

Zoomed 4x:

2388.image_5F00_401AFB8B.png

This has almost too many aliasing problems to mention! Some that I find particularly bothersome are:

  • The black diagonal lines have pieces missing in the full size rotated image
  • The half size non rotated image has lots of problems:
    • The green vertical line, and also the red and blue horizontal lines, are entirely missing
    • It ended up with just two rather than three sets of black diagonal lines
    • The black border remains on the bottom and right, but is missing on the top and left
    • The two quarter size images are entirely different:
      • Non rotated version has only a blue line, no red or green at all
      • Rotated version has scattered red and green pixels, but no blue
      • Imagine how horrible it would look if we animated this sprite spinning, as it would flicker back and forth between different colors! Remember how multisampling smooths triangle edges but does not affect their interior? We can confirm this by turning on 4x multisampling, and noting how the only difference is smoother borders on the rotated images:

        6521.image_5F00_34F17141.png

        With 4x supersampling, on the other hand, texture aliasing is indeed reduced:

        1715.image_5F00_7FE4E210.png

        But this is still far from perfect. The full size rotated and half size non rotated images look pretty nice, but the half size rotated and both quarter size versions have flaws. We'd still get nasty color pulsation if we animated a rotation of that quarter size version. This is because 4x supersampling only gives a 2x improvement in sampling frequency along each of the horizontal and vertical axes. That can reduce aliasing, but is not enough to keep us above the Nyquist threshold if we transform the texture by a factor of more than 2x.

        Whatever is a poor graphics programmer to do?

        To start with, we shouldn't have made life difficult for ourselves by specifying point sampling! If we turn off supersampling and multisampling, then change our SpriteBatch.Begin call to use the default SamplerState.LinearClamp, bilinear filtering produces a much nicer image than the point sampled version we started out with:

        8662.image_5F00_0DB7280C.png

        Unlike multisampling and supersampling, texture filtering does not smooth the border of the rotated images, but it does a nice job to reduce aliasing inside our full size rotated and half size non rotated images. Bilinear filtering lets us down in the same places as supersampling. Because the GPU only takes four filter taps per texture fetch (two horizontal and two vertical), we get 2x more headroom before we will run into aliasing problems, but a 2x improvement cannot entirely eliminate the Nyquist threshold, so our quarter size images remain nasty.

        The solution is to combine bilinear filtering with precalculated mipmaps (plus anisotropic filtering if you can afford it). No matter how small the texture is scaled, the GPU can now simply select the appropriate mip level to sample from, always remaining just below the Nyquist threshold regardless of what transforms are applied.

        With mipmaps enabled, even our smallest images now keep the same color intensity and hue, with no stray pixels or random changes of shape, so we can animate our sprite rotating or scaling with no aliasing problems at all:

        6518.image_5F00_1B896E07.png

        aggbug.aspx?PostID=10159661

        Source

0
Sign in to follow this  
Followers 0


0 Comments


There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now