#version 410 core

layout(PATCH_TYPE, fractional_odd_spacing, ccw) in;

uniform mat4 uModelViewProjectionMatrix;
uniform mat4 uModelViewMatrix;

in vec4 vertexPos_ES_in[];
out vec3 vObjPos;
//out N;
DECLARE_VERTEX_PROPERTIES

void main()
{
  vec4
    cFinalVert = vec4(0.0);
  
  DECLARE_VERTEX_PROPERTY_FINALS

  float
    rU = gl_TessCoord.x,
    rV = gl_TessCoord.y;

  float
    arB_u[] = float[DEGREEU+1](BASIS_U),
    arB_v[] = float[DEGREEV+1](BASIS_V);

  for (int iJ = 0; iJ <= DEGREEV; iJ++)
  {
    for (int iI = 0; iI <= DEGREEU; iI++)
    {
      float
        rB = arB_u[iI] * arB_v[iJ];

      int
        iVertex = iI + iJ*(DEGREEU+1);

      cFinalVert = cFinalVert + vertexPos_ES_in[iVertex]*rB;
      COMPUTE_VERTEX_PROPERTIES
    }
  }

 float
   finalW = cFinalVert.w;

  vec3
    cFinalPos = cFinalVert.xyz/finalW;

  vObjPos = vec3(uModelViewMatrix* vec4(cFinalPos , 1.0));
  SET_VERTEX_PROPERTIES

  //N = vec3(1,0,0);

  gl_Position = uModelViewProjectionMatrix * vec4(cFinalPos, 1.0);
}






/*
rgb.x = 1.0;//mod(gl_TessCoord.x * gl_TessLevelInner[1],0.9);
rgb.y = 1.0;//mod(gl_TessCoord.y * gl_TessLevelInner[0],0.9);
rgb.z = 1.0;
*/
