gpt4 book ai didi

c++ - 像素着色器中的 SamplerState 问题

转载 作者:行者123 更新时间:2023-12-01 14:47:36 33 4
gpt4 key购买 nike

我的像素着色器有问题,它编译但不渲染任何东西,而是 Directx 给出了这个错误:
D3D11 错误:ID3D11DeviceContext::DrawIndexed:像素着色器单元期望将配置为默认过滤的采样器设置在插槽 0,但绑定(bind)在此插槽的采样器配置为比较过滤。如果使用采样器,这种不匹配将产生未定义的行为(例如,由于着色器代码分支,它不会被跳过)。 [执行错误#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);

关于c++ - 像素着色器中的 SamplerState 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62398339/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com