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 Dref 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 λbase as described in Level-of-Detail Operation.
For cube map image instructions, the (s,t,r) coordinates are treated as a direction vector (rx,ry,rz). The direction vector is used to select a cube map face. The direction vector is transformed to a per-face texel coordinate system (sface,tface), 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 rz wins over ry and rx, and the second rule that ry wins over rx. An implementation may choose other rules, but the rules must be deterministic and depend only on (rx,ry,rz).
The layer number (corresponding to a cube map face), the coordinate selections for sc, tc, rc, 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 | sc | tc | rc |
---|---|---|---|---|---|
+rx | 0 | Positive X | -rz | -ry | rx |
-rx | 1 | Negative X | +rz | -ry | rx |
+ry | 2 | Positive Y | +rx | +rz | ry |
-ry | 3 | Negative Y | +rx | -rz | ry |
+rz | 4 | Positive Z | +rx | -ry | rz |
-rz | 5 | Negative Z | -rx | -ry | rz |
Table 15.5. Cube map derivative selection
Major Axis Direction | ∂sc / ∂x | ∂sc / ∂y | ∂tc / ∂x | ∂tc / ∂y | ∂rc / ∂x | ∂rc / ∂y |
---|---|---|---|---|---|---|
+rx | -∂rz / ∂x | -∂rz / ∂y | -∂ry / ∂x | -∂ry / ∂y | +∂rx / ∂x | +∂rx / ∂y |
-rx | +∂rz / ∂x | +∂rz / ∂y | -∂ry / ∂x | -∂ry / ∂y | -∂rx / ∂x | -∂rx / ∂y |
+ry | +∂rx / ∂x | +∂rx / ∂y | +∂rz / ∂x | +∂rz / ∂y | +∂ry / ∂x | +∂ry / ∂y |
-ry | +∂rx / ∂x | +∂rx / ∂y | -∂rz / ∂x | -∂rz / ∂y | -∂ry / ∂x | -∂ry / ∂y |
+rz | +∂rx / ∂x | +∂rx / ∂y | -∂ry / ∂x | -∂ry / ∂y | +∂rz / ∂x | +∂rz / ∂y |
-rz | -∂rx / ∂x | -∂rx / ∂y | -∂ry / ∂x | -∂ry / ∂y | -∂rz / ∂x | -∂rz / ∂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 sface and tface 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:
and
(for the baseMipLevel
, from the image descriptor).
The scale factors (ρx, ρy) should be calculated by:
The ideal functions ρx and ρy may be approximated with functions fx and fy, 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 wbase, hbase, dbase for rectangle textures either, since they do not support implicit derivatives. |
The minimum and maximum scale factors (ρmin,ρmax) are determined by:
The sampling rate is determined by:
where:
maxAnisotropy
(from sampler
descriptor)
maxSamplerAnisotropy
(from physical
device limits)
If ρmax = ρ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 ρmax ≠ 0 and ρ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 maxAniso. However, anytime the footprint is small in texel space the implementation may use a smaller value of N, even when ρ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 λ is computed as follows:
where:
and maxSamplerLodBias is the value of the VkPhysicalDeviceLimits
feature maxSamplerLodBias
.
The image level(s) d, dhi, and dlo 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
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:
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 or dhi and dlo) used in filtering.
Operations then proceed to Unnormalized Texel Coordinate Operations.