问题描述
我正在尝试构建以下 fx 文件,但在标题中出现错误。我的文件有什么问题?我将texture2d 切换到Texture.Sample,因为texture2d 不再存在。这修复了我的第一个错误,但现在出现了这个错误
// 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();
}
}
解决方法
关于 Monogame 中着色器的各种语义,我没有找到很好的参考,但 Texture2D 是有效的。下面是一个将纹理传递到 monogame 管道的示例。
Texture2D ScreenTexture : register(t0);
sampler TextureSampler : register(s0)
{
Texture = (ScreenTexture);
};