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 5 of 5

Thread: sub-ranged texture() in GLSL

Threaded View

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Apr 2009
    Posts
    600

    sub-ranged texture() in GLSL

    The basic idea of this suggestion is to make texture atlasing less awful to do. Create (another!) texture function of the form:

    Code :
    texture(sampler2D T, vec2 p, vec4 rect)

    which does the sampling restricted to rect (encoded as .xy=position withing texture and .zw=size within texture) i.e. the texture coordinate p is relative to rect. Without filtering, it is equivalent to

    Code :
    texture(T, p, rect) == texture(T, rect.xy + rect.zw*p)

    with filtering is where it is useful, texels on the boundary of rect get filtered with the texel on the opposite size for repeat, and with itself for mirror repeat, mirror and clamp. Extending, I want this:

    Code :
    enum RepeatMode
    {
        mirror,
        repeat,
        clamp,
        mirror_repeat
    }
     
     
    texture(sampler2D T, vec2 p, vec4 rect, enum RepeatMode mode);

    this does fit in with mipmapping and gives what you want IF both:
    • the texel-size of rect is a power of 2 AND
    • the boundary of rect is a multiple of the size of rect



    Naturally this above can be logically extended to textureLod, textureGrad, textureProj, textureProjGrad, texture arrays, 1D textures, 3D textures, and texture rectangles. [3D textures will needs that the rect is a cube].

    As a side note, it is debatable if it is also worth adding another enumeration argument stating if the filtering is linear or nearest. [mipmap filtering is essentially handled by LOD, though one can argue the filtering between mip maps also needs to be specified].

    One can naturally emulate this doing the filtering by hand in shader using texelFetch, but that seems like an unnecessary burden on a developer and a potential optimization lost on the hardware.
    Last edited by kRogue; 09-18-2012 at 01:23 AM.

Posting Permissions

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