#version 410 compatibility
#define SMAA_PIXEL_SIZE vec2(1.0/512.0, 1.0/512.0)

#define SMAA_THRESHOLD 0.05
#define SMAA_MAX_SEARCH_STEPS 32
#define SMAA_MAX_SEARCH_STEPS_DIAG 16
#define SMAA_CORNER_ROUNDING 25


#ifndef SMAA_DEPTH_THRESHOLD
#define SMAA_DEPTH_THRESHOLD (0.1 * SMAA_THRESHOLD)
#endif


#ifndef SMAA_REPROJECTION
#define SMAA_REPROJECTION 0
#endif

#define SMAA_REPROJECTION_WEIGHT_SCALE 30.0


#ifndef SMAA_AREATEX_MAX_DISTANCE
#define SMAA_AREATEX_MAX_DISTANCE 16
#endif
#ifndef SMAA_AREATEX_MAX_DISTANCE_DIAG
#define SMAA_AREATEX_MAX_DISTANCE_DIAG 20
#endif
#define SMAA_AREATEX_PIXEL_SIZE (1.0 / vec2(160.0, 560.0))
#define SMAA_AREATEX_SUBTEX_SIZE (1.0 / 7.0)


/* --- Define section is over ---- */

/**
 * Edge Detection Vertex Shader
 */
void SMAAEdgeDetectionVS(vec4 position,
                         out vec4 svPosition,
                         inout vec2 texcoord,
                         out vec4 offset[3]) {
    svPosition = position;

    offset[0] = texcoord.xyxy + SMAA_PIXEL_SIZE.xyxy * vec4(-1.0, 0.0, 0.0, -1.0);
    offset[1] = texcoord.xyxy + SMAA_PIXEL_SIZE.xyxy * vec4( 1.0, 0.0, 0.0,  1.0);
    offset[2] = texcoord.xyxy + SMAA_PIXEL_SIZE.xyxy * vec4(-2.0, 0.0, 0.0, -2.0);
}

/* ------------- Header is over -------------- */

out vec2 texcoord;
out vec4 offset[3];
out vec4 dummy2;



attribute vec3 vPosition;
attribute vec2 vTexCoord;
uniform mat4 ProjectionMatrix;


void main()
{
  texcoord = vTexCoord;
  vec4 dummy1 = vec4(0);
  SMAAEdgeDetectionVS(dummy1, dummy2, texcoord, offset);
  gl_Position = ProjectionMatrix * vec4(vPosition.xyz, 1.0);
}