Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Bilinear filtering in fragment program using GLSL

  1. #1
    Intern Contributor
    Join Date
    Nov 2003
    Location
    Russia / Saint-Petersburg
    Posts
    50

    Bilinear filtering in fragment program using GLSL

    How to do custom subj in fragment program with filtering mode set to GL_NEAREST ?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: Bilinear filtering in fragment program using GLSL

    What does "subj" mean in your question?
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Bilinear filtering in fragment program using GLSL

    I think subj is an alias for the title.

    You can do something quick and cheap with clamping the texcoord, then do sampling at the 4 local texels :

    {x, y)
    (x+1, y)
    (x, y+1)
    (x+1, y+1)

    then do a weighted blend between the 4.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  4. #4
    Intern Contributor
    Join Date
    Nov 2003
    Location
    Russia / Saint-Petersburg
    Posts
    50

    Re: Bilinear filtering in fragment program using GLSL

    I've understood how to do it!

    float OneTexel = 1.0/TextureSize;

    vec2 coord1 = TexCoord0+vec2(0.0, OneTexel);
    vec2 coord2 = TexCoord0+vec2(OneTexel, 0.0 );
    vec2 coord3 = TexCoord0+vec2(OneTexel, OneTexel);
    vec2 coord4 = TexCoord0;

    vec4 s1 = vec4(texture2D(Texture0, coord1));
    vec4 s2 = vec4(texture2D(Texture0, coord2));
    vec4 s3 = vec4(texture2D(Texture0, coord3));
    vec4 s4 = vec4(texture2D(Texture0, coord4));

    vec2 Dimensions = vec2(TexCoord0) * TextureSize;

    float fu = fract(Dimensions.x);
    float fv = fract(Dimensions.y);

    vec4 tmp1 = mix(s4, s2, fu);
    vec4 tmp2 = mix(s1, s3, fu);

    vec4 t0 = mix(tmp1, tmp2, fv);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •