I want to build the following shader but I keep getting the error " DX9 style intristics are disabled when not in dx9 compatibility mode" . Is there anything wrong with my fx file?
// Our texture sampler
float SINLOC;
float4 filterColor;
texture Texture;
sampler TextureSampler = sampler_state
{
Texture = <Texture>;
};
// This data comes from the sprite batch vertex shader
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCordinate : TEXCOORD0;
};
// Our pixel shader
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
{
float4 texColor = tex2D(TextureSampler, input.TextureCordinate);
float4 color;
if (texColor.a != 0)
{
color = float4(texColor.r + (texColor.r - filterColor.r) * SINLOC, texColor.g + (texColor.g - filterColor.g) * SINLOC, texColor.b + (texColor.b - filterColor.b) * SINLOC, texColor.a);
}
else
{
color = float4(texColor.r, texColor.g, texColor.b, texColor.a);
}
return color * filterColor;
}
// Compile our shader
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
}
}
See this SO answer. I think you need to call Texture.Sample
instead of tex2D
.
Done that but now I am getting the error “texture object does not have any methods”
// Our texture sampler
float SINLOC;
float4 filterColor;
texture Texture;
sampler TextureSampler = sampler_state
{
Texture = <Texture>;
};
// This data comes from the sprite batch vertex shader
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCordinate : TEXCOORD0;
};
// Our pixel shader
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
{
float4 texColor = Texture.Sample(TextureSampler, input.TextureCordinate);
float4 color;
if (texColor.a != 0)
{
color = float4(texColor.r + (texColor.r - filterColor.r) * SINLOC, texColor.g + (texColor.g - filterColor.g) * SINLOC, texColor.b + (texColor.b - filterColor.b) * SINLOC, texColor.a);
}
else
{
color = float4(texColor.r, texColor.g, texColor.b, texColor.a);
}
return color * filterColor;
}
// Compile our shader
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
}
}
Try using
Texture2D Texture;
instead of
texture Texture;
And if there’s an issue with the sampler type, try
SamplerState TextureSampler
instead of
sampler TextureSampler = sampler_state
Edited to this but now I am getting “invalid ps_4_0_leve_9_1 output semantic ‘COLOR’”
// Our texture sampler
float SINLOC;
float4 filterColor;
Texture2D Texture;
sampler TextureSampler = sampler_state
{
Texture = <Texture>;
};
// This data comes from the sprite batch vertex shader
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCordinate : TEXCOORD0;
};
// Our pixel shader
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
{
float4 texColor = Texture.Sample(TextureSampler, input.TextureCordinate);
float4 color;
if (texColor.a != 0)
{
color = float4(texColor.r + (texColor.r - filterColor.r) * SINLOC, texColor.g + (texColor.g - filterColor.g) * SINLOC, texColor.b + (texColor.b - filterColor.b) * SINLOC, texColor.a);
}
else
{
color = float4(texColor.r, texColor.g, texColor.b, texColor.a);
}
return color * filterColor;
}
// Compile our shader
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
}
}
I think your pixel shader output semantic needs to be COLOR0
.
I am having the same problem. Everything worked except the last step:
Changeing “COLOR” → “COLOR0”
did not work for me. Anyone know what I am doing wrong here?