preset raw;

uniform highp vec2 direction;
uniform highp vec2 size;
uniform highp float radius;

varying highp vec2 pos;
varying highp vec4 blurPos1;
varying highp vec4 blurPos2;


void vertex()
{
    highp float aspect = size.y / size.x;
    highp float horRadius = aspect * radius;

    highp vec2 offset = vec2(horRadius, radius) * direction;

    VERTEX = apply_mvp(VERTEX);

    pos = (VERTEX + vec2(1.0)) / 2.0;

    blurPos1.xy = pos + offset;
    blurPos1.zw = pos - offset;
    blurPos2.xy = pos + offset * 2.0;
    blurPos2.zw = pos - offset * 2.0;
}


void fragment()
{
    // Very simple gaussian blur.
    highp vec4 sum = zTexture(pos) * 0.375;
    sum += zTexture(blurPos1.xy) * 0.25;
    sum += zTexture(blurPos1.zw) * 0.25;
    sum += zTexture(blurPos2.xy) * 0.0625;
    sum += zTexture(blurPos2.zw) * 0.0625;

    // We actually "add" energy to the wall here while blurring with the * 1.2.
    // Keep in mind that the wall is pitch black right now
    // so it'd look like half brightness of the surroundings otherwise..
    COLOR = sum * 1.1;
}
