当不在 dx9 兼容模式下时,DX9 风格的特性被禁用了吗?
DX9 style intristics are disabled when not in dx9 compatibility mode?
我目前正在为基本的高斯模糊编写 HLSL
着色器。着色器代码很简单,但我一直收到错误消息:
DX9 style intristics are disabled when not in dx9 compatibility mode. (LN#: 19)
这告诉我代码中的第 19 行是问题所在,我认为这是由于该特定行中的 tex2D
或 Sampler
。
#include "Common.hlsl"
Texture2D Texture0 : register(t0);
SamplerState Sampler : register(s0);
float4 PSMain(PixelShaderInput pixel) : SV_Target {
float2 uv = pixel.TextureUV; // This is TEXCOORD0.
float4 result = 0.0f;
float offsets[21] = { ... };
float weights[21] = { ... };
// Blur horizontally.
for (int x = 0; x < 21; x++)
result += tex2D(Sampler, float2(uv.x + offsets[x], uv.y)) * weights[x];
return result;
}
有关代码的注释和我的问题,请参阅下文。
备注
由于我的代码位于未连接的计算机上,因此我必须将我的代码手动输入到 Whosebug 中。因此:
- 代码中不存在此处出现的任何拼写或大小写错误。
offsets
和 weights
中没有值是故意的。
- 这是因为每个值有 21 个值,我不想全部输入。
offsets
是从 -10
到 10
的每个整数。
weights
范围从 0.01
到 0.25
并返回到 0.01
。
- 由于前面提到的缺失,此处的行数较少。
- 这里错误的行号是
15
.
- 列范围是
13 - 59
,封装了tex2D
和Sampler
。
我的问题
- 我在
tex2D
调用中为 Sampler
使用了错误的数据类型吗?
- 是否在
DirectX 11
中弃用了 tex2D
?
- 我应该改用什么?
- 我在这里做错了什么,因为这是我唯一的错误。
经过广泛搜索后,我发现 ps_4_0
及更高版本不再支持 tex2D
。好吧,4_0
将在旧模式下工作,但它不起作用 5_0
,这正是我正在使用的。
Shader Model : Supported
Shader Model 4 : yes (pixel shader only), but you must use the legacy compile option when compiling.
Shader Model 3 (DirectX HLSL) : yes (pixel shader only)
Shader Model 2 (DirectX HLSL) : yes (pixel shader only)
Shader Model 1 (DirectX HLSL) : yes (pixel shader only)
这已被替换为Texture2D
; documentation 可用。以下是上述文档中的示例:
// Object Declarations
Texture2D g_MeshTexture;
SamplerState MeshTextureSampler
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
float4 Diffuse : COLOR0;
float2 TextureUV : TEXCOORD0;
};
VS_OUTPUT In;
// Shader body calling the intrinsic function
Output.RGBColor = g_MeshTexture.Sample(MeshTextureSampler, In.TextureUV) * In.Diffuse;
替换我的代码中的 tex2D
调用:
result += Texture0.Sample(Sampler, float2(uv.x + offsets[x], uv.y)) * weights[x];
此外,请注意此 post 中的代码用于高斯模糊的水平传递。
我目前正在为基本的高斯模糊编写 HLSL
着色器。着色器代码很简单,但我一直收到错误消息:
DX9 style intristics are disabled when not in dx9 compatibility mode. (LN#: 19)
这告诉我代码中的第 19 行是问题所在,我认为这是由于该特定行中的 tex2D
或 Sampler
。
#include "Common.hlsl"
Texture2D Texture0 : register(t0);
SamplerState Sampler : register(s0);
float4 PSMain(PixelShaderInput pixel) : SV_Target {
float2 uv = pixel.TextureUV; // This is TEXCOORD0.
float4 result = 0.0f;
float offsets[21] = { ... };
float weights[21] = { ... };
// Blur horizontally.
for (int x = 0; x < 21; x++)
result += tex2D(Sampler, float2(uv.x + offsets[x], uv.y)) * weights[x];
return result;
}
有关代码的注释和我的问题,请参阅下文。
备注
由于我的代码位于未连接的计算机上,因此我必须将我的代码手动输入到 Whosebug 中。因此:
- 代码中不存在此处出现的任何拼写或大小写错误。
offsets
和weights
中没有值是故意的。- 这是因为每个值有 21 个值,我不想全部输入。
offsets
是从-10
到10
的每个整数。weights
范围从0.01
到0.25
并返回到0.01
。
- 由于前面提到的缺失,此处的行数较少。
- 这里错误的行号是
15
. - 列范围是
13 - 59
,封装了tex2D
和Sampler
。
- 这里错误的行号是
我的问题
- 我在
tex2D
调用中为Sampler
使用了错误的数据类型吗? - 是否在
DirectX 11
中弃用了tex2D
? - 我应该改用什么?
- 我在这里做错了什么,因为这是我唯一的错误。
经过广泛搜索后,我发现 ps_4_0
及更高版本不再支持 tex2D
。好吧,4_0
将在旧模式下工作,但它不起作用 5_0
,这正是我正在使用的。
Shader Model : Supported
Shader Model 4 : yes (pixel shader only), but you must use the legacy compile option when compiling.
Shader Model 3 (DirectX HLSL) : yes (pixel shader only)
Shader Model 2 (DirectX HLSL) : yes (pixel shader only)
Shader Model 1 (DirectX HLSL) : yes (pixel shader only)
这已被替换为Texture2D
; documentation 可用。以下是上述文档中的示例:
// Object Declarations
Texture2D g_MeshTexture;
SamplerState MeshTextureSampler
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
float4 Diffuse : COLOR0;
float2 TextureUV : TEXCOORD0;
};
VS_OUTPUT In;
// Shader body calling the intrinsic function
Output.RGBColor = g_MeshTexture.Sample(MeshTextureSampler, In.TextureUV) * In.Diffuse;
替换我的代码中的 tex2D
调用:
result += Texture0.Sample(Sampler, float2(uv.x + offsets[x], uv.y)) * weights[x];
此外,请注意此 post 中的代码用于高斯模糊的水平传递。