Black squares in bloom effect

Good Morning!
I’m having trouble rendering an on-screen bloom shader by post processing.
Basically the shader works like this:

Camera image before rendering the effect:

First a filter is passed on the camera image to leave only one highlights.

float4 _BloomThreshold;
float _BloomIntensity;
float _BloomScattering;

float3 ApplyBloomThreshold(float3 color) {
    float brightness = Max3(color.r, color.g, color.b);
    float soft = brightness + _BloomThreshold.y;
    soft = clamp(soft, 0.0, _BloomThreshold.z);
    soft = soft * soft * _BloomThreshold.w;
    float contribution = max(soft, brightness - _BloomThreshold.x);
    contribution /= max(brightness, 0.00001);
    return color * contribution;
}

float4 PreFilter(Varyings i) : SV_TARGET{
    float3 color = pow(ApplyBloomThreshold(GetSource(i.fxUV).rgb),2);
    return float4(color, 1.0);
}

After that, the image goes through a downsample:

float4 FragBox(Varyings i) : SV_Target
{
    return float4(SampleBox(i.fxUV),1);
}

static const float gaussian[14] = {
    0.00598,    0.060626,    0.241843,    0.383103,    0.241843,    0.060626,    0.00598,
    0.02400,    0.0160125,    0.741843,    0.455653,    0.296803,    0.189060,    0.18406
};

float4 FragHBlur(Varyings i) : SV_Target
{
    float4 color;
    float2 o = float2(GetSourceTexelSize().x, 0);
    for (int idx = -3; idx <= 3; idx++) {
        float4 tColor = GetSource(i.fxUV + idx * o);
        color += tColor * gaussian[idx + 3];
    }
    return float4(color.rgb, 1 / _Levels);
}

float4 FragVBlur(Varyings i) : SV_Target
{
    float4 color;
    float2 o = float2(0, GetSourceTexelSize().y);
    for (int idx = -3; idx <= 3; idx++) {
        float4 tColor = GetSource(i.fxUV + idx * o);
        color += tColor * gaussian[idx + 3];
    }
    return float4(color.rgb, 1 / _Levels);
}

This step occurs several times in the effect’s rendering, with each of the images used from source having its dimensions shrunk.

After the image is blurred, it will be merged with the image from the previous frame, which was also blurred but has larger dimensions.

After merging all bloomed images, the final image is merged with the camera image before rendering the effect:

So far so good.

The problem is these black squares that sometimes appear when I move the camera.
Why are they there???

The same problem happens in the lens flare shader, which uses the same downsample method:

@MatheusMarkies
I wonder if NaN’s are causing that problem.

Same here, getting NaNs everywhere after latest update. had to revert because its unusable.

1 Like

@Oniros88
Aw man. Sorry to hear that.