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.

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.

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.

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/