如何解决MonoGame+HLSL:在构建 .fx 文件时使用 tex2Dlod 会引发“无效的 DCL”异常
我正在尝试访问顶点着色器中的纹理。 tex2D 不能在顶点着色器中使用,所以我尝试了 tex2Dlod。但随后不再使用 MonoGame 内容管道工具构建效果文件,向我显示“此着色器模型的 DCL 寄存器类型无效”。我使用 OpenGL 以及 VS 和 PS 着色器模型 3_0,因为 OpenGL 似乎不支持更高版本。
是否有人使用 Monogame 和 OpenGL 成功访问了顶点着色器中的纹理?这可能吗?
这是着色器代码,其唯一目的是在 tex2Dlod 工作时获得该效果:
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
texture2D StateMap;
sampler2D StateMapSampler = sampler_state
{
Texture = <StateMap>;
MinFilter = POINT;
MagFilter = POINT;
MipFilter = POINT;
AddressU = CLAMP;
AddressV = CLAMP;
};
struct VertexShaderInput
{
float4 Position : POSITION0;
};
struct VertexShaderOutput
{
float4 Position : POSITION0;
};
VertexShaderOutput MainVS(in VertexShaderInput input)
{
VertexShaderOutput output;
output.Position = input.Position;
float4 coord = float4(input.Position.x,input.Position.y,0);
output.Position += tex2Dlod(StateMapSampler,coord); // the build only fails,when this line is included
return output;
}
float4 MainPS(VertexShaderOutput input) : COLOR
{
return float4(0,0);
}
technique Technique1
{
pass Pass1
{
VertexShader = compile VS_SHADERMODEL MainVS();
PixelShader = compile PS_SHADERMODEL MainPS();
}
};
这个问题似乎是已知的 (https://github.com/MonoGame/MonoGame/issues/1813),但目前还没有提供解决方案,除了使用更高的着色器版本,我不能,因为 OpenGL。
我使用的是最新的 MonoGame 版本 (3.8)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。