嗨,我的像素着色器出现了一个错误, vector 类型的隐式截断。

这是导致错误的代码:

float3 colour = 0;
float3 ppColour = SceneTexture.Sample(PointSample, ppIn.UV);
float4 col = SceneTexture.Sample(PointSample, ppIn.UV);
float intensity = 0.0f;
float r = SceneTexture.Sample(PointSample, ppIn.UV).r;
float g = SceneTexture.Sample(PointSample, ppIn.UV).g;
float b = SceneTexture.Sample(PointSample, ppIn.UV).b;
float a = SceneTexture.Sample(PointSample, ppIn.UV).a;
intensity = r + g + b + a;

if (intensity > 5.0f)
{
    for (int count = 0; count < 13; count++)
    {
        colour += SceneTexture.Sample(TrilinearSampler, ppIn.UV + PixelKernel[count] * BlurStrength) * BlurWeights[count];
    }
    return float4(colour, 1.0f);
}

return float4(ppColour, 1.0f);

如果我注释掉强度= r + g + b + a;然后编译项目。谁能看到我在做什么错,谢谢。

最佳答案

出现此错误的原因是,您要多加/累加float3和float4。您应该使用float4(float3,1.0f)或float4.xyz(使其变为float3)将float3“投射”到float4

关于c++ - DirectX HLSL着色器 vector 类型错误的隐式截断,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29044058/

10-11 21:01