Texture functions

Sample texture data

float4 sample(sampler s, float2 coord, int2 offset = int2(0))

The function returns the value of a texture for the given coordinates using the specified sampler and offset. The dimension of the coordinate and offset vector has to match the dimension of the texture.

The return type is a 4-component vector that is derived from the type specified in the texture declaration.

texture2d<float> texture

The available types are float, half, int, uint, short and ushort.

Read texture data

float4 read(uint2 coord, uint lod = 0)

The function returns the value of a texture for the given coordinates using the specified level of detail (sampler-less). The dimension of the coordinate has to match the dimension of the texture.

The return type is a 4-component vector that is derived from the type specified in the texture declaration.

texture2d<float> texture

The available types are float, half, int, uint, short and ushort.

Texture width

uint get_width(uint lod = 0)

The function returns the width of a texture using the specified level of detail.

Texture height

uint get_height(uint lod = 0)

The function returns the height of a texture using the specified level of detail.

Number of mipmaps

uint get_num_mip_levels()

The function returns number of mipmaps of a texture.