DirectX HLSL shader implicit truncation of vector type error

12,256

The reason you get this error is, that you are mulitplying/adding up float3's and float4's. You should 'cast' float3 to float4 with float4(float3, 1.0f) or float4.xyz (which makes it float3)

Share:
12,256
user3427689
Author by

user3427689

Updated on June 04, 2022

Comments

  • user3427689
    user3427689 almost 2 years

    Hi I'm getting an error in one my pixel shaders, implicit truncation of vector type.

    Here is the code causing the error:

    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);
    

    If I comment out intensity = r + g + b + a; then the project compiles. Can anyone see what I'm doing wrong, thanks.