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.
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
ImplicitLodSPIR-V sampling operation, which corresponds to the
texture*functions not suffixed with
- Explicitly, specified in the shader. This is done using an
ExplicitLodSPIR-V sampling operation, which corresponds to the
texture*Lodfunctions 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 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.