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

vec3 gauss9cloud(sampler2D tex, float sigma, const float scaleCoord) {
    vec2 pixelRad = sigma/vec2(viewWidth, viewHeight);
    vec3 col = vec3(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) {
            vec3 temp = texture(tex, bcoord).xyz;
            if (isTerrain) {
                col += temp*gauss9w[i];
            } else {
                col.xz += temp.xz*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).xyz*gauss9w[i];
        }
    }
    #endif

    return col;
}