If the image sampler instruction provides normalized texel coordinates, some of the following operations are performed.
For Proj
image operations, the normalized texel coordinates
$(s,t,r,q,a)$
and (if present) the
$D_{ref}$
coordinate are transformed as follows:
Derivatives are used for level-of-detail selection. These derivatives are
either implicit (in an ImplicitLod
image instruction in a fragment
shader) or explicit (provided explicitly by shader to the image instruction
in any shader).
For implicit derivatives image instructions, the derivatives of texel coordinates are calculated in the same manner as derivative operations above. That is:
Partial derivatives not defined above for certain image dimensionalities are set to zero.
For explicit level-of-detail image instructions, if the optional SPIR-V operand $Grad$ is provided, then the operand values are used for the derivatives. The number of components present in each derivative for a given image dimensionality matches the number of partial derivatives computed above.
If the optional SPIR-V operand $Lod$ is provided, then derivatives are set to zero, the cube map derivative transformation is skipped, and the scale factor operation is skipped. Instead, the floating point scalar coordinate is directly assigned to $\lambda_{base}$ as described in Level-of-Detail Operation.
For cube map image instructions, the $(s,t,r)$ coordinates are treated as a direction vector $(r_{x},r_{y},r_{z})$ . The direction vector is used to select a cube map face. The direction vector is transformed to a per-face texel coordinate system $(s_{face},t_{face})$ . The direction vector is also used to transform the derivatives to per-face derivatives.
The direction vector selects one of the cube map’s faces based on the largest magnitude coordinate direction (the major axis direction). Since two or more coordinates can have identical magnitude, the implementation must have rules to disambiguate this situation.
The rules should have as the first rule that $r_{z}$ wins over $r_{y}$ and $r_{x}$ , and the second rule that $r_{y}$ wins over $r_{x}$ . An implementation may choose other rules, but the rules must be deterministic and depend only on $(r_{x},r_{y},r_{z})$ .
The layer number (corresponding to a cube map face), the coordinate selections for $s_{c}$ , $t_{c}$ , $r_{c}$ , and the selection of derivatives, are determined by the major axis direction as specified in the following two tables.
Table 15.4. Cube map face and coordinate selection
Major Axis Direction | Layer Number | Cube Map Face | $s_{c}$ | $t_{c}$ | $r_{c}$ |
---|---|---|---|---|---|
$+r_{x}$ | $0$ | $Positive X$ | $-r_{z}$ | $-r_{y}$ | $r_{x}$ |
$-r_{x}$ | $1$ | $Negative X$ | $+r_{z}$ | $-r_{y}$ | $r_{x}$ |
$+r_{y}$ | $2$ | $Positive Y$ | $+r_{x}$ | $+r_{z}$ | $r_{y}$ |
$-r_{y}$ | $3$ | $Negative Y$ | $+r_{x}$ | $-r_{z}$ | $r_{y}$ |
$+r_{z}$ | $4$ | $Positive Z$ | $+r_{x}$ | $-r_{y}$ | $r_{z}$ |
$-r_{z}$ | $5$ | $Negative Z$ | $-r_{x}$ | $-r_{y}$ | $r_{z}$ |
Table 15.5. Cube map derivative selection
Major Axis Direction | $\partial{s_{c}}/\partial{x}$ | $\partial{s_{c}}/\partial{y}$ | $\partial{t_{c}}/\partial{x}$ | $\partial{t_{c}}/\partial{y}$ | $\partial{r_{c}}/\partial{x}$ | $\partial{r_{c}}/\partial{y}$ |
---|---|---|---|---|---|---|
$+r_{x}$ | $-\partial{r_{z}}/\partial{x}$ | $-\partial{r_{z}}/\partial{y}$ | $-\partial{r_{y}}/\partial{x}$ | $-\partial{r_{y}}/\partial{y}$ | $+\partial{r_{x}}/\partial{x}$ | $+\partial{r_{x}}/\partial{y}$ |
$-r_{x}$ | $+\partial{r_{z}}/\partial{x}$ | $+\partial{r_{z}}/\partial{y}$ | $-\partial{r_{y}}/\partial{x}$ | $-\partial{r_{y}}/\partial{y}$ | $-\partial{r_{x}}/\partial{x}$ | $-\partial{r_{x}}/\partial{y}$ |
$+r_{y}$ | $+\partial{r_{x}}/\partial{x}$ | $+\partial{r_{x}}/\partial{y}$ | $+\partial{r_{z}}/\partial{x}$ | $+\partial{r_{z}}/\partial{y}$ | $+\partial{r_{y}}/\partial{x}$ | $+\partial{r_{y}}/\partial{y}$ |
$-r_{y}$ | $+\partial{r_{x}}/\partial{x}$ | $+\partial{r_{x}}/\partial{y}$ | $-\partial{r_{z}}/\partial{x}$ | $-\partial{r_{z}}/\partial{y}$ | $-\partial{r_{y}}/\partial{x}$ | $-\partial{r_{y}}/\partial{y}$ |
$+r_{z}$ | $+\partial{r_{x}}/\partial{x}$ | $+\partial{r_{x}}/\partial{y}$ | $-\partial{r_{y}}/\partial{x}$ | $-\partial{r_{y}}/\partial{y}$ | $+\partial{r_{z}}/\partial{x}$ | $+\partial{r_{z}}/\partial{y}$ |
$-r_{z}$ | $-\partial{r_{x}}/\partial{x}$ | $-\partial{r_{x}}/\partial{y}$ | $-\partial{r_{y}}/\partial{x}$ | $-\partial{r_{y}}/\partial{y}$ | $-\partial{r_{z}}/\partial{x}$ | $-\partial{r_{z}}/\partial{y}$ |
![]() | editing-note |
---|---|
(Bill) Note that we never revisited ARB_texture_cubemap after we introduced dependent texture fetches (ARB_fragment_program and ARB_fragment_shader). The derivatives of $s_{face}$ and $t_{face}$ are only valid for non-dependent texture fetches (pre OpenGL 2.0). |
Level-of-detail selection can be either explicit (provided explicitly by the image instruction) or implicit (determined from a scale factor calculated from the derivatives).
The magnitude of the derivatives are calculated by:
where:
The scale factors $(\rho_{x}, \rho{y})$ should be calculated by:
The ideal functions $\rho_{x}$ and $\rho_{y}$ may be approximated with functions $f_x$ and $f_y$ , subject to the following constraints:
![]() | editing-note |
---|---|
(Bill) For reviewers only - anticipating questions. We only support implicit derivatives for normalized texel coordinates. So we are documenting the derivatives in s,t,r (normalized texel coordinates) rather than u,v,w (unnormalized texel coordinates) as in OpenGL and OpenGL ES specifications. (I know, u,v,w is the way it has been documented since OpenGL V1.0.) Also there is no reason to have conditional application of $w_{base} , h_{base} , d_{base}$ for rectangle textures either, since they do not support implicit derivatives. |
The minimum and maximum scale factors $(\rho_{min},\rho_{max})$ are determined by:
The sampling rate is determined by:
where:
If $\rho_{max} = \rho_{min} = 0$ , then all the partial derivatives are zero, the fragment’s footprint in texel space is a point, and $N$ should be treated as 1. If $\rho_{max} \neq 0 \textrm{ and } \rho_{min} = 0$ then all partial derivatives along one axis are zero, the fragment’s footprint in texel space is a line segment, and $N$ should be treated as $max_{Aniso}$ . However, anytime the footprint is small in texel space the implementation may use a smaller value of $N$ , even when $\rho_{min}$ is zero or close to zero.
An implementation may round $N$ up to the nearest supported sampling rate.
If $N=1$ , sampling is isotropic. If $N>1$ , sampling is anisotropic.
The level-of-detail parameter $\lambda$ is computed as follows:
where:
and
$maxSamplerLodBias$
is the value of the
VkPhysicalDeviceLimits
feature
maxSamplerLodBias
.
The image level(s)
$d, d_{hi},\textrm{ and }d_{lo}$
which texels
are read from are selected based on the level-of-detail parameter, as
follows. If the sampler’s mipmapMode
is
VK_SAMPLER_MIPMAP_MODE_NEAREST
, then level d is used:
where:
and
$q = \mathit{levelCount} - 1$
levelCount
is taken from the subresourceRange
of the
image view.
If the sampler’s mipmapMode
is VK_SAMPLER_MIPMAP_MODE_LINEAR
,
two neighboring levels are selected:
$\delta$ is the fractional value used for linear filtering between levels.
The normalized texel coordinates are scaled by the image level dimensions and the array layer is selected. This transformation is performed once for each level ( $d\textrm{ or }d_{hi}\textrm{ and }d_{lo}$ ) used in filtering.
Operations then proceed to Unnormalized Texel Coordinate Operations.