const vec2 gauss9mask[4] = vec2[4] (
    vec2(1.0, 1.0), vec2(-1.0, 1.0),
    vec2(1.0, -1.0), vec2(-1.0, -1.0)
);

vec2 gauss9cloud(sampler2D tex, float sigma, const float scaleCoord) {
    vec2 pixelRad = sigma/vec2(viewWidth, viewHeight);
    vec2 col = vec2(0.0);

    #ifdef s_cloudOutlineFix
    float mask = 0.0;
    bool terrainEdge = texture(colortex3, coord).x>0.125;

    for (int i = 0; i<4; i++) {
        float temp  = texture(colortex3, coord + gauss9mask[i] * pixelRad).x;
        mask = max(mask, temp);
    }
    bool isTerrain = (mask<0.125) && !terrainEdge;

    if (!isTerrain) col.y = texture(tex, coord*scaleCoord).y;
    if (!isTerrain) sigma *= 0.25;

    for (int i = 0; i<9; i++) {
        vec2 bcoord = coord*scaleCoord + gauss9o[i]*pixelRad;
        if (bcoord.x >= 0.0 && bcoord.x <= 1.0 && bcoord.y >= 0.0 && bcoord.y <= 1.0) {
            vec2 temp = texture(tex, bcoord).xy;
            if (isTerrain) {
                col += temp*gauss9w[i];
            } else {
                col.x += temp.x*gauss9w[i];
                col.y   = max(col.y, temp.y);
            }
        }
    }
    #else

    for (int i = 0; i<9; i++) {
        vec2 bcoord = coord*scaleCoord + gauss9o[i]*pixelRad;
        if (bcoord.x >= 0.0 && bcoord.x <= 1.0 && bcoord.y >= 0.0 && bcoord.y <= 1.0) {
            col += texture(tex, bcoord).xy*gauss9w[i];
        }
    }
    #endif

    return col;
}