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: Cube and shadow multisample textures

  1. #1
    Junior Member Regular Contributor
    Join Date
    Mar 2009
    Location
    California
    Posts
    188

    Cubemap lookup jitter

    Does anyone have a quick formula for adding offsets when taking multiple samples in a cubemap shadow lookup? With a 2D texture, you can just take 1.0/textureSize for the offset, but with 3D cubemap coordinates it's a little harder.
    Last edited by JoshKlint; 09-23-2013 at 10:39 AM.

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by JoshKlint View Post
    Does anyone have a quick formula for adding offsets when taking multiple samples in a cubemap shadow lookup? With a 2D texture, you can just take 1.0/textureSize for the offset, but with 3D cubemap coordinates it's a little harder.
    If you just want a 2x2 neighbourhood for filtering, use textureGather().:
    Code :
    vec4 textureGather(samplerCubeShadow sampler, vec3 P, float refZ)
    It returns a vec4 containing the four texels which would be used for bilinear interpolation, in the order: top-left, top-right, bottom-right, bottom-left (in the sense that "bottom-left" means "toward (0,0)"; the actual orientation of cube map faces isn't particularly intuitive).

    If you need something more general, you'll need to reproduce the cube-map lookup algorithm (section 8.13 in recent versions of the specification). In which case, there isn't much point in using a cube map in the first place; you may as well just use an array texture with 6 layers.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Mar 2009
    Location
    California
    Posts
    188
    I figured out how to do it correctly, but it's quite a lot of math.

    Does textureGather return the same result as just doing a single texture lookup with linear filtering enabled?

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by JoshKlint View Post
    Does textureGather return the same result as just doing a single texture lookup with linear filtering enabled?
    textureGather() returns the four values which would be used for bilinear filtering.

    For shadow samplers (which always have a single component), it returns a vec4 instead of a float. For samplers which can use textures with multiple components, it takes an extra integer argument, comp, to select which component is returned, so e.g. comp=1 will return a vec4 containing the green component from each of the four texels.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    Also, in order to get proper values returned from textureGather when using cube maps, make sure you have seamless cube map filtering enabled, otherwise you won't get the proper 2x2 neighborhood when sampling around the edges of the cube map.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

Posting Permissions

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