PDA

View Full Version : Integer Texture Filtering



Aleksandar
03-09-2014, 08:31 AM
Hi all,

This was a problem I've encountered several years ago, but since it could be neglected then I repressed it.
Yesterday it appeared once again and now it is crucial to be solved. The problem is that I cannot use GL_LINEAR (minification/magnification) filtering on textures with GL_R16UI internal format. It seems like GL_NEAREST is used instead. Is it something common and normal, or I have some other problem in the application? Did anyone have a similar issue?

Thanks in advance!

arekkusu
03-10-2014, 12:21 PM
That's by design. Pure integer formats don't allow any form of filtering (they are treated as "incomplete" if the current sampler would need filtering.)

If you want to filter them, do it manually in a shader (you get to decide what happens with the low bit.)

Aleksandar
03-11-2014, 03:18 AM
Thank you very much for the answer, arekkusu!

That's exactly what I was afraid of. I've chosen GL_R16UI format because it gives me the best precision/size ratio. GL_R32F is twice the size of GL_R16UI, while GL_R16F doesn't have enough precision. I'll try filtering in the shader (VS), but I guess the performance will not be great because of multiple texture readings plus setting more uniforms in order to precisely define extent and boundaries of the texels (for each layer of the array), plus math for calculating offset and linear interpolation. Texture filtering is something we've got for free.
:doh:

Osbios
03-11-2014, 06:31 AM
With only one component in your texture you could use textureGather (ARB_texture_gather) to sample 4 values with one sample.

arekkusu
03-11-2014, 12:04 PM
How about simply using GL_R16 (UNORM?)

Aleksandar
03-11-2014, 12:06 PM
Thank you for the suggestion, Osbios!

Unfortunately, GL_ARB_texture_gather is not supported in GL3.x, or to be more precise in NV Cg gp4vp profile.
That significantly limits the usage, but I'll try it certainly.

Aleksandar
03-11-2014, 12:20 PM
How about simply using GL_R16 (UNORM?)
Thanks for the suggestion, but glTexImage3D() simply refuses to accept it as an internal format if I provide integer source data.
Here is the corresponding code segment:


m_nInternalFormat = GL_R16UI; // or GL_R16I
m_nDataFormat = GL_RED_INTEGER;
m_nDataType = GL_UNSIGNED_SHORT;
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, m_nInternalFormat, width, height, m_nLevelsNo, 0, m_nDataFormat, m_nDataType, NULL);

Maybe there is something I have overlooked.

Thank you very much for the help!

arekkusu
03-11-2014, 12:24 PM
GL_R16 isn't integer, it's UNORM. Just like GL_R8, or GL_RGBA8.

So, you're over-complicating things:
glTexImage3D(...GL_R16... GL_RED, GL_UNSIGNED_SHORT...)

(and use a sampler2DArray, not a usampler2DArray).

Aleksandar
03-11-2014, 02:55 PM
Thank you, arekkusu, a million times! :)
This works excellent!