Reputation: 2923
I am currently writing an HLSL
shader for a basic Gaussian blur. The shader code is straight forward, but I keep getting an error:
DX9 style intristics are disabled when not in dx9 compatibility mode. (LN#: 19)
This tells me that line 19 in my code is the issue, and I believe it is either due to tex2D
or Sampler
in that particular line.
#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;
}
See below for notes about the code, and my questions.
I have to hand type my code into StackOverflow due to my code being on a computer without a connection. Therefore:
offsets
and weights
is intentional.
offsets
is every integer from -10
to 10
.weights
ranges from 0.01
to 0.25
and back to 0.01
.15
.13 - 59
which encapsulates tex2D
and Sampler
.Sampler
in the tex2D
call?tex2D
deprecated in DirectX 11
?Upvotes: 5
Views: 2488
Reputation: 2923
After some extensive searching, I've found out that tex2D
is no longer supported from ps_4_0
and up. Well, 4_0
will work in legacy mode, but it doesn't work it 5_0
which is what I am using.
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)
This has been replaced by Texture2D
; the documentation is available for it. Below is an example from the mentioned 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;
To replace the tex2D
call in my code:
result += Texture0.Sample(Sampler, float2(uv.x + offsets[x], uv.y)) * weights[x];
Also, note that the code in this post is for the horizontal pass of a Gaussian blur.
Upvotes: 4