7.18 Texture Sampling
7.18 纹理采样****
7.18.1 Overview
7.18.1 概述****
This section describes the mechanics of sampling Texture1D/2D/3D/Cube resources using filtering.The simplest form of sampling a texture is point sampling, supported for all data formats, however more complex filtering operations are only available to some formats, indicated in the format list in the Formats(19.1) section.
本节介绍使用过滤对 Texture1D/2D/3D/Cube 资源进行采样的机制。对纹理进行采样的最简单形式是点采样,支持所有数据格式,但更复杂的过滤操作仅适用于某些格式,如“格式 (19.1) ”部分的格式列表中所示。
The behaviors described here are obtained via the the various sample* instructions, such as sample(22.4.15). See the specs for those instructions for further details that complement this section.
此处描述的行为是通过各种 sample* 指令获得的,例如 sample (22.4.15) 。请参阅这些说明的规格,了解补充本节的更多详细信息。
sample[_aoffimmi(u,v,w)][_cl][_s]
dest[.mask],
srcAddress[.swizzle],
srcResource[.swizzle],
srcSampler
是一个在Shader Model 4或更高版本中使用的sample指令。这个指令用于从指定的纹理中采样数据。这个指令的各个部分的含义如下:
sample:这是指令的名称,表示"sample"。
[_aoffimmi(u,v,w)]:这是一个可选的后缀,表示地址偏移。它指示纹理坐标将按一组提供的立即纹素空间整数常量值进行偏移。
dest[.mask]:这是操作结果的地址。
srcAddress[.swizzle]:这是执行采样所需的纹理坐标。
srcResource[.swizzle]:这是一个必须声明的纹理寄存器 (t#),用于识别要从中提取数据的纹理或缓冲区。
srcSampler:这是一个采样器寄存器 (s#),用于指定纹理采样的方式。
这个指令是ld指令的复杂替代指令。与ld不同,sample还能够从纹理中提取数据,并进行纹理过滤,以平滑纹理中的像素值
Unless otherwise noted, all texture sampling address operations are performed according to the arithmetic processing rules described in the Basics(3) section.
除非另有说明,否则所有纹理采样地址操作均根据“基本信息 (3) ”部分中描述的算术处理规则执行。
3 Basics
3.1 Floating Point Rules
3.2 Data Conversion
3.3 Coordinate Systems
3.4 Rasterization Rules
3.5 Multisampling
Texture filtering theory or historical background is NOT provided in this spec.
本规范中未提供纹理过滤理论或历史背景。
Note that details of all required texture filtering algorithms are not fully/exactly specified for this version of D3D11.3; the specs below only explicitly define a subset of all filtering features available in D3D11.3.
请注意,所有必需的纹理过滤算法的详细信息并未在D3D11.3的这个版本中完全/精确地指定。以下规范仅显式定义 D3D11.3 中可用的所有过滤功能的子集。
7.18.2 Samplers
7.18.2 采样器****
Samplers identify filtering modes and other sampler state, described below. Samplers are not indexable from within shaders. There are 16 samplers "slots" per Pipeline stage, to which "Sampler Objects" can be arbitrarily assigned/reassigned.
采样器可识别过滤模式和其他采样器状态,如下所述。采样器不能从着色器中建立索引。每个 Pipeline 阶段有 16 个采样器“插槽”,可以任意分配/重新分配“采样器对象”。
The state for a sampler is encapsulated in a "sampler object", up to 4096 of which can be created through the API. At the time a sampler object is created, all of its state must be chosen permanently, and can never be changed. These sampler objects can be arbitrarily assigned to any of the 16 "sampler slots" at each of the Shader stages (a single sampler object is allowed to be assigned to multiple sampler slots, even on multiple pipelines stages simultaneously, if desired.
采样器的状态封装在“采样器对象”中,其中最多可通过 API 创建 4096 个。在创建采样器对象时,必须永久选择其所有状态,并且永远不能更改。这些采样器对象可以任意分配给每个着色器阶段的 16 个“采样器插槽”中的任何一个(如果需要,允许将单个采样器对象分配给多个采样器插槽,甚至可以同时在多个流水线阶段上分配。
The reason Sampler Objects are statically created, and there is a limit on the number that can be created, is to enable hardware to maintain references to multiple samplers in flight in the Pipeline, without having to track changes or flush the Pipeline, which would be necessary if Sampler Objects were allowed to be edited.
采样器对象是静态创建的,且存在创建数量的限制,这是为了使硬件能够在Pipeline中维护对多个采样器的引用,而无需跟踪更改或刷新Pipeline,如果允许编辑采样器对象,那么就需要进行这些操作。
7.18.3 Sampler State
7.18.3 采样器状态****
| typedef enum D3D11_FILTER{ // Bits used in defining enumeration of valid filters: // bits [1:0] - mip: 0 == point, 1 == linear, 2,3 unused // bits [3:2] - mag: 0 == point, 1 == linear, 2,3 unused // bits [5:4] - min: 0 == point, 1 == linear, 2,3 unused // bit [6] - aniso // bit [7] - comparison // bits [8:7] - reduction type: // 0 == standard filtering // 1 == comparison // 2 == min // 3 == max // bit [31] - mono 1-bit (narrow-purpose filter) [no longer supported in D3D11] D3D11_FILTER_MIN_MAG_MIP_POINT = 0x00000000, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR = 0x00000001, D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x00000004, D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR = 0x00000005, D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT = 0x00000010, D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x00000011, D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT = 0x00000014, D3D11_FILTER_MIN_MAG_MIP_LINEAR = 0x00000015, D3D11_FILTER_ANISOTROPIC = 0x00000055, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT = 0x00000080, D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR = 0x00000081, D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x00000084, D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR = 0x00000085, D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT = 0x00000090, D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x00000091, D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT = 0x00000094, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR = 0x00000095, D3D11_FILTER_COMPARISON_ANISOTROPIC = 0x000000d5, D3D11_FILTER_MINIMUM_MIN_MAG_MIP_POINT = 0x00000100, D3D11_FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR = 0x00000101, D3D11_FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x00000104, D3D11_FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR = 0x00000105, D3D11_FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT = 0x00000110, D3D11_FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x00000111, D3D11_FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT = 0x00000114, D3D11_FILTER_MINIMUM_MIN_MAG_MIP_LINEAR = 0x00000115, D3D11_FILTER_MINIMUM_ANISOTROPIC = 0x00000155, D3D11_FILTER_MAXIMUM_MIN_MAG_MIP_POINT = 0x00000180, D3D11_FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR = 0x00000181, D3D11_FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x00000184, D3D11_FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR = 0x00000185, D3D11_FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT = 0x00000190, D3D11_FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x00000191, D3D11_FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT = 0x00000194, D3D11_FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR = 0x00000195, D3D11_FILTER_MAXIMUM_ANISOTROPIC = 0x000001d5} D3D11_FILTER; typedef enum D3D11_TEXTURE_ADDRESS_MODE{ D3D11_TEXADDRESS_WRAP = 1, D3D11_TEXADDRESS_MIRROR = 2, D3D11_TEXADDRESS_CLAMP = 3, D3D11_TEXADDRESS_BORDER = 4, D3D11_TEXADDRESS_MIRRORONCE = 5} D3D11_TEXTURE_ADDRESS_MODE; typedef struct D3D11_SAMPLER_STATE{ D3D11_FILTER Filter; D3D11_TEXTURE_ADDRESS_MODE AddressU; // U coordinate address mode D3D11_TEXTURE_ADDRESS_MODE AddressV; // V coordinate address mode D3D11_TEXTURE_ADDRESS_MODE AddressW; // W coordinate address mode float MinLOD; float MaxLOD; float MipLODBias; // (-16.0f..15.99f) DWORD MaxAnisotropy; // (0 - 16) D3D11_COMPARISON_FUNC ComparisonFunction; // for Percentage-Closer filter float BorderColor[4]; // R,G,B,A} D3D11_SAMPLER_STATE; |
|---|
// sampler state
AddressU
AddressV
AddressW
BorderColor
Filter
MaxAnisotropy
MaxLOD
MinLOD
MipLODBias
// sampler-comparison state
ComparisonFun
例:
Texture2D gDiffuseMap;
SamplerState samAnisotropic
{
Filter = ANISOTROPIC;
MaxAnisotropy = 4;
AddressU = WRAP;
AddressV = WRAP;
};
texColor = gDiffuseMap.Sample( samAnisotropic, pin.Tex );
7.18.4 Normalized-Space Texture Coordinate Magnitude vs. Maximum Texture Size
7.18.4 归一化空间纹理坐标大小与最大纹理大小的关系****
The magnitude of normalized-space texture coordinates (allowing for texture tiling) has no effect on the maximum supportable texture dimensions that can be sampled. The only catch is that as the absolute magnitude of a normalized-space texture coordinate gets larger (e.g.large amounts of tiling), floating point dictates that less precision will be available to resolve individual texels in a given tiling of the texture being sampled.Large amounts of tiling of large dimension textures will yield sampling artifacts where float32 precision becomes inadequate.But separate from this tradoff, in order to otherwise achieve decoupling of the magnitude of normalized-space texture coordinates from having any effect on maximum texture dimension that can be sampled given float32 normalized-space addressing, a range reduction to about [-10...10], depending on the scenario, is applied on the texture coordinates.
归一化空间纹理坐标的大小(允许纹理平铺)对可采样的最大可支持纹理尺寸没有影响。唯一的问题是,随着归一化空间纹理坐标的绝对量级变大(例如大量平铺),浮点数决定了在给定纹理的平铺中解析单个纹素的精度会减小。大量使用大尺寸纹理的平铺会导致采样伪影,其中 float32 精度变得不足。但是,除了这种权衡,为了实现归一化空间纹理坐标大小的解耦,而不会对给定 float32 归一化空间寻址可采样的最大纹理维度产生一些影响,根据场景,对纹理坐标应用范围缩小到约 [-10...10]。
Details of this range reduction are described later(7.18.6). The reduction happens before scaling texture coordinates by texture size, conversion to fixed point, and final application of Texture Address modes (CLAMP/MIRROR/WRAP etc.) on texel addresses.The range reduction allows the fixed point representation to not have to dedicate storage for the texture tiling. It is important to note that range reduction is a separate step from applying Texture Address mode (although the particular Texture Address mode affects what type of reduction gets used).
此范围减少的详细信息将在后面 (7.18.6) 介绍。减少发生在按纹理大小缩放纹理坐标、转换为定点数,以及在纹素地址上最终应用纹理地址模式(CLAMP/MIRROR/WRAP等)之前。范围缩小允许定点表示不必为纹理平铺专门存储。需要注意的是,范围减少与应用纹理地址模式是不同的步骤(尽管特定的纹理地址模式影响使用哪种类型的减少)。
Using range reduction to decouple texture coordinate magnitude from supportable texture size has the following implication: The maximum texture dimension possible to be sampled in D3D11.3 is 2^17. This limit is derived starting with 24 bits of float32 fractional precision for the original texture coordinate, subtracting required subtexel precision (8 bits), and subtracting 1 more bit due to the factor of 2 scaling in the reduced range. Of course, the minimum upper limit for filterable texture dimension required to be exposed by all D3D11.3 implementations is far smaller, at only 16384 (see System Limits(21)).
使用范围减少将纹理坐标幅度与可支持的纹理大小分离具有以下含义:D3D11.3 中可能采样的最大纹理维度为 2^17。此限制是从原始纹理坐标的 24 位 float32 小数精度开始推导的,减去所需的 subtexel 精度(8 位),然后再减去 1 位,因为在缩小的范围内,比例为 2。当然,所有D3D11.3实现需要暴露的可过滤纹理尺寸的最小上限要小得多,只有16384(见系统限制(21))。
7.18.5 Processing Normalized Texture Coordinates
7.18.5 处理归一化纹理坐标****
在计算机图形学中,纹理坐标通常被归一化,这意味着无论纹理的实际尺寸如何,纹理坐标的范围都是[0,1]。这使得纹理坐标独立于任何特定的纹理尺寸。
例如,对于一个256x256的纹理,纹理坐标(0.5, 0.5)对应于纹理的中心。如果我们将纹理大小改为512x512,纹理坐标(0.5, 0.5)仍然对应于纹理的中心。这是因为纹理坐标已经被归一化,所以它们不依赖于纹理的实际尺寸。
然而,当我们在着色器中采样纹理时,我们需要考虑纹理的最大尺寸。因为GPU在执行纹理过滤时,会考虑到纹理的实际尺寸。例如,当执行线性过滤时,GPU需要读取纹理中的多个像素,并根据这些像素的颜色和纹理坐标的精确位置来计算出最终的颜色。
总的来说,虽然纹理坐标被归一化,但在进行纹理采样时,我们仍然需要考虑纹理的最大尺寸。
This section describes in general how to convert a normalized texture coordinate to a texture address. The description is based on sampling a Texture1D, but applies equally to Texture2D and Texture3D (and not TextureCubes).
本节介绍如何将归一化纹理坐标转换为纹理地址。该描述基于对 Texture1D 的采样,但同样适用于 Texture2D 和 Texture3D(不适用于 TextureCubes)。
A normalized texture coordinate (U) maps the range [0, 1] to the range [0, numTexelsU], where numTexelsU is the size of a 1D texture in texels. The process of computing a texture address is as follows:
归一化纹理坐标(U)将范围 [0,1] 映射到范围 [0,numTexelsU],其中 numTexelsU 是纹素中一维纹理的大小。纹理地址的计算过程如下:
1. Reducing the normalized texture coordinate range based on the texture address mode.
1. 根据纹理地址模式缩小归一化纹理坐标范围
2. Performing point sample or linear sample addressing (scaling the normalized texture coordinate by the texture size and snapping the value to a fixed point number with 8 bits fraction).
2. 执行点采样或线性采样寻址(按纹理大小缩放归一化纹理坐标,并将值捕捉到具有 8 位小数的定点数)。
3. Applying the texture address mode.
3. 应用纹理地址模式
例:
假设我们有一个1D纹理,其大小(以texels为单位)为4。这意味着我们有4个texel,它们的索引分别为0, 1, 2, 3。现在,如果我们有一个规范化的纹理坐标U,其值为0.5,那么我们如何找到对应的纹理地址呢?
-
根据纹理地址模式减小规范化纹理坐标的范围:这一步通常涉及到将规范化的纹理坐标调整到适合纹理寻址模式的范围。例如,如果我们的寻址模式是CLAMP(将纹理坐标限制在[0, 1]范围内),那么我们的规范化纹理坐标U=0.5不需要调整。如果我们的寻址模式是WRAP(在超出[0, 1]范围时将纹理坐标“包装”回来),那么我们的规范化纹理坐标U=0.5同样不需要调整。
-
执行点采样或线性采样寻址:这一步涉及到将规范化的纹理坐标缩放到纹理的大小,然后将结果捕获为一个固定点数。在我们的例子中,我们将U=0.5乘以纹理的大小4,得到2。然后,我们将这个结果捕获为一个固定点数。如果我们正在进行点采样,那么我们将结果四舍五入到最近的整数,得到2。如果我们正在进行线性采样,那么我们将结果保留为一个小数,得到2.0。
-
应用纹理地址模式:最后,我们将纹理地址模式应用到我们的结果上。在我们的例子中,无论我们的寻址模式是CLAMP还是WRAP,我们的结果都是2,因此我们不需要进行任何额外的调整。
所以,通过这个过程,我们将规范化的纹理坐标U=0.5转换为了纹理地址2。这意味着,如果我们在这个纹理上进行采样,我们将会得到索引为2的texel的值。
7.18.6 Reducing Texture Coordinate Range
7.18.6 缩小纹理坐标范围****
To limit the number of bits needed to store the texture coordinate in fixed point after conversion from floating point, the range of the normalized texture coordinate is reduced to be within [-10,10], depending on the Address mode.This removes the magnitude of texture tiling from the texture coordinate, while not affecting the behavior of texture address wrap modes. The same address mode handling can be applied to the range reduced texture coordinate as the original, producing the same result. The benefit is that the magnitude of texture tiling is not stored in the coordinate at the same time that texture size scaling is performed on the coordinate.This enables far larger texture coordinate range to be handled cleanly than would otherwise be possible without reduction.
为了限制从浮点转换后将纹理坐标存储在定点所需的位数,归一化纹理坐标的范围将缩小到 [-10,10] 以内,具体取决于地址模式。这将从纹理坐标中移除纹理平铺的大小,同时不影响纹理地址wrap模式的行为。相同的地址模式处理可以应用于与原始的范围缩小的纹理坐标,产生相同的结果。好处在于,纹理平铺的大小不会存储在坐标中,同时纹理大小缩放是在坐标上执行的。这使得更大的纹理坐标范围能够被干净地处理,而不是在没有减少的情况下。
Note that the range reductions applied here in some cases leave a bit of extra padding (up to [-10,10] mentioned).This padding allows for the fact that after scaling by texture size, the selection of texels for point or linear sample kernels involves picking texel(s) to the left and/or right of the sample location, so coordinates that are not near the boundaries of the addresing mode must not appear as if they are on the boundary.e.g. Consider Linear sampling a coordinate that straddles a border when in BORDER mode: this needs to pick up the Border Color for 1/2 of the samples and the interior edge of the texture for the other 1/2. However range reduction cannot just clamp to [0..1) for BORDER mode, because it would make coordinates that fall completely into BORDER territory incorrectly behave as if they straddle the border (picking up some contribution of Border Color and interior).Range reduction has to also allow for immediate texel offsets permitted in shader code Range reduction does not change expected texture sampling behavior; it just helps keep the sequence of floating point operations on texture coordinates within manageable range.
请注意,在某些情况下,此处应用的范围缩小会留下一些额外的填充(最多提到 [-10,10])。这种填充允许在纹理尺寸缩放后,为点采样或线性采样内核选择 texel 时,选择位于采样位置左侧和/或右侧的 texel。因此,不靠近 addressing 模式边界的坐标不能表现得像它们在边界上一样。例如,考虑在BORDER模式下对跨越边界的坐标进行线性采样:这需要为一半的样本获取边界颜色,为另一半获取纹理的内部边缘。然而,范围缩减不能仅仅将BORDER模式下的值限制在[0…1)内,因为这会使完全落在BORDER区域内的坐标错误地表现为它们跨越了边界(获取了一些边界颜色和内部的贡献)。范围缩小还必须允许着色器代码中允许的即时纹素偏移:范围缩小不会改变预期的纹理采样行为;它只是有助于将纹理坐标上的浮点运算序列保持在可管理的范围内。
The following logic describes how normalized texture coordinate range reduction is performed. (This is different form final Texture Address Processing(7.18.9), which happens a couple of steps later, on scaled coordinates that identify texels.)
以下逻辑描述了如何执行归一化纹理坐标范围缩小。(这与最终的纹理地址处理(7.18.9)不同,它发生在几个步骤之后,在标识纹素的缩放坐标上。)
| Given:float signedFrac(float f) returns (f - round_z(f)) // round_z : "round towards zero"float frac(float f) returns (f - round_ni(f)) // round_ni : "round towards negative infinity" We have:float ReduceRange(float U, D3D11_TEXTURE_ADDRESS_MODE AddressMode){ switch (AddressMode) { case D3D11_TEXTURE_ADDRESS_WRAP: // The reduced range is [0, 1) return frac(U); //取小数部分 case D3D11_TEXTURE_ADDRESS_MIRROR: // The reduced range is (-2, 2) return signedFrac(U/2) * 2; //取偶数与现在的差值 case D3D11_TEXTURE_ADDRESS_MIRRORONCE: case D3D11_TEXTURE_ADDRESS_CLAMP: case D3D11_TEXTURE_ADDRESS_BORDER: // The reduced range is [-10, 10]. // Each of these modes might use different tightnesses of reduced range, // but since there really is no benefit in that, a one-size-fits-all // approach is taken here. // Note that the range leaves room for immediate texel-space offsets // supported by sample instructions, [-8...7], // preventing these offsets from causing texcoords that clearly should // be out of range (i.e. in border/clamp region) from falling within // range after range reduction. The point is that range reduction does // not have an affect on the texels that are supposed to be chosen. if(U <= -10) return -10; else if(U >= 10) return 10; else return U; } return 0;} |
|---|
Note that the amount of padding supported here for mirroronce/clamp/border are only feasible for use with point or linear filtering of a texture (a larger kernel becomes more likely to expose the reduced range boundary), including with immediate texel offsets from the shader.Furthermore, complex filters which use point or linear filter taps as building blocks (key example being Anisotropic Texture Filtering) are perfectly compatible with the specified range reduction.The reason is that such filters choose their "taps" by perturbing normalized texture coordinates (e.g.walking the line of anisotropy in Anisotropic Texture Filtering), and thus each pertubed "tap" individually goes through the range reduction described here before application of the usual Point/Linear Sample Addressing logic and Texture Address Processing described below.
请注意,这里支持的mirroronce/clamp/border的填充量只适用于对纹理进行点或线性过滤(更大的内核更有可能暴露出减小的范围边界),包括来自着色器的立即纹素偏移。此外,使用点采样或线性采样作为构建块的复杂过滤器(其中关键示例是各向异性纹理过滤)与指定的范围缩减完全兼容。原因是这些过滤器通过干扰归一化的纹理坐标来选择它们的“采样点(taps)”(例如,在各向异性纹理过滤中沿着各向异性的线进行),因此,每个被干扰的"tap"在应用通常的点/线性采样寻址逻辑和下面描述的纹理地址处理之前,都会单独经过这里描述的范围减小。
7.18.7 Point Sample Addressing
7.18.7 点 采样 寻址****
Setting aside how sampler state is configured and how mipmap LOD is chosen, consider simply the task of point sampling an Element from a particular miplevel of a Texture1D, given a scalar floating point texture coordinate in normalized space. In the Texture Coordinate Interpretation(3.3.3) section, there is a diagram illustrating generally how a 1D texture coordinates maps to a texel (not accounting for wrapping).Note from the "Texture Coordinate System" diagram shown that texel corners have integral coordinates in texel-space, and so texel centers are at half-units away from the corners. Point sampling selects the "nearest" texel based on the proximity of texel centers to the texture coordinate (keeping in mind that texel centers are at half-units):
不考虑采样器状态如何配置以及如何选择mipmap LOD,只考虑从Texture1D的特定miplevel中点采样一个元素的任务,给定一个在归一化空间中的标量浮点纹理坐标。在纹理坐标解释(3.3.3)部分,有一个图示说明了1D纹理坐标如何映射到纹素(不考虑环绕)。从显示的"纹理坐标系统"图示中注意到,纹素角在纹素空间中具有整数坐标,因此纹素中心距离角点有半个单位。点采样根据纹素中心到纹理坐标的接近度选择"最近"的纹素(请记住,纹素中心在半个单位处):
1. Given a 1D texture coordinate in normalized space U, assumed to be any float32 value.
1. 给定在归一化空间中的一维纹理坐标 U,假设为任何 float32 值。 //也就是说,它的范围在[0, 1]之间。
2. U is scaled by the Texture1D size. Call this scaledU
2. U 按 Texture1D 大小缩放。将此名称称为 scaledU. //得到了一个在[0, numTexels]范围内的值,其中numTexels是纹理的大小
3. scaledU is converted to at least 16.8 Fixed Point(3.2.4.1). Call this fxpScaledU.
3. scaledU 转换为至少 16.8 的定点 (3.2.4.1) 。将此称为 fxpScaledU。
4. The integer part of fxpScaledU is the chosen texel. Call this t. Note that the conversion to Fixed Point(3.2.4.1) basically accomplished: t = floor(scaledU).
4. fxpScaledU 的整数部分是所选的纹素。称之为 t。请注意,到定点 (3.2.4.1) 的转换基本完成:t = floor(scaledU)。
5. If t is outside [0...numTexels-1] range, D3D11_SAMPLER_STATE's AddressU mode is applied(7.18.9).
5. 如果 t 超出 [0...numTexels-1] 范围,则应用 (7.18.9) D3D11_SAMPLER_STATE 的 AddressU 模式。
For Texture2D and Texture3D Resources, the same rules apply independently on the other dimensions.
对于 Texture2D 和 Texture3D 资源,相同的规则独立应用于其他维度。
For TextureCube Resources, the following occurs:
对于 TextureCube 资源,将发生以下情况://对于TextureCube资源的点采样寻址的处理过程
**1.**Choose the largest magnitude component of the input vector. Call this magnitude of this value AxisMajor. In the case of a tie, the following precedence should occur: Z, Y, X.
1. 选择输入向量的最大的分量。将此值的大小称为 AxisMajor。如果分量都相等,应按照以下优先级进行选择:Z、Y、X。
2. Select and mirror the minor axes as defined by the TextureCube(5.3.8) coordinate space. Call this new 2d coordinate Position.
2. 根据TextureCube (5.3.8) 坐标空间定义,选择并镜像小轴。将此新 2d 坐标称为 Position。
3. Project the coordinate onto the cube by dividing the components Position by AxisMajor.
3. 通过将分量 Position 除以 AxisMajor,将坐标投影到立方体上。
4. Transform to 2d Texture space as follows: Position = Position * 0.5f + 0.5f;
4. 转换为 2d 纹理空间,如下所示: Position = Position * 0.5f + 0.5f;
5. Convert the coordinate to fixed point as for a Texture2D.
5. 将坐标转换为 Texture2D 的定点。
假设我们有一个输入向量 (0.1, 0.2, 0.3),我们可以按照上述步骤进行处理:
1.选择输入向量的最大幅度分量。在这个例子中,Z 分量的值最大,所以 AxisMajor = 0.3。
2.选择并镜像次要轴。在这个例子中,次要轴是 X 和 Y,所以 Position = (0.1, 0.2)。
3.将坐标投影到立方体上。这是通过将 Position 的分量除以 AxisMajor 来完成的,所以新的 Position = (0.1/0.3, 0.2/0.3) = (0.333, 0.666)。
4.转换到 2d 纹理空间:Position = Position * 0.5 + 0.5 = (0.333 * 0.5 + 0.5, 0.666 * 0.5 + 0.5) = (0.666, 0.833)。
5.将坐标转换为 Texture2D 的定点。这个步骤取决于你的纹理坐标和纹理大小,所以我无法给出具体的数值。
7.18.8 Linear Sample Addressing
7.18.8 线性样本寻址****
Similar to the previous section, set aside how sampler state is configured and how mipmap LOD is chosen for now, and consider simply the task of linear sampling an Element from a particular miplevel of a Texture1D, given a scalar floating point texture coordinate in normalized space.Linear sampling in 1D selects the nearest two texels to the sample location and weights the texels based on the proximity of the sample location to them.
与前一节类似,暂时不考虑采样器状态如何配置以及如何选择mipmap LOD,只考虑从Texture1D的特定miplevel中线性采样一个元素的任务,给定一个在归一化空间中的标量浮点纹理坐标。在线性采样中,1D 纹理会选择最接近采样位置的两个 texel,并根据采样位置与它们的接近程度对这些 texel 进行加权。
1. Given a 1D texture coordinate in normalized space U, assumed to be any float32 value.
1. 给定归一化空间 U 中的一维纹理坐标,假设为任何 float32 值。
2. U is scaled by the Texture1D size, and 0.5f is subtracted. Call this scaledU.
2. U 按 Texture1D 大小缩放,并减去 0.5f。将此称为 scaledU。
3. scaledU is converted to at least 16.8 Fixed Point(3.2.4.1). Call this fxpScaledU.
3. scaledU 转换为至少 16.8 的定点 (3.2.4.1) 。将此称为 fxpScaledU。
4. The integer part of fxpScaledU is the chosen left texel. Call this tFloorU. Note that the conversion to Fixed Point(3.2.4.1) basically accomplished: tFloorU = floor(scaledU).
4. fxpScaledU 的整数部分是所选的左纹素。将此称为 tFloorU。请注意,到定点 (3.2.4.1) 的转换基本完成:tFloorU = floor(scaledU)。
5. The right texel, tCeilU is simply tFloorU + 1.
5. 右纹素,tCeilU 只是 tFloorU + 1。
6. The weight value wCeilU is assigned the fractional part of fxpScaledU, converted to float(3.2.4.2) (although using less than full float32 precision for computing and processing wCeilU and wFloorU is permitted).
6. 权重值 wCeilU 被分配为 fxpScaledU 的小数部分,转换为浮点数 (3.2.4.2) (尽管允许使用小于全 float32 精度来计算和处理 wCeilU 和 wFloorU)。
7. The weight value wFloorU is 1.0f - wCeilU.
7. 权重值 wFloorU 为 1.0f - wCeilU。
8. If tFloorU or tCeilU are out of range of the texture, D3D11_SAMPLER_STATE's AddressU mode is applied(7.18.9) to each individually.
8. 如果 tFloorU 或 tCeilU 超出纹理范围,则D3D11_SAMPLER_STATE的 AddressU 模式将单独应用于 (7.18.9) 每个纹理。
9. Since more than one texel is chosen, the single sample result is computed as:
9. 由于选择了多个纹素,因此单个样本结果的计算公式为:
texelFetch(tFloorU) * wFloorU + texelFetch( tCeilU) * wCeilU
The procedure described above applies to linear sampling of a given miplevel of a Texture2D as well:
上述过程也适用于 Texture2D 的给定 miplevel 的线性采样:
1. Peform the texel selection to both U and V directions independently, producing 2 U texel locations and 2 V texel locations. Combined, these select 4 texels: (tFloorU,tFloorV), (tFloorU,tCeilV), (tCeilU,tFloorV), (tCeilU,tCeilV).
1. 将纹素选择独立地固定到 U 和 V 方向,产生 2 个 U 纹素位置和 2 个 V 纹素位置。组合起来,这些选择 4 个纹素:(tFloorU,tFloorV)、(tFloorU,tCeilV)、(tCeilU,tFloorV)、(tCeilU,tCeilV)。
2. There are also 4 weight values produced: wFloorU, wCeilU, wFloorV, wCeilV.
2. 还产生了 4 个重量值:wFloorU、wCeilU、wFloorV、wCeilV。
3. The linear sample result is:
3. 线性样本结果为:
texelFetch(tFloorU,tFloorV) * wFloorU * wFloorV +
texelFetch(tFloorU, tCeilV) * wFloorU * wCeilV +
texelFetch( tCeilU,tFloorV) * wCeilU * wFloorV +
texelFetch( tCeilU, tCeilV) * wCeilU * wCeilV
Performing linear sampling of a miplevel of a Texture3D Resource extends the concepts described above to fetching of 8 texels.
对 Texture3D 资源的 miplevel 执行线性采样将上述概念扩展到获取 8 个纹素。
In the case of a TextureCube, see the section regarding TextureCube Edge and Corner Handling(7.18.12)
对于 TextureCube,请参阅有关 TextureCube 边缘和角落处理 (7.18.12) 的部分
7.18.9 Texture Address Processing
7.18.9 纹理地址处理****
The sample* instructions provide texture coordinates in normalized floating point form, such that values in [0..1] range span a given dimension of a texture, and values outside this range fall off the borders of the texture.Later in the filtering process, when individual texels are fetched, if the address is outside the extents of the texture, either the address gets mapped back into range by the texture address mode for each component, or the border-color is used.The texture address mode is defined by the AddressU, AddressV, and AddressW members of D3D11_SAMPLER_STATE.
sample*指令以归一化的浮点形式提供纹理坐标,使得[0…1]范围内的值跨越纹理的给定维度,而超出此范围的值则落在纹理的边界之外。在过滤过程的后期,当获取单个纹素时,如果地址超出纹理范围,则每个组件的纹理地址模式会将地址映射回范围,或者使用边框颜色。纹理地址模式由 D3D11_SAMPLER_STATE 的 AddressU、AddressV 和 AddressW 成员定义。
Consider the moment in the process of sampling of a Texture1D just after picking a particular integer address scaledU to fetch a texel from (details on choosing sample locations described elsewhere for various filter modes).Suppose the texel address scaledU falls off the Texture1D, meaning either (scaledU < 0), or (scaledU > numTexelsU - 1), where numTexelsU is the count of texels in the U dimension of the Texture1D. The following pseudocode describes how the setting on D3D11_SAMPLER_STATE member AddressU gets applied on scaledU:
考虑在对Texture1D进行采样的过程中,在选择特定的整数地址scaledU以从中获取texel的那一刻(关于如何选择各种滤波模式下的采样位置的详细信息在其他地方有描述)。假设texel地址scaledU超出了Texture1D的范围,意味着(scaledU < 0)或者(scaledU > numTexelsU - 1),其中numTexelsU是Texture1D的U维度中的texel数量。以下伪代码描述了如何在scaledU上应用D3D11_SAMPLER_STATE成员AddressU的设置:
| if ((scaledU < 0) || (scaledU > numTexelsU-1)){ switch (AddressU) { case D3D11_TEXADDRESS_WRAP: scaledU = scaledU % numTexelsU; if(scaledU < 0) scaledU += numTexelsU; break; case D3D11_TEXADDRESS_MIRROR: { if(scaledU < 0) scaledU = -scaledU - 1; bool Flip = (scaledU/numTexelsU) & 1; scaledU %= numTexelsU; if( Flip ) // Odd tile scaledU = numTexelsU - scaledU - 1; break; } case D3D11_TEXADDRESS_CLAMP: scaledU = max( 0, min( scaledU, numTexelsU - 1 ) ); break; case D3D11_TEXADDRESS_MIRRORONCE: if(scaledU < 0) scaledU = -scaledU - 1; scaledU = max( 0, min( scaledU, numTexelsU - 1 ) ); break; case D3D11_TEXADDRESS_BORDER: // Special case: Instead of fetching from the texture, // use the Border Color(7.18.9.1). bUseBorderColor = true; break; default: scaledU = 0; }} | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
For Texture2D and Texture3D, all of the above modes apply to the V and W dimensions independently, based on AddressV and AddressW. If any single dimension selects Border Color, then the Border Color(7.18.9.1) is applied.
对于 Texture2D 和 Texture3D,上述所有模式都基于 AddressV 和 AddressW 分别应用于 V 和 W 维度。如果任何单个尺寸选取了“边框颜色”(Border Color),则应用“边框颜色”(Border Color (7.18.9.1) )。
7.18.9.1 Border Color
7.18.9.1 边框颜色****
Border Color values are defined in the DDI via 4 floating point values (RGBA), in linear space. The Border Color used in filtering is snapped to the precision the hardware performs filtering at for the format.
边框颜色值在 DDI 中通过线性空间中的 4 个浮点值 (RGBA) 定义。在过滤中使用的边界颜色会根据硬件对格式执行过滤的精度进行调整。
Note that the only components of the BorderColor used by filtering hardware are the ones present in the resource format description.
请注意,过滤硬件使用的 BorderColor 的唯一组件是资源格式描述中存在的组件。
For example, suppose the resource format is DXGI_FORMAT_R8_SNORM, and BorderColor is needed during a sample operation. In this case only the RED component of BorderColor is used, along with the appropriate format-specific defaults for the other components.The BorderColor (the red part in this case) is taken as floating-point data and clamped into the range of the format before filtering.In this case, the red part of the BorderColor is clamped to [-1.0f,1.0f] range before being used by the filtering hardware. From this point (entering the filtering hardware) onward, the fact that BorderColor is being used has no more behavioral effect.
例如,假设资源格式为 DXGI_FORMAT_R8_SNORM,并且在采样操作期间需要 BorderColor。在这种情况下,仅使用 BorderColor 的 RED 组件,以及其他组件的适当的特定于格式的默认值。将 BorderColor(在本例中为红色部分)作为浮点数据,并在过滤之前将其限制在格式范围内。在这种情况下,在被过滤硬件使用之前,BorderColor的红色部分被限制在[-1.0f,1.0f]范围内。从这一点(进入过滤硬件)开始,使用BorderColor的事实没有更多行为上的影响。
7.18.10 Mipmap Selection
7.18.10 Mipmap选择****
什么是Mipmap?
*.Mipmap是纹理的一组逐渐变小的版本,每个级别的尺寸是前一个级别的一半。
*.最高分辨率(原始)纹理称为基本级别(级别0),后续级别通过降采样生成。
*.Mipmap以图像链的形式存储在内存中,每个级别的尺寸都是前一个级别的一半(宽度和高度)。
*.Mipmap的目的是在不同距离和视角下提供更好的纹理质量,以减少纹理失真和锯齿。
为什么使用Mipmap?
*.提高性能:在远处或小尺寸上使用较低级别的mipmap,避免了对高分辨率纹理的不必要采样。
*.减少锯齿:mipmap可以减少纹理在远处或倾斜视角下的锯齿伪影。
*.避免过滤器伪影:在纹理缩小时,使用更接近原始像素的颜色值,避免了过滤器伪影。
如何选择Mipmap级别?
*.自动选择:大多数图形API和渲染器会自动选择适当的mipmap级别,以匹配纹理在屏幕上的大小和距离。
*.手动选择:有时您可以手动选择mipmap级别,例如在远处或倾斜视角下使用较低级别的mipmap。
下图是OpenGL中的解释:
Suppose the task at hand is to choose a mipmap level from a Resource, given a floating point LOD value. The choice of mipmap level is based on the particular choice of filter mode in the Sampler State(7.18.3); in which the possible choices are POINT and LINEAR. Anisotropic texture filtering uses LINEAR mipmap selection.
假设手头的任务是从给定浮点LOD值的资源中选择一个mipmap级别。mipmap 级别的选择基于采样器状态 (7.18.3) 中过滤器模式的特定选择;其中可能的选择是 POINT 和 LINEAR。各向异性纹理过滤使用 LINEAR mipmap 选择。
SamplerState samLinear
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};
l If the Sampler defines a Filter for which MIP is set to POINT (otherwise known as 'nearest'), the LOD is first converted to at least 8.8 fixed point (if not already in fixed point form), 0.5 is added, and then the integer part of the LOD is taken as the mipmap level (clamped to available miplevels or any settings for clamping miplevels). This selects the "nearest" miplevel.
l 如果采样器定义了一个过滤器,其中 MIP 被设置为 POINT(也被称为 ‘最近’),那么 LOD 首先被转换为至少 8.8 定点(如果还没有以定点形式存在),加 0.5,然后取 LOD 的整数部分作为 mipmap 级别(限制到可用的 miplevels 或任何用于限制 miplevels 的设置)。这选择了 “最近” 的 miplevel。//D3D11_FILTER_MIN_MAG_MIP_POINT
l If the Sampler defines a Filter for which MIP is set to LINEAR:
l 如果采样器定义了 MIP 设置为 LINEAR 的过滤器://D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
1. The two nearest mipmaps are selected as follows.
1. 选择两个最近的 mipmap,如下所示。
2. First, the LOD is converted to at least 8.8 fixed point (if not already in fixed point form). Call this fxpLOD.
2. 首先,将 LOD 转换为至少 8.8 个定点(如果尚未采用定点形式)。将此称为 fxpLOD。
3. The integer part of the fxpLOD is the first miplevel. Call this mipFloor.
3. fxpLOD 的整数部分是第一个 miplevel。将此称为 mipFloor。
4. The second miplevel, call it mipCeil, is miplFloor+1.
4. 第二个 miplevel,称为 mipCeil,是 miplFloor+1。
5. The selected miplevels are clamped to the range of mipmaps available, plus any other settings for clamping miplevels.
5. 选定的 miplevel 被限制到可用的 mipmap 范围,以及用于限制 miplevels 的任何其他设置。
6. The weight for mipCeil, call it wMipCeil, is the fractional component of fxpLOD, converted to float.
6. mipCeil 的权重,称为 wMipCeil,是 fxpLOD 的小数分量,转换为浮点数。
7. The weight for mipFloor, call it wMipFloor, is 1.0f - wMipCeil.
7. mipFloor(称为 wMipFloor)的权重为 1.0f - wMipCeil。
In the past multiple IHVs have cheated here (weight selection) with tactics such as snapping LOD values loosely "around" a given mipmap level to that level in order to avoid performing fetches from multiple mipmap levels.Such practices were always in violation of spec, and will continue to be violations in D3D11.3.
过去,多个 IHV 在这里作弊(权重选择),其策略包括将 LOD 值松散地“围绕”给定的 mipmap 级别捕捉到该级别,以避免从多个 mipmap 级别执行提取。这种做法始终违反规范,并将继续违反 D3D11.3 中的规范。
8. Finally, the texture filtering operation receives the pair of chosen miplevels and weights.The filter can perform some sampling operation at each miplevel combines them using the weights: sampleAt(mipCeil) * wMipCeil + sampleAt(mipFloor) * wMipFloor, where the particular sample operation performed depends on the filtering mode (and multiple such operations involving LINEAR mipmap selection could be involved in a complicated filtering process, e.g. in anisotropic filtering).
8. 最后,纹理过滤操作接收所选的 miplevel 和权重对。过滤器可以在每个 miplevel 执行一些采样操作,使用权重将它们组合在一起:sampleAt(mipCeil)* wMipCeil + sampleAt(mipFloor)* wMipFloor,其中执行的特定采样操作取决于过滤模式(复杂的过滤过程可能涉及多个涉及线性 mipmap 选择的此类操作,例如在各向异性滤波中)。
7.18.11 LOD Calculations
7.18.11 LOD计算****
This section describes how LOD is computed as part of sample* instructions involving filtering.
本节介绍如何将 计算LOD,作为涉及过滤的 sample* 指令的一部分。
l The following determines whether LOD will be computed by a sample instruction, either in an isotropic formulation or in anisotropic formulation:
l 以下内容确定是按各向同性公式还是各向异性公式的示例指令计算 LOD:
| bool ComputeAnisotropicLOD = (SamplerState.Filter == D3D11_FILTER_ANISOTROPIC) && IsTexture2D // Includes. 2D array. // Note: Implementations may choose to perform anisotropic texture // filtering for TextureCubes as well, however D3D11.3 does not require(7.18.13) // filtering of TextureCubes to behave any better than tri-linear filtering. bool ComputeIsotropicLOD = !ComputeAnisotropicLOD bool Magnifying = (clampedLOD <= 0) |
|---|
l Given a texture coordinate vector (1D, 2D or 3D), let it be referred to here as:
l 给定纹理坐标向量(1D、2D 或 3D),此处将其称为:
float3 TC.uvw
l If the Shader is a Pixel Shader, compute the partial derivative vectors in the RenderTarget x and y directions for TC.uvw. Let the derivatives be referred to here as:
l 如果着色器是像素着色器,则计算 TC.uvw 的 RenderTarget x 和 y 方向上的导数向量。这里将导数称为:
float3 dX.uvw
float3 dY.uvw
l See the deriv_rtx_coarse(22.5.2) and deriv_rty_coarse(22.5.3) instructions for details on how to compute these quantities.
l 有关如何计算这些数量的详细信息,请参阅deriv_rtx_coarse (22.5.2) 和deriv_rty_coarse (22.5.3) 说明。
l A couple of variants of the sampling instructions allow the Shader to provide derivatives directly or specify LOD directly (and are available in all Shader stages, not just the Pixel Shader). The sample_d(22.4.17) instruction provides derivatives directly, and the sample_l(22.4.18) instruction allows the LOD to be provided directly. When anisotropic filtering, the ratio of anisotropy with sample_l(22.4.18) is 1 (isotropic).
l 采样指令的几个变体允许着色器直接提供导数或直接指定 LOD(并且可用于所有着色器阶段,而不仅仅是像素着色器)。sample_d (22.4.17) 指令直接提供导数,sample_l (22.4.18) 指令允许直接提供LOD。当各向异性过滤时,各向异性与sample_l的比 (22.4.18) 值为1(各向同性)。
l If the current texture is a TextureCube, transform the partial derivative vectors into the space of the primary TextureCube face as follows:
l 如果当前纹理是 TextureCube,则将导数向量转换为主 TextureCube 面的空间,如下所示:
1. Using TC, determine which component is of the largest magnitude, as when calculating the texel location(7.18.7). If any of the components are equivalent, precedence is as follows: Z, Y, X. The absolute value of this will be referred to as AxisMajor.
1. 使用 TC 确定哪个分量的大小最大,就像计算纹素位置 (7.18.7) 时一样。如果所有分量都是相等的,则优先级如下:Z、Y、X。其绝对值将称为 AxisMajor。
2. select and mirror the minor axes of TC as defined by the TextureCube coordinate space to generate TC'.uv
2. 选择并镜像 TextureCube 坐标空间定义的 TC 短轴,以生成 TC'.uv
3. select and mirror the minor axes of the partial derivative vectors as defined by the TextureCube coordinate space, generating 2 new partial derivative vectors dX'.uv & dY'.uv.
3. 选择并镜像由 TextureCube 坐标空间定义的导数向量的短轴,生成 2 个新的导数向量 dX'.uv 和 dY'.uv。
4. Suppose DerivativeMajorX and DerivativeMajorY are the major axis component of the original partial derivative vectors.
4. 假设 DerivativeMajorX 和 DerivativeMajorY 是原始导数向量的主轴分量。
5. Calculate 2 new dX and dY vectors for future calculations as follows:
5. 计算 2 个新的 dX 和 dY 向量以供将来的计算,如下所示:
dX.uv = (AxisMajordX'.uv - TC'.uvDerivativeMajorX)/(AxisMajor*AxisMajor)
dY.uv = (AxisMajordY'.uv - TC'.uvDerivativeMajorY)/(AxisMajor*AxisMajor)
l Scale the derivatives by the texture size at largest mipmap:
l 按最大 mipmap 的纹理大小缩放导数:
| if (IsTextureCube) { // multiplying by 0.5f to adjust for TextureCube coordinate system dX.uvw = 0.5f * dX.uvw * [NumTexelsAlongCubeSide,NumTexelsAlongCubeSide,0]; dY.uvw = 0.5f * dY.uvw * [NumTexelsAlongCubeSide,NumTexelsAlongCubeSide,0]; } else { dX.uvw = dX.uvw * [NumTexelsInUDimension,NumTexelsInVDimension,NumTexelsInWDimension]; dY.uvw = dY.uvw * [NumTexelsInUDimension,NumTexelsInVDimension,NumTexelsInWDimension]; } |
|---|
l Given a pair of partial derivative vectors representing an elliptical transform, it is important to calculate LOD using a proper orthogonal Jacobian matrix, as described by [Heckbert 89].When performing anisotropic filtering, it is also important to use these modified vectors to calculate the proper filtering footprint. D3D11.3 will allow approximations to this effect. The following describes the ideal transformation, given 2 dimensional vectors:
l 给定一对表示椭圆变换的偏导数向量,使用合适的正交雅可比矩阵计算 LOD 是很重要的,如 [Heckbert 89] 所述。在执行各向异性过滤时,使用这些修改的向量来计算适当的过滤占用也很重要。D3D11.3 将允许对此效果进行近似。下面描述了给定二维向量的理想变换:
Implicit ellipse coefficients:
隐式椭圆系数:
A = dX.v ^ 2 + dY.v ^ 2
B = -2 * (dX.u * dX.v + dY.u * dY.v)
C = dX.u ^ 2 + dY.u ^ 2
F = (dX.u * dY.v - dY.u * dX.v) ^ 2
Defining the following variables:
定义以下变量:
p = A - C
q = A + C
t = sqrt(p ^ 2 + B ^ 2)
The new vectors may be then calculated as:
然后,新向量可以计算为:
new_dX.u = sqrt(F * (t+p) / ( t * (q+t)))
new_dX.v = sqrt(F * (t-p) / ( t * (q+t)))sgn(B) // The paper says sgn(Bp), which appears to be incorrect.
new_dY.u = sqrt(F * (t-p) / ( t * (q-t)))*-sgn(B)
new_dY.v = sqrt(F * (t+p) / ( t * (q-t)))
If w is nonzero, as when calculating LOD for a volume map, an orthogonal transformation must be used to calculate a pair of 2 dimensional vectors with the same lengths and inner angle prior to computing the correct Jacobian matrix.The following is the transformation implemented by the reference rasterizer:
如果 w 不为零,例如在计算体积图的 LOD 时,必须使用正交变换来计算一对具有相同长度和内角的二维向量,然后再计算正确的雅可比矩阵。以下是参考光栅器实现的变换:
orthovec = dX x (dX x dY)
dX' = (|dX|, 0, 0)
dY' = (dot(dY,dX) / |dX|, dot(dY,orthovec) / |orthovec|, 0)
The following caveats also apply:
以下注意事项也适用:
1. if either of dX or dY are of zero length, an implementation should skip these transformations.
1. 如果 dX 或 dY 中的任何一个长度为零,则实现应跳过这些转换。
2. if dX and dY are parallel, an implementation should skip these transformations.
2. 如果 dX 和 dY 是平行的,则实现应跳过这些转换。
3. if dX and dY are perpendicular, an implementation should skip these transformations.
3. 如果 dX 和 dY 是垂直的,则实现应跳过这些转换。
4. if any component of dX or dY is inf or NaN, an implementation should skip these transformations.
4. 如果 dX 或 dY 的任何组件是 inf 或 NaN,则实现应跳过这些转换。
5. if components of dX and dY are large or small enough to cause NaNs in these calculations, an implementation should skip these transformations.
5. 如果 dX 和 dY 的分量足够大或小到足以在这些计算中产生 NaN,则实现应跳过这些转换。
l if(ComputeIsotropicLOD), the LOD calculation is:
l if(ComputeIsotropicLOD),则 LOD 计算为:
float lengthX = sqrt(dX.udX.u + dX.vdX.v + dX.w*dX.w)
float lengthY = sqrt(dY.udY.u + dY.vdY.v + dY.w*dY.w)
output.LOD = log2(max(lengthX,lengthY))
l if(ComputeAnisotropicLOD), the LOD calculation is:
l if(ComputeAnisotropicLOD),LOD计算为:
| // Compute outputs: // (1) float ratioOfAnisotropy // (2) float anisoLineDirection // (3) float LOD // (For 1D Textures, dX.v and dY.v are 0, so all the // math below can be simplified) float squaredLengthX = dX.udX.u + dX.vdX.v float squaredLengthY = dY.udY.u + dY.vdY.v float determinant = abs(dX.udY.v - dX.vdY.u) bool isMajorX = squaredLengthX > squaredLengthY float squaredLengthMajor = isMajorX ? squaredLengthX : squaredLengthY float lengthMajor = sqrt(squaredLengthMajor) float normMajor = 1.f/lengthMajor output.anisoLineDirection.u = (isMajorX ? dX.u : dY.u) * normMajor output.anisoLineDirection.v = (isMajorX ? dX.v : dY.v) * normMajor output.ratioOfAnisotropy = squaredLengthMajor/determinant // clamp ratio and compute LOD float lengthMinor if ( output.ratioOfAnisotropy > input.maxAniso ) // maxAniso comes from a Sampler state. { // ratio is clamped - LOD is based on ratio (preserves area) output.ratioOfAnisotropy = input.maxAniso lengthMinor = lengthMajor/output.ratioOfAnisotropy } else { // ratio not clamped - LOD is based on area lengthMinor = determinant/lengthMajor } // clamp to top LOD if (lengthMinor < 1.0) { output.ratioOfAnisotropy = MAX( 1.0, output.ratioOfAnisotropy*lengthMinor ) // lengthMinor = 1.0 // This line is no longer recommended for future hardware // // The commented out line above was part of the D3D10 spec until 8/17/2009, // when it was finally noticed that it was undesirable. // // Consider the case when the LOD is negative (lengthMinor less than 1), // but a positive LOD bias will be applied later on due to // sampler / instruction settings. // // With the clamp of lengthMinor above, the log2() below would make a // negative LOD become 0, after which any LOD biasing would apply later. // That means with biasing, LOD values less than the bias amount are // unavailable. This would look blurrier than isotropic filtering, // which is obviously incorrect. The output of this routine must allow // negative LOD values, so that LOD bias (if used) can still result in // hitting the most detailed mip levels. // // Because this issue was only noticed years after the D3D10 spec was originally // authored, many implementations will include a clamp such as commented out // above. WHQL must therefore allow implementations that support either // behavior - clamping or not. It is recommended that future hardware // does not do the clamp to 1.0 (thus allowing negative LOD). // The same applies for D3D11 hardware as well, since even the D3D11 specs // had already been locked down for a long time before this issue was uncovered. } output.LOD = log2(lengthMinor); |
|---|
l Given an LOD specified either from the shader or calculated from derivatives, MipLODBias, srcLODBias (sample_b(22.4.16) only), and MinLOD and MaxLOD clamps are applied to it:
l 给定从着色器指定或从导数计算的 LOD,将对其应用 MipLODBias、srcLODBias( (22.4.16) 仅限sample_b)以及 MinLOD 和 MaxLOD 限制:
biasedLOD = output.LOD + MipLODBias;
biasedLOD = biasedLOD + srcLODBias; // for sample_b only; must be per done pixel
clampedLOD = max(MinLOD,(min(MaxLOD, biasedLOD)));
The ordering of min/max guarantees that if MinLOD > MaxLOD, then MinLOD takes precedence. These min and max operations follow the Floating Point Rules(3.1), so NaN never gets propagated. A sampler state that specifies NaN for MinLOD or MaxLOD is invalid.
最小/最大值的排序保证了如果 MinLOD > MaxLOD,则 MinLOD 优先。这些最小值和最大值运算遵循浮点规则 (3.1) ,因此 NaN 永远不会传播。为 MinLOD 或 MaxLOD 指定 NaN 的采样器状态无效。
Note that the naming for MinLOD and MaxLOD is different/opposing from the D3DSAMP_MAXMIPLEVEL sampler state present in Direct3D9.
请注意,MinLOD 和 MaxLOD 的命名与 Direct3D9 中存在的D3DSAMP_MAXMIPLEVEL采样器状态不同/相反。
The selection of minification vs magnification occurs after LOD clamping.
缩小与放大的选择发生在LOD限制之后。
Prior to feature level 11.0, it was undefined whether magnification selection occurred before or after LOD clamping.
在特征级别11.0之前,放大率选择是发生在LOD限制之前还是之后是未定义的。
Also note the independent Per-Resource Mipmap Clamping(5.8) feature, which is an optional additional clamp on the LOD like MinLOD above but specified at a resource level as opposed to a sample+shader-resource view level.
另请注意独立的 Per-Resource Mipmap Clamping (5.8) 功能,它是 LOD 上的可选附加 Clamp,如上面的 MinLOD,但在资源级别指定,而不是 sample+shader-resource 视图级别。
In some future D3D version, a better definition of magnification should be considered. For one, filtering should take into account the available mipmaps after clamping.Further, perhaps whenever the most detailed available mipmap is read, it should receive magnification filtering, while minification filtering would always be applied to any less detailed mips read in a given filter operation.Thus a given trilinear filter operation could be applying both magnification on one of the mips referenced simultaneously with minification filtering on the other before blending the mips together.This distinction becomes interesting if more compelling magnification filter types are ever introduced, particularly in avoiding discontinuities transitioning between minification and magnification.
在未来的某个 D3D 版本中,应该考虑更好的放大定义。首先,过滤应考虑在限制后可用的 mipmap。此外,也许每当读取最详细的可用 mipmap 时,它都应该接受放大过滤,而缩小过滤将始终应用于给定过滤操作中读取的一些不太详细的 mips。因此,给定的三线性过滤操作可以同时在其中一个引用的 mips 上应用放大和在另一个上应用缩小过滤,然后再将 mips 混合在一起。如果引入了更有吸引力的放大过滤类型,这种区别变得有趣,特别是在避免在缩小和放大之间过渡时的不连续性。
Regarding MipLODBias: The valid range for MipLODBias in the sampler and srcLODBias in the sample_b(22.4.16) instruction are (-16.0f...15.99f). An implementation must support sufficient range for the LOD value before the application-defined MinLOD/MaxLOD/MipLODBias/srcLODBias equation above, such that if the calculated LOD before this equation is outside of the internally supported range and gets clamped (prior to applying application-defined MinLOD/MaxLOD), then the MipLODBias part of the equation (given any valid MipLODBias and srcLODBias value) must not cause the LOD to come back into the range that affects mip selection.
关于 MipLODBias:在采样器中的 MipLODBias 和 sample_b(22.4.16) 指令中的 srcLODBias 的有效范围是 (-16.0f…15.99f)。实现必须在上述应用程序定义的 MinLOD/MaxLOD/MipLODBias/srcLODBias 方程之前,支持足够的LOD 值范围,这样如果在此方程之前计算的 LOD 超出内部支持的范围并被限制(在应用程序定义的 MinLOD/MaxLOD 之前),那么方程的 MipLODBias 部分(给定任何有效的 MipLODBias 和 srcLODBias 值)不应导致 LOD 回到影响 mip 选择的范围。
7.18.12 TextureCube Edge and Corner Handling
7.18.12 纹理立方体边缘和角落处理****
TextureCube filtering near Cube edges, where 2x2 (bilinear) filter taps would fall off a face are required to spill over by one texel row/column to the appropriate adjacent map.
在立方体边缘附近对TextureCube进行过滤时,需要将2x2(双线性)滤波采样点溢出一个纹素行/列到相应的相邻贴图中。
At TextureCube corners, a linear combination of the three relevant samples is required. The ideal (reference) linear combination of the three samples in the corner case is as follows: Imagine flattening out the Cube faces at the corner, yielding 3 texels and a missing one. Apply bilinear weights on this virtual grid of 4 texels, and then divide the weight for the missing texel evenly amongst the 3 other texels. It is alternatively permissible for an implementation to, instead of dividing the weight evenly amongst the 3 other texels, just split the weight of the missing texel across the 2 adjacent texels. However in future versions of D3D, only the reference behavior will be permitted.
在TextureCube的角落,需要三个相关样本的线性组合。
在角落情况下,三个样本的理想(参考)线性组合如下:想象一下,在角落处展平立方体面,产生 3 个纹素和一个缺失的纹素。在这个虚拟的 4纹素网格上应用双线性权重,然后将缺失的纹素的权重均匀地分配给其他3个纹素。
另一种允许的实现方式是,而不是将权重均匀地分配给其他 3个纹素,只是将缺失的纹素的权重分配给 2 个相邻的纹素。
然而,在未来的 D3D 版本中,只有这个参考行为将被允许。
7.18.13 Anisotropic Filtering of TextureCubes
7.18.13 纹理立方体 的各向异性滤波****
Anisotropic texture filtering on a TextureCube does not have specified/required behavior except that it must at least behave no "worse" than tri-linear filtering would.
TextureCube 上的各向异性纹理过滤没有指定/必需的行为,除非它至少必须表现得不比三线性过滤“差”。
7.18.14 Sample Return Value Type Interpretation
7.18.14 采样 返回值类型解释****
The application is given control over the return type of texture load instructions (i.e. reading raw integer values vs. reading normalized float values) by simply choosing an appropriate format to interpret the resource's contents as. See the Formats(19.1) section for detail.
应用程序可以通过简单地选择适当的格式来解释资源的内容,从而控制纹理加载指令的返回类型(即读取原始整数值与读取规范化浮点值)。有关详细信息,请参阅“格式 (19.1) ”部分。
7.18.15 Comparison Filtering
7.18.15 比较过滤****
For details on comparison filtering, see the sample_c(22.4.19) and sample_c_lz(22.4.20) instructions.
有关比较过滤的详细信息,请参阅sample_c (22.4.19) 和sample_c_lz (22.4.20) 说明。
Comparision Filtering is an attempt by D3D11.3 to define basic building-block filtering operation that is useful for Percentage Closer Depth Filtering.
比较过滤是 D3D11.3 定义基本构建块过滤操作的尝试,该操作对Percentage Closer Depth Filtering很有用。
7.18.15.1 Shadow Buffer Exposure on Feature Level 9.x
7.18.15.1 功能级别 9.x 上的阴影缓冲区曝光****
D3D9 never officially supported dedicated hardware support for shadow map scenarios. Namely, D3D9 does not spec the ability to bind a depth buffer as a shader input and to sample from it using comparision filtering (also known as "Percentage Closer Filtering").Even though this never made it into the D3D9 spec, the D3D9 runtime intentionally used loose validation to enabled IHVs to align on a convention for how to make the feature work.
D3D9 从未正式支持对阴影贴图方案的专用硬件支持。也就是说,D3D9 没有指定将深度缓冲区绑定为着色器输入并使用比较过滤(也称为“Percentage Closer Filtering”)从中采样的功能。尽管这从未进入 D3D9 规范,但 D3D9 运行时有意使用松散验证,使 IHV 能够就如何使功能工作的约定保持一致。
In the meantime, the D3D10+ hardware spec added a requirement for supporting binding depth as a texture and for comparison filtering.
同时,D3D10+ 硬件规范增加了支持绑定深度作为纹理和比较过滤的要求。
As more scenarios arise involving the D3D11+ APIs running on Feature Level 9.x it finally makes sense to expose the D3D9 shadow buffer support.It turns out this is possible simply by loosening validation on existing API constructs in the D3D11.1+ API for depth buffers and comparision filtering, mapping to the equivalent on the D3D9 convention IHVs had aligned on where applicable.
随着涉及在功能级别 9.x 上运行的 D3D11+ API 的更多方案出现,最终公开 D3D9 阴影缓冲区支持是有意义的。事实证明,这可以通过放宽对 D3D11.1+ API 中现有 API 构造的验证来实现,用于深度缓冲区和比较筛选,映射到 IHV 在适用的情况下对齐的 D3D9 约定上的等效项。
When Feature Level 9.x is used at the D3D11.1+ API (meaning the D3D9 DDI is used) on a Win8+ driver, regardless of hardware feature level, applications can do the following:
在 Win8+ 驱动程序上的 D3D11.1+ API(意味着使用 D3D9 DDI)使用功能级别 9.x 时,无论硬件功能级别如何,应用程序都可以执行以下操作:
1. Create Texture2D surfaces with the format DXGI_FORMAT_R16_TYPELESS or DXGI_FORMAT_R24G8_TYPELESS and set BindFlags to both D3D11_BIND_SHADER_RESOURCE and D3D11_BIND_DEPTH_STENCIL together.
1. 使用 DXGI_FORMAT_R16_TYPELESS 或 DXGI_FORMAT_R24G8_TYPELESS 格式创建 Texture2D 曲面,并将 BindFlags 设置为同时D3D11_BIND_SHADER_RESOURCE和D3D11_BIND_DEPTH_STENCIL。
2. Create Sampler State objects with a comparison filter chosen and comparison mode lessEqual.
2. 创建采样器状态对象,并选择比较过滤器和比较模式 lessEqual。
3. Use BorderColor addressing if desired on these samplers, even though border color is otherwise not normally allowed on Feature Levels 9.1 and 9.2. This is useful to allow applications to choose what happens when sampling off the bounds of Depth Buffer.A typical choice would be using a depth value (placed in the R component of the border color) that would result in the depth comparison always passing or always failing.
3. 如果需要,在这些采样器上使用 BorderColor 寻址,即使功能级别 9.1 和 9.2 上通常不允许使用边框颜色。这对于允许应用程序选择在深度缓冲区边界之外采样时发生的情况非常有用。典型的选择是使用深度值(放置在边框颜色的 R 分量中),这将导致深度比较始终通过或始终失败。
4. The Mag and Min filter settings in the comparison filter choose between linear or point filtering (using different choices for Mag/Min filter is undefined). Anisotropic filtering is not allowed.The Mip filter choice is meaningless since Feature Level 9.x does not allow mipmapped depth buffers.
4. 比较滤波器中的Mag 和Min 过滤器设置在线性滤波或点滤波之间进行选择(未定义对磁力/最小滤波器使用不同的选择)。不允许各向异性滤波。Mip 筛选器的选择毫无意义,因为功能级别 9.x 不允许 mipmapped 深度缓冲区。
5. Create a DepthStencil View of the typeless Texture2D resource with format DXGI_FORMAT_D16_UNORM / DXGI_FORMAT_D24_UNORM_S8_UINT and render depth to it.
5. 创建格式为 DXGI_FORMAT_D16_UNORM / DXGI_FORMAT_D24_UNORM_S8_UINT 的无类型 Texture2D 资源的 DepthStencil 视图,并向其渲染深度。
6. Create a Shader Resource View of the typeless Texture2D resource with format DXGI_FORMAT_R16_UNORM / DXGI_FORMAT_R24_UNORM_X8_TYPELESS and bind it with the comparison sampler described above.
6. 创建格式为 DXGI_FORMAT_R16_UNORM/DXGI_FORMAT_R24_UNORM_X8_TYPELESS的无类型 Texture2D 资源的着色器资源视图,并将其与上述比较采样器绑定。
7. Use the SampleCmp/SampleCmpLevelZero texture2D methods in ps_4_0_level_9_* shaders to sample from the Shader Resource View above.
7. 使用 ps_4_0_level_9_* 着色器中的 SampleCmp/SampleCmpLevelZero texture2D 方法从上面的着色器资源视图中采样。
7.1 Note these methods already exist for ps_4_0+ (sample_c/sample_c_lz in the bytecode). They are simply now also available for ps_4_0_level_9_*, where the D3D9 texld operation is repurposed for comparision filtering, described further below.
7.1请注意,这些方法已存在于 ps_4_0+ (字节码中的 sample_c/sample_c_lz) 中。它们现在也可用于 ps_4_0_level_9_*,其中 D3D9 texld 操作被重新用于比较过滤,如下所述。
7.2 sample_c/sample_c_lz (the latter forcing mip level 0) behave identically since depth textures cannot be mipmapped on Feature Level 9.x.
7.2 sample_c/sample_c_lz(后者强制 mip 级别为 0)的行为相同,因为深度纹理无法在功能级别 9.x 上mipmapped 。
8. Passing these shaders to CreatePixelShader (or using any of these features) on an old runtime will fail.
8. 在旧的运行时上将这些着色器传递给 CreatePixelShader(或使用其中任何功能)将失败。
**9.**If any state is configured incorrectly by the application, either the runtime will fail state creation, else if the mismatch is only visible at Draw-time the Draw call gets dropped by the runtime. Basically the runtime drops the Draw call if a texture is bound and it is depth but the sampler is not a comparision sampler or the texture is not depth and the sampler is comparison. This validation does not check whether the current shader even uses the texture at all, so in that sense it is stricter than necessary (for simplicity of implementation).
9. 如果应用程序未正确配置一些状态,则运行时将无法创建状态,否则,如果不匹配只在绘制时可见,则运行时会放弃绘制调用。基本上,如果纹理已绑定并且它是深度但采样器不是比较采样器,或者纹理不是深度并且采样器是比较采样器,则运行时会放弃 Draw 调用。此验证不会检查当前着色器是否使用了纹理,因此从这个意义上说,它比必要的更严格(为了实现的简单性)。
The overbearing validation described above (dropping Draw calls when state is invalid) helps ensure that an application that can get shadows working at Feature Level 9.x will behave the same if the Feature Level is bumped up to 10+ with no code change required.
上面描述的强制验证(当状态无效时删除 Draw 调用)有助于确保在 Feature Level 9.x 上可以获得阴影效果的应用程序在 Feature Level 提升到 10+ 时仍然可以获得相同的效果,而无需进行代码更改。
The reason this feature is limited to Win8+ drivers (regardless of hardware feature level) is to avoid having to test on any old D3D9 hardware that is unlikely to be driven by the D3D11.1 APIs in the first place.
此功能仅限于 Win8+ 驱动程序(无论硬件功能级别如何)的原因是为了避免在任何旧的 D3D9 硬件上进行测试,这些硬件首先不太可能由 D3D11.1 API 驱动。
7.18.15.1.1 Mapping the Shadow Buffer Scenario to the D3D9 DDI
7.18.15.1.1 将 阴影 缓冲区方案映射到 D3D9 DDI****
The D3D11.1 runtime maps this shadow scenario to the D3D9 DDI (regardless of hardware feature level) as follows.
D3D11.1 运行时将此阴影方案映射到 D3D9 DDI(无论硬件功能级别如何),如下所示。
1. Surfaces can be created with both depth and texture flags as long as the format is either D3DDDIFMT_S824 or D3DDIFMT_D16.
1. 只要格式为D3DDDIFMT_S824或D3DDIFMT_D16,就可以使用深度和纹理标志创建表面。
2. If a depth texture is bound as a texure input to the Pixel Shader, comparison filtering with less-equal comparison is always assumed. (There is no DDI in D3D9 for explicitly turning on or off comparison filtering.)
2. 如果深度纹理被绑定为像素着色器的纹理输入,总是假定比较过滤器是小于等于比较的。(在D3D9中没有DDI可以显式地打开或关闭比较过滤器。)
3. The Mag and Min filter settings in the comparison filter choose between linear or point filtering (using different choices for Mag/Min filter is undefined). Anisotropic filtering is not allowed.The Mip filter choice is meaningless since Feature Level 9.x does not allow mipmapped depth buffers.
3. 比较过滤器中的 Mag 和 Min 过滤器设置在线性过滤和点过滤之间进行选择(对于 Mag/Min 过滤器使用不同的选择是未定义的)。不允许各向异性过滤。Mip 过滤器的选择毫无意义,因为功能级别 9.x 不允许 mipmapped 深度缓冲区。
4. BorderColor addressing is allowed to be requested by the application when a depth buffer is set as a texture. For all other cases border addressing is not allowed on Feature Level 9.1 and 9.2.
4. 当深度缓冲区设置为纹理时,应用程序允许请求 BorderColor 寻址。对于所有其他情况,功能级别 9.1 和 9.2 上不允许边界寻址。
**5.**In the Pixel Shader, the 3rd component of the texture cooordinate input to the texld instruction specifies the reference z value to use during comparision filtering. For a description of comparision filtering, refer to D3D10+ sample_c shader instruction.The difference for the (repurposed) D3D9 texld instruction is that the z value is packed with the texture coordinate rather than a separate argument.
5. 在像素着色器中,输入到 texld 指令的纹理坐标的第三个组件指定了在比较过滤期间使用的参考 z 值。有关比较过滤的描述,请参阅 D3D10+ sample_c 着色器指令。(重新调整用途的)D3D9 texld 指令的区别在于,z 值包含纹理坐标,而不是单独的参数。
This feature was added too late to enforce via hardware conformance kit testing. However all hardware vendors at the time of shipping agreed to support it, and tests are being authored to assist with basic verification (even if not enforced for now).
添加此功能为时已晚,无法通过硬件一致性工具包测试强制执行。但是,所有硬件供应商在发货时都同意支持它,并且正在编写测试以协助基本验证(即使目前尚未强制执行)。
7.18.15.1.2 Checking for Shadow Support on Feature Level 9.x
7.18.15.1.2 检查功能级别 9.x 上的阴影支持****
The D3D11 CheckFeatureSupport() API has a new capability that can be checked: D3D11_FEATURE_D3D9_SHADOW_SUPPORT. This is set to true if the driver is Win8+ (no need to ask the driver anything else).
D3D11 CheckFeatureSupport() API 有一个新的可以检查的功能:D3D11_FEATURE_D3D9_SHADOW_SUPPORT。如果驱动程序是 Win8+,则此项设置为 true(无需向驱动程序询问任何其他问题)。
typedef enum D3D11_FEATURE {
D3D11_FEATURE_THREADING = 0,
...
D3D11_FEATURE_D3D9_SHADOW_SUPPORT,
...
D3D11_FEATURE_DISPLAYABLE
} ;
HRESULT CheckFeatureSupport(
D3D12_FEATURE Feature,
[in, out] void *pFeatureSupportData,
UINT FeatureSupportDataSize
);
On the other hand if the D3D11 CheckFeatureSupport() / CheckFormatSupport() APIs are used to query format support on the individual DXGI_FORMAT_* names described here, the runtime will NOT report support for any capabilities specific to the shadow buffer scenario.For example support for using DXGI_FORMAT_R16_UNORM as a texture is not reported on Feature Level 9.1/9.2 (though it is supported on 9.3, independent of the shadow scenario).
另一方面,如果 D3D11 CheckFeatureSupport() / CheckFormatSupport() API 用于查询此处所述的各个 DXGI_FORMAT_* 名称的格式支持,则运行时将不会报告于阴影缓冲区方案的任何功能的支持。例如,功能级别 9.1/9.2 上未报告对使用DXGI_FORMAT_R16_UNORM作为纹理的支持(尽管 9.3 支持它,但与阴影方案无关)。
HRESULT CheckFormatSupport(
[in] DXGI_FORMAT Format,
[out] UINT *pFormatSupport
);
Not reporting shadow support on format caps queries was a simplification. It avoids conflicts where this depth scenario allows operations with format names that are not allowed in non-shadow cases, particularly for DXGI_FORMAT_R16_UNORM. It was not worth disambiguating the format caps reporting for this unique case. The bottom line is all an application needs to do is check the D3D11_FEATURE_D3D9_SHADOW_SUPPORT cap described above to know if the entire scenario will work.
在格式能力查询中不报告阴影支持是一种简化。它避免了这种深度场景允许使用在非阴影情况下不允许的格式名称的操作,特别是对于 DXGI_FORMAT_R16_UNORM。为这个独特的情况消除格式能力报告的歧义是不值得的。最重要的是,应用程序需要做的所有事情就是检查上述的 D3D11_FEATURE_D3D9_SHADOW_SUPPORT 能力,以了解整个场景是否会工作。
7.18.16 Texture Sampling Precision
7.18.16 纹理采样精度****
7.18.16.1 Texture Addressing and LOD Precision
7.18.16.1 纹理寻址和LOD精度****
During Texture Sampling(7.18), the amount of range required for selecting texels (after scaling normalized texture coordinates by texture size) is at least 216. This range is centered around 0.
在纹理采样 (7.18) 期间,选择纹素所需的范围量(按纹理大小缩放归一化纹理坐标后)至少为 216。此范围以 0 为中心。
The amount of subtexel precision required (after scaling texture coordinates by texture size) is at least 8-bits of fractional precision (28subdivisions).
所需的子纹素精度量(按纹理大小缩放纹理坐标后)至少为 8 位小数精度(28 个 细分)。
In mipmap selection, after conversion from float, at least 8-bits must represent the integer component of the LOD, and at least 8-bits must represent the fractional component of an LOD (28subdivisions).
在 mipmap 选择中,从浮点数转换后,至少有 8 位必须表示 LOD 的整数分量,并且至少 8 位必须表示 LOD 的小数分量(28个细分)。
See the discussion in the Fixed Point Integers(3.2.4) section on how fixed point numbers should be defined and how it relates to texture coordinate precision.
请参阅“定点整数” (3.2.4) 部分中的讨论,了解应如何定义定点数以及它与纹理坐标精度的关系。
7.18.16.2 Texture Filtering Arithmetic Precision
7.18.16.2 纹理过滤算 法 精度****
All of the texture filtering operations in D3D11.3, when being performed on floating point formats (regardless of format width), are required to follow the D3D11.3 Floating Point Rules(3.1), with one exception: When a filter weight of 0.0 is encountered, NaN's or signed zeros may or may not be propagated from the source texture.
D3D11.3 中的所有纹理过滤操作在浮点格式(无论格式宽度如何)上执行时,都需要遵循 D3D11.3 浮点规则 (3.1) ,但有一个例外:当遇到过滤器权重为 0.0 时,NaN 或有符号零可能会也可能不会从源纹理传播。
Texture filtering operations performed on fixed point formats must be done with at least as much precision as the format.
对定点格式执行的纹理过滤操作必须至少具有与格式相同的精度。
7.18.16.3 General Texture Sampling Invariants
7.18.16.3 常规纹理采样不变量****
Here are some general observations about things that can be expected of texture filtering operations.
以下是关于可以预期的纹理过滤操作的一些一般性观察。
1. Point sampling always yields a single texel, exactly.
2. On a filter that samples from multiple texels, the output must fall between the min and the max values of the texels accessed. Consequently, filtering a constant-color texture always yields that color. The one exception to this is that as stated here(22.4.15), point sampling of a denormalized 32-bit float value, the result may or may not be flushed.
2. 在从多个纹素采样的过滤器上,输出必须介于所访问纹素的最小值和最大值之间。因此,过滤恒定颜色的纹理始终会产生该颜色。唯一的例外是,如本文 (22.4.15) 所述,对非规范化的 32 位浮点值进行点采样,结果可能会刷新,也可能不会刷新。
3. In a bilinear filter operation, colors must increase or decrease monotonically as a function of the U or V filter weights.
3. 在双线性过滤器操作中,颜色作为 U 或 V 过滤器权重的函数,必须单调增加或减少。
7.18.17 Sampling Unbound Data
7.18.17 采样未绑定数据****
Sampling from a slot with no texture bound returns 0 in all components.
从没有纹理绑定的插槽中采样时,所有组件均返回 0。