MULTIMEDIA

iPhone 3D Programming : Anisotropic Filtering: Textures on Steroids

6/30/2011 3:50:40 PM
An issue with standard bilinear texture filtering is that it samples the texture using the same offsets, regardless of how the primitive is oriented on the screen. Bilinear filtering samples the texture four times across a 2×2 square of texels; mipmapped filtering makes a total of eight samples (2×2 on one mipmap level, 2×2 on another). The fact that these methods sample across a uniform 2×2 square can be a bit of a liability.

For example, consider a textured primitive viewed at a sharp angle, such as the grassy ground plane in the Holodeck sample from this article. The grass looks blurry, even though the texture is quite clear. Figure 1 shows a zoomed-in screenshot of this.

Figure 1. Isotropic versus anisotropic filtering


A special type of filtering scheme called anisotropic filtering can alleviate blurriness with near edge-on primitives. Anisotropic filtering dynamically adjusts its sampling distribution depending on the orientation of the surface. Anisotropic is a rather intimidating word, so it helps to break it down. Traditional bilinear filtering is isotropic, meaning “uniform in all dimensions”; iso is Greek for “equal,” and tropos means “direction” in this context.

Go with the Grain

Anisotropic can also describe a lighting model that simulates a surface with directional grain, such as satin or brushed metal. David Banks developed this technique in a 1994 SIGGRAPH paper. My favorite example can be found in the uniforms worn by the main characters in The Incredibles.


Anisotropic texturing is made available via the GL_EXT_texture_filter_anisotropic extension. Strangely, at the time of this writing, this extension is available only on older iPhones. I strongly suggest checking for support at runtime before making use of it.


Note:

Even if your device does not support the anisotropic extension, it’s possible to achieve the same effect in a fragment shader that leverages derivatives


The anisotropic texturing extension adds a new enumerant for passing in to glTexParameter:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);

The GL_TEXTURE_MAX_ANISOTROPY_EXT constant sets the maximum degree of anisotropy; the higher the number, the more texture lookups are performed. Currently, Apple devices that support this extension have a maximum value of 2.0, but you should query it at runtime, as shown in Example 1.

Example 1. Enabling anisotropic filtering
GLfloat maxAniso;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAniso);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAniso);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

For highest quality, you’ll want to use this anisotropic filtering in concert with mipmapping. Take care with this extension; the additional texture lookups can incur a loss in performance.

Other  
  •  iPhone 3D Programming : Reflections with Cube Maps
  •  Silverlight Recipes : Networking and Web Service Integration - Accessing Resources over HTTP
  •  Silverlight Recipes : Networking and Web Service Integration - Using JSON Serialization over HTTP
  •  Microsoft XNA Game Studio 3.0 : Displaying Images - Using Resources in a Game (part 4) - Filling the Screen
  •  Microsoft XNA Game Studio 3.0 : Displaying Images - Using Resources in a Game (part 3) - Sprite Drawing with SpriteBatch
  •  Microsoft XNA Game Studio 3.0 : Displaying Images - Using Resources in a Game (part 2) - Positioning Your Game Sprite on the Screen
  •  Microsoft XNA Game Studio 3.0 : Displaying Images - Using Resources in a Game (part 1) - Loading XNA Textures
  •  iPhone 3D Programming : Holodeck Sample (part 5) - Overlaying with a Live Camera Image
  •  iPhone 3D Programming : Holodeck Sample (part 4) - Replacing Buttons with Orientation Sensors
  •  iPhone 3D Programming : Holodeck Sample (part 3) - Handling the Heads-Up Display
  •  
    Most View
    How To Accelerate Windows 8
    Give Your Shots Wings!
    Fitness Gadget Shootout : Fitness Gadgets (Part 2) - Motorola MOTOACTV, Nike+ Fuelband
    System Center Configuration Manager 2007 : Configuration Manager Network Communications (part 4) - Site-to-Site Communications - Tuning Status Message Replication
    Nokia Lumia 920 - Windows Phone with PureView Camera
    Windows 8 vs OS X Mountain Lion (Part 2)
    Managing Windows 8 native applications (part 3) - Controlling applications by using AppLocker
    BlackBerry Push APIs (part 1) - Building an Application that Uses the BlackBerry Push APIs - BlackBerry Push API Domains , Subscriber Registration
    Four Of The Best Stereo Systems (Part 4)
    Nvidia GeForce GTX Titan 6 GB Graphics Card Review (Part 1)
    Top 10
    The Citroën C4 Picasso – An Interesting Option
    The Mini JCW GP – Fun And Infectious
    The Renaultsport Clio 200 Turbo – A Good Hot Hatchback
    The Skoda Octavia Ambition 1.4 TSI – Fun Factory
    The Subaru WRX STI – An Extremely Quick Daily Driver
    Outdoor Speaker Buyer Guide (Part 2)
    Outdoor Speaker Buyer Guide (Part 1) - Gaelen Andrews, Portable Outdoor Speakers
    Preamplifier/DAC Gato Audio PRD-3 Review (Part 2)
    Preamplifier/DAC Gato Audio PRD-3 Review (Part 1)
    ReADL EH008 Dual Dynamic Driver Earphones