GL_NEAREST 和 GL_LINEAR

2019-04-15 15:11发布

OPENGL TEXTURE DIFFERENCE BETWEEN GL_LINEAR AND GL_NEAREST

Growly Notes glsl 1 Growly Notes glsl source: http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html Comments [0]
Suppose a picture of size 3 pixels x 3 pixels, which a zoom result to this :
Zoom on the 3x3 picture Texture 'pixels' are called texels. A texel is associated with a color and correspond to a region on the UV system (texture coordinate system). Texels are represented in the following pictures.
The texture associated of this picture can be represented by the picture shown below.
Texture texels In most cases, the uv coordinate read on the texture does not correspond to a texel center. It is generaly between two texels.
To determine the uv color, there are different ways :
  • Pick up the the closest texel, and use its color (GL_NEAREST). This is equivalent to zooming on the picture.
  • Linear interpolation of the color between the two closest texels (GL_LINEAR)
 
GL_NEAREST & GL_LINEAR Here is the result of these two methods :
Zoom on the original picture (4x4 pixels)  
GL_NEAREST vs GL_LINEAR