uniform vec4 uniOverallColor;
uniform vec4 cRadiusScale;
uniform vec3 cSceneScale;

varying float rLogValueTransferFunction;

varying vec3 v;
varying vec3 vObjPos;
varying vec3 cNormal;
varying vec4 cNoValueColor;

uniform vec4
  acPos[16];

uniform float
  arProp[16];

uniform vec3
  acVecX[16],
  acVecY[16],
  acVecZ[16];

void main()
{
  int
    iVertex = int(gl_Vertex.x);

  rLogValueTransferFunction = arProp[iVertex];

  vec3
    cPos = acPos[iVertex].xyz;

  mat3
    cMat = mat3(acVecX[iVertex], acVecY[iVertex], acVecZ[iVertex]);

  vec3
    cDir = gl_Vertex.yzw;

  cPos += (cMat * cDir) * vec3(cRadiusScale.w);

  gl_FrontColor = uniOverallColor;
  cNoValueColor = gl_Color;
  
  cNormal = cDir;
  
  cNormal.x /= length(vec3(cMat[0].x, cMat[1].x, cMat[2].x));
  cNormal.y /= length(vec3(cMat[0].y, cMat[1].y, cMat[2].y));
  cNormal.z /= length(vec3(cMat[0].z, cMat[1].z, cMat[2].z));

  cMat[0] = normalize(cMat[0]);
  cMat[1] = normalize(cMat[1]);
  cMat[2] = normalize(cMat[2]);

  cNormal = normalize(gl_NormalMatrix * (cMat * cNormal));
  
  gl_Position = gl_ModelViewProjectionMatrix * vec4(cPos, 1.0);
  vObjPos = (gl_ModelViewMatrix * vec4(cPos, 1.0)).xyz;

  v = vObjPos = vec3(gl_ModelViewMatrix * vec4(cPos.xyz, 1.0));
  vObjPos.z -=  gl_ModelViewMatrix[3][2];

  gl_ClipVertex = gl_ModelViewMatrix * vec4(cPos.xyz,1.0);
}
