logo
Expand description

How to retrieve data from a sampled image within a shader.

When you retrieve data from a sampled image, you have to pass the coordinates of the pixel you want to retrieve. The implementation then performs various calculations, and these operations are what the Sampler object describes.

Level of detail

The level-of-detail (LOD) is a floating-point value that expresses a sense of how much texture detail is visible to the viewer. It is used in texture filtering and mipmapping calculations.

LOD is calculated through one or more steps to produce a final value. The base LOD is determined by one of two ways:

  • Implicitly, by letting Vulkan calculate it automatically, based on factors such as number of pixels, distance and viewing angle. This is done using an ImplicitLod SPIR-V sampling operation, which corresponds to the texture* functions not suffixed with Lod in GLSL.
  • Explicitly, specified in the shader. This is done using an ExplicitLod SPIR-V sampling operation, which corresponds to the texture*Lod functions in GLSL.

It is possible to provide a bias to the base LOD value, which is simply added to it. An LOD bias can be provided both in the sampler object and as part of the sampling operation in the shader, and are combined by addition to produce the final bias value, which is then added to the base LOD.

Once LOD bias has been applied, the resulting value may be clamped to a minimum and maximum value to provide the final LOD. A maximum may be specified by the sampler, while a minimum can be specified by the sampler or the shader sampling operation.

Texel filtering

Texel filtering operations determine how the color value to be sampled from each mipmap is calculated. The filtering mode can be set independently for different signs of the LOD value:

  • Negative or zero: magnification. The rendered object is closer to the viewer, and each pixel in the texture corresponds to exactly one or more than one framebuffer pixel.
  • Positive: minification. The rendered object is further from the viewer, and each pixel in the texture corresponds to less than one framebuffer pixel.

Modules

Conversion from sampled YCbCr image data to RGB shader data.

Structs

A mapping between components of a source format and components read by a shader.
Describes how to retrieve data from a sampled image within a shader.
Parameters to create a new Sampler.

Enums

The color to use for the border of an image.
Describes the value that an individual component must return when being accessed.
Describes how the color of each pixel should be determined.
How the sampler should behave when it needs to access a pixel that is out of range of the texture.
Error that can happen when creating an instance.
Describes which mipmap from the source to use.
Describes how the value sampled from a mipmap should be calculated from the selected pixels, for the Linear and Cubic filters.

Constants

A special value to indicate that the maximum LOD should not be clamped.