# The Industry's Foundation for High Performance Graphics

1. ## 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.

2. Originally Posted by JoshKlint
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. 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. Originally Posted by JoshKlint
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. 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.

#### Posting Permissions

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