Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: Texture filter and atlas image distortion problem

  1. #11
    Junior Member Newbie
    Join Date
    May 2018
    Posts
    9
    So the start coordinates, width and height of a subtexture in atlas must all be multiple of scale factor in bilinear and also scale factors of used mipmaps in trilinear. This seems like impossible to achieve, is trying to avoid that bleeding (and subpixels) an achievable thing and worthy effort?

    (I also try to scale all graphics according to mobile device resolution which may need non-integer scale ratios)

  2. #12
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,928
    Quote Originally Posted by hellgasm View Post
    So the start coordinates, width and height of a subtexture in atlas must all be multiple of scale factor in bilinear and also scale factors of used mipmaps in trilinear. This seems like impossible to achieve
    The borders of each subtexture must be aligned to texel boundaries for all of the mipmap levels you will actually use. So the dimensions of each subtexture need to be a multiple of the texel size of the lowest-resolution mipmap level which will be used. This tends to be trivially true if all subtextures have power-of-two sizes, but that isn't a requirement.

    Quote Originally Posted by hellgasm View Post
    is trying to avoid that bleeding (and subpixels) an achievable thing and worthy effort?
    Yes.

    Quote Originally Posted by hellgasm View Post
    (I also try to scale all graphics according to mobile device resolution which may need non-integer scale ratios)
    In which case, you have to choose between the jagged-ness of "nearest" filtering modes or the blur of linear filtering. For icons, alpha-testing may be an option, but even these don't work particularly well with features not much larger than a pixel.

  3. #13
    Junior Member Newbie
    Join Date
    May 2018
    Posts
    9
    Quote Originally Posted by GClements View Post
    The borders of each subtexture must be aligned to texel boundaries for all of the mipmap levels you will actually use. So the dimensions of each subtexture need to be a multiple of the texel size of the lowest-resolution mipmap level which will be used. This tends to be trivially true if all subtextures have power-of-two sizes, but that isn't a requirement.
    Lowest resolution? If I use various different scale factors between 0.5x to 0.125x and suppose I have a 125x125 image in 2048x2048 atlas. Lowest resolution mipmap used is 64x64. If I make my image 128x128 its dimensions are multiples of 64x64 and 128x128 but not 256x256? Can you give me an example?

    Quote Originally Posted by GClements View Post
    In which case, you have to choose between the jagged-ness of "nearest" filtering modes or the blur of linear filtering. For icons, alpha-testing may be an option, but even these don't work particularly well with features not much larger than a pixel.
    So I should forget about mipmapping if there are many different scale ratios and they can even be non-integers. I think Linear has problems with decimal pixels, too.

    When I use MipMapLinearLinear with decimal scale ratios, my textures get clipped at the edges. Probably because fully transparent pixels (0, 0, 0, 0) bleed.

  4. #14
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,928
    Quote Originally Posted by hellgasm View Post
    Lowest resolution? If I use various different scale factors between 0.5x to 0.125x and suppose I have a 125x125 image
    Is 125 a typo?

    Quote Originally Posted by hellgasm View Post
    in 2048x2048 atlas. Lowest resolution mipmap used is 64x64. If I make my image 128x128 its dimensions are multiples of 64x64 and 128x128 but not 256x256? Can you give me an example?
    2048/64=32. I.e. an aligned 32x32 block in the base texture will be a single texel in the 64x64 mipmap level. So all of your subtextures must have dimensions which are multiples of 32.

    Quote Originally Posted by hellgasm View Post
    So I should forget about mipmapping if there are many different scale ratios and they can even be non-integers. I think Linear has problems with decimal pixels, too.
    You should definitely be using mipmaps if you're planning on minifying textures. But you need to ensure that the subtextures within the atlas have suitable dimensions; you can't just use arbitrary dimensions without taking into account the resolution of the mipmap levels.

    Also: you need to ensure that the type used for texture coordinates has adequate precision. Normalised types are problematic because the denominator is 2n-1, not 2n. Bytes aren't sufficient, shorts are borderline.

  5. #15
    Junior Member Newbie
    Join Date
    May 2018
    Posts
    9
    Quote Originally Posted by GClements View Post
    Is 125 a typo?
    No. Why should it be? I meant 0.125x = 1/8. And the image in that example was 125x125 before modifying it for mipmaps and changing dimensions to power of two. If 125 being odd number you are talking about, then let it be 124x124 i just gave an arbitrary number as example.

    Also I can adjust subtexture sizes, this is OK but texture atlas is generated by texture packer programs and they don't seem to care about starting positions. I can make my own texture packer or modify existing ones but still I wonder if its a "wise" choice

    My last question is:

    I have textures in max resolution I support (for example 8k or 1080p) in an atlas. I never magnify and just need to minify. My application will always be fullscreen and since I target mobile, device resolutions are non-standard. The scale factor may be different on each device and I cannot know that when preparing atlas. Maybe relying on OpenGL texture filters is bad idea for this scenario after all and I should use a better re-sizing algorithm at program startup?

    Also:
    Quote Originally Posted by hellgasm View Post
    When I use MipMapLinearLinear with decimal scale ratios, my textures get clipped at the edges.
    Quote Originally Posted by GClements View Post
    Also: you need to ensure that the type used for texture coordinates has adequate precision. Normalised types are problematic because the denominator is 2n-1, not 2n. Bytes aren't sufficient, shorts are borderline.
    I don't have problems with normalised types or variable types. It's about subpixels I think. For some reason when I position my textures at decimal coords or scale factor is something like 3.2, texture is clipped at edges.
    Last edited by hellgasm; 05-21-2018 at 04:04 PM.

  6. #16
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,928
    Quote Originally Posted by hellgasm View Post
    No. Why should it be? I meant 0.125x = 1/8. And the image in that example was 125x125 before modifying it for mipmaps and changing dimensions to power of two. If 125 being odd number you are talking about, then let it be 124x124 i just gave an arbitrary number as example.
    Well, if you want to use a 1/8-scale mipmap, the size neeeds to be a multiple of 8. So 124x124 won't work either.

    Quote Originally Posted by hellgasm View Post
    Also I can adjust subtexture sizes, this is OK but texture atlas is generated by texture packer programs and they don't seem to care about starting positions. I can make my own texture packer or modify existing ones but still I wonder if its a "wise" choice
    You can probably assume that an atlas generator isn't going to introduce arbitrary gaps. So if all of the subtexture sizes are multiples of 8 (or whatever), then the subtextures should be aligned to multiples of 8 regardless of exactly how the code chooses to pack them.

    Quote Originally Posted by hellgasm View Post
    I have textures in max resolution I support (for example 8k or 1080p) in an atlas. I never magnify and just need to minify. My application will always be fullscreen and since I target mobile, device resolutions are non-standard. The scale factor may be different on each device and I cannot know that when preparing atlas. Maybe relying on OpenGL texture filters is bad idea for this scenario after all and I should use a better re-sizing algorithm at program startup?
    Well, you can't guarantee integer scale factors if you're scaling fixed-size images to an arbitrary display resolution. Rescaling images prior to texture creation allows for more control over the rescaling algorithm. Depending upon the nature of the images, you might be better off using a vector format (e.g. SVG) and rasterising at the target resolution.

    Quote Originally Posted by hellgasm View Post
    I don't have problems with normalised types or variable types. It's about subpixels I think. For some reason when I position my textures at decimal coords or scale factor is something like 3.2, texture is clipped at edges.
    I'm not sure what you're saying. You'll need to provide a concrete example.

  7. #17
    Junior Member Newbie
    Join Date
    May 2018
    Posts
    9
    Quote Originally Posted by GClements View Post
    I'm not sure what you're saying. You'll need to provide a concrete example.
    I have a 128x128 yellow rectangle with black borders. When I put them to some integer coordinate like 100, 100 (pixel coords) there is no problem, they are rendered exactly as they should. But when I put them on 100.5, 100.5 they are rendered like this

    Original rectangle image:
    Click image for larger version. 

Name:	whcFvxfM_o.png 
Views:	20 
Size:	263 Bytes 
ID:	2768

    Rectangle at decimal position (with MipMapLinearLinear filter):
    Click image for larger version. 

Name:	XeiucE0D_o.png 
Views:	23 
Size:	1.2 KB 
ID:	2769

    Similar thing happens when width and height are decimal, too. Edges of texture are clipped.

    Is this because of how OpenGL renders pixels smaller than 1? Should I expect the same thing to happen when minification with a scale factor which has a non-integer denominator?

  8. #18
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,480
    Your reference to MipMapLinearLinear (presumably GL_LINEAR_MIPMAP_LINEAR under-the-hood) suggest that you are sampling your texture with trilinear filtering.

    However, the fact that your 2nd image shows no pixels which are partial blends between 100% black and your yellow color (0xFFF200) seems to contradict that.

    Perhaps you should show the code for how you're creating and sampling your texture.

Posting Permissions

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