所有不同的 HLSL 采样器类型有何用途?
我目前正在使用 DX9/SM3 以及有关 HLSL 采样器的 MSDN 文档 似乎非常缺乏解释如何使用不同的采样器类型。更糟糕的是,他们试图在一篇文章中涵盖 DX9 和 DX10,因此他们将所有关键字混在一起:
采样器名称 = SamplerType { 纹理 = <texture_variable>; [state_name = state_value;] ... };
...
采样器类型
<块引用>[in] 采样器类型,为以下类型之一:sampler、sampler1D、sampler2D、sampler3D、samplerCUBE、sampler_state、SamplerState。
Direct3D 9 和 Direct3D 10 之间的差异:
Direct3D 10 支持一种附加采样器类型:SamplerComparisonState。
我感觉与本文相反,SamplerState
仅适用于 DX10。事实上,我看到的所有代码都使用 sampler_state
来表示 SamplerType。 BasicHLSL (DX9) 的一个简单示例:
sampler MeshTextureSampler =
sampler_state
{
Texture = <g_MeshTexture>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
为什么存在所有不同的 _SamplerType_ 以及何时使用 sampler
或 sampler2D
而不是 sampler_state
?无论如何,在获取时您需要明确,例如 tex2D、texCUBE,那么这里发生了什么?
I'm working with DX9/SM3 at the moment, and the MSDN documentation on HLSL samplers seems to be sorely lacking in explaining how to use the different sampler types. What's worse is they try to cover DX9 and DX10 in a single article, so they jumble together all the keywords:
sampler Name = SamplerType { Texture = <texture_variable>; [state_name = state_value;] ... };
...
SamplerType
[in] The sampler type, which is one of the following: sampler, sampler1D, sampler2D, sampler3D, samplerCUBE, sampler_state, SamplerState.
Differences between Direct3D 9 and Direct3D 10:
Direct3D 10 supports one additional sampler type: SamplerComparisonState.
I get the feeling that contrary to this writeup, SamplerState
is DX10 only. Virtually all the code I see uses sampler_state
for SamplerType. A quick example from BasicHLSL (DX9):
sampler MeshTextureSampler =
sampler_state
{
Texture = <g_MeshTexture>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
Why do all the different _SamplerType_s exist and when would you use, say, sampler
or sampler2D
instead of sampler_state
? You need to be explicit when fetching anyhow, e.g. tex2D
, texCUBE
, so what is going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

你说得对。这很奇怪。
DirectX 9 语法的文档似乎是错误的。我绝不是 HLSL 或 DirectX 方面的专家,但我总是只看到 DirectX 9 中的采样器是这样声明的:
我可能遗漏了一些东西,但对我来说,上面的语法比文档中的语法更有意义。您声明具有给定类型的采样器,并指定采样器状态。
更新:显然这是错误的。我已经在官方论坛上启动了一个帖子,到目前为止我已经只是得到确认,这是错误的。我还直接向 DirectX 团队发送了一封邮件。只是为了安全起见。
You're right. That is very odd.
It seems as if the documentation on the DirectX 9 syntax is wrong. I'm by no means an expert on either HLSL or DirectX, but I've always only seen samplers in DirectX 9 being declared like this:
I might be missing something but to me the above syntax makes more sense than the one in the documentation. You declare a sampler with a given type, and specifies the sampler state.
UPDATE: Apparently it IS wrong. I've started a thread on the official forums and so far I've only gotten a confirmation that it is wrong. I've also sent a mail directly to the DirectX team. Just to be on the safe side.