4.4 Texture and Array Access

Texture accesses also use both the “[]” and “()” operators. In both cases this operator has one argument which is used as the lookup index. This operator may be a shader run-time variable.

For textures, this argument need not be a ShTexCoord (although that would be common) but should either be the same dimension as the declared texture coordinate dimension or one larger. If it is one larger, the last coordinate is assumed to be a homogeneous component and is divided out for lookup. This factor is simply ignored for cube map lookups. For the ShArray types, only the integer part of the parameter is considered.

The “()” and “[]” operators differ in that “()” scales the texture coordinate range to the declared size of the texture while “[]” uses integer coordinates. The scale on “()” is defined so that (0,0) picks up the texel in the lower left and (1,1) picks up the texel in the upper right. This makes these lookups independent of the resolution of the texture. The “[]” operator accesses texels centered at each integer. This access operator is most useful with the ShArray type when it is used to implement data structures.


Note: This manual is available as a bound book from AK Peters, including better formatting, in-depth examples, and about 200 pages not available on-line.