如何解决顶点着色器 - 尽管输入/输出匹配,但像素着色器链接错误
我正在尝试制作一些基于变形的顶点动画,但我收到了 #342 错误,告诉我:
D3D11 ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Pixel Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (NR_POSITION,0) as input,but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND]
D3D11 ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Pixel Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (NORMAL,but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND]
D3D11 ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Pixel Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (COLOUR,but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND]
D3D11 ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Pixel Shader linkage error: Signatures between stages are incompatible. Semantic 'UV' is defined for mismatched hardware registers between the output stage and input stage. [ EXECUTION ERROR #343: DEVICE_SHADER_LINKAGE_REGISTERINDEX]
D3D11 ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Pixel Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (BLEND,but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND]
D3D11 ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Pixel Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (LS_POSITION,but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND]
当查看我的着色器时,这让我非常困惑,顶点着色器的输出与像素着色器的输入完全匹配,我通过将输入从像素着色器复制粘贴到顶点着色器来确认这一点,但没有解决问题.我目前对此感到困惑,因为我不知道出了什么问题。我在某处读到过,如果您不设置输出值,它“不算数”,就会被丢弃,这会导致链接错误,但我正在设置所有值,但仍然出现错误。
这是我的着色器代码:
顶点着色器
struct MorphShaderInput
{
float4 position : POSITION;
uint index : INDEX; // Not at all a position but the input layout screams if I don't call it as such
};
struct MorphShaderOutput
{
float4 position : SV_POSITION;
float4 NR_Position : NR_POSITION;
float4 normal : NORMAL;
float3 colour : COLOUR;
float2 uv : UV;
float blend : BLEND;
float4 positionLightSpace : LS_POSITION;
};
struct morphPoint
{
float4 position;
float4 normal;
};
// A structured buffer of the previous frame's values
StructuredBuffer<morphPoint> firstPoint : register(t0);
// A structured buffer of the next frame's values
StructuredBuffer<morphPoint> secondPoint : register(t1);
cbuffer interpolationValue : register(b1) // (This buffer is in slot 1 and not 0)
{
matrix morphWvp;
matrix morphSpace;
float iValue;
}
MorphShaderOutput main(MorphShaderInput input)
{
MorphShaderOutput output;
float4 morphedPosition = (iValue * firstPoint[input.index].position) + ((1.0f - iValue) * secondPoint[input.index].position);
float4 morphedNormal = (iValue * firstPoint[input.index].normal) + ((1.0f - iValue) * secondPoint[input.index].normal);
output.position = mul(morphedPosition,morphWvp);
output.NR_Position = mul(morphedPosition,morphSpace);
output.normal = mul(morphedNormal,morphSpace);
output.colour = float3(0.7f,0.7f,0.7f);
output.uv = float2(0,0);
output.blend = 1.0f;
output.positionLightSpace = float4(0.0f,0.0f,-1.0f);
return output;
}
像素着色器
Texture2D rockTexture : register(t0);
Texture2D dirtTexture : register(t1);
Texture2D grassTexture : register(t2);
Texture2D shadowMap : register(t3);
SamplerState Sampler : register(s0);
SamplerState ShadowSampler : register(s1);
struct PixelShaderInput
{
float4 position : SV_POSITION;
float4 NR_Position : NR_POSITION;
float4 normal : NORMAL;
float3 colour : COLOUR;
float2 uv : UV;
float blend : BLEND;
float4 positionLightSpace : LS_POSITION;
};
cbuffer phongLighting : register(b0)
{
float4 l_pos;
float4 l_cam;
float l_amb;
float l_dif;
float l_spc;
}
cbuffer shadowMapping : register(b1)
{
matrix wvpLight;
matrix inverseWorld;
float2 mapSize;
}
float4 main(PixelShaderInput input) : SV_TARGET
{
// Does containt code that works when linked with other vertex shaders. I don't think the contents here matters to the linkage error
}
解决方法
好吧,我不觉得自己愚蠢,原来问题甚至不在着色器文件中,而是我创建了“VSGetShader()”而不是“VSSetShader()”的类型。
友情提醒所有其他新手:记得检查你是否真的写了“Set”...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。