0

I am not sure how exactly the texture2D command works in GLSL with linear filtering. How does it choose and linearly interpolate between pixels.

Imagine I had a texture with 4 grayscale pixels of value {0, 1, 2, 3}. And I wanted OpenGL to draw it across a line, 8 pixels wide. How would texture2D fill those 8 pixels?

Would it be something like: {0, .375(3/8), .75(6/8), 1.125(9/8), 1.5(12/8), 1.875(15/8), 2.25(18/8), 2.625(21/8), 3}?

user3758015
  • 119
  • 1
  • 9

1 Answers1

0

in fact there are 2 aspects in the question: - yes, GL_LINEAR means it's a linear interpolation, in each direction (so, bilinear). - now, texture pixels and screen pixels might not fall exactly face to face, depending whether the floating point value of the vertex project it at the center or at the corner. So it changes first,last, and indeed all intermediate values.

Note that for these questions, it is almost quicker to experiment than to discuss about it: doing fast small experiment in GLSL(ES) is straightforward on web sites such as shadertoy, for instance.

Fabrice NEYRET
  • 644
  • 4
  • 16