像素着色器中的SamplerState问题

Ciubix8513

我的像素着色器有问题,它可以编译但不呈现任何内容,而Directx会发出此错误:D3D11错误:ID3D11DeviceContext :: DrawIndexed:Pixel Shader单元期望将配置为默认过滤的采样器设置为插槽0,但是绑定到此插槽的采样器已配置为进行比较过滤。如果使用了采样器,则这种不匹配将产生不确定的行为(例如,由于着色器代码分支而不会被跳过)。[执行错误#390:DEVICE_DRAW_SAMPLER_MISMATCH]。这是我的着色器:

struct PixelInput
{
 float4 position: SV_POSITION;
 float4 color : COLOR;
 float2 UV: TEXCOORD0;

};

//globals
SamplerState ss;
Texture2D shaderTex;

float4 TexturePixelShader(PixelInput input) : SV_TARGET
{
 float4 texColors;

 texColors = shaderTex.Sample(ss, input.UV);

 return texColors;
}

采样器创建:

samplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
    samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
    samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
    samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    samplerDesc.MipLODBias = 0.0f;
    samplerDesc.MaxAnisotropy = 1;
    samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
    samplerDesc.BorderColor[0] = 0;
    samplerDesc.BorderColor[1] = 0;
    samplerDesc.BorderColor[2] = 0;
    samplerDesc.BorderColor[3] = 0;
    samplerDesc.MinLOD = 0;
    samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
    result = device->CreateSamplerState(&samplerDesc,  &m_SS);
    if (FAILED(result))
        return false;
    return true;

和渲染功能:

void TextureShader::RenderShader(ID3D11DeviceContext* ctxt, int indexCount)
{
    ctxt->IASetInputLayout(m_layout);

    ctxt->VSSetShader(m_vertexShader, NULL, 0);
    ctxt->PSSetShader(m_pixelShader, NULL, 0);
    ctxt->PSSetSamplers(0, 1, &m_SS);
    ctxt->DrawIndexed(indexCount, 0, 0);

    return;
}
卡特彼勒

您将您的采样器声明为比较采样器:

samplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;

它应该是 :

samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;

比较采样器主要用于阴影贴图,并在hlsl中声明如下:

SamplerComparisonState myComparisonSampler;
myTexture.SampleCmp(myComparisonSampler, texCoord);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章