//
//  Object3d.vsh  --  basic Object3d shader w/single texture and lighting
//  PlayMate
//
//  Created by David McKibbin on 7/5/12.
//  Copyright (c) 2012 Firaxis Games. All rights reserved.
//

#ifdef GL_ES
precision highp   int;		// built-in defaults
precision highp   float;
precision lowp    sampler2D;
precision lowp    samplerCube;
#endif

// Inputs
attribute vec4	a_Position;
attribute vec3	a_Normal;
attribute vec4	a_Color;	// team color
attribute vec2	a_TexUV0;

// Outputs
varying   vec4	v_Color;
varying   vec3	v_Light;
varying   vec2	v_TexUV;

// Constants
uniform   vec3	LightVector;	// pre-normalized
uniform   vec3	LightAmbient;
uniform   vec3	LightDiffuse;

uniform   mat4	RenderMatrix;
uniform   mat3	NormalMatrix;

void main()
{
    gl_Position = RenderMatrix * a_Position;

	v_TexUV = a_TexUV0;

	v_Color = a_Color;	// default & preserve alpha

	v_Color.rgb *= v_Color.a;	// pre-mul alpha

    vec3 eyeNormal = normalize( NormalMatrix * a_Normal );

    float nDotVP = max( 0.0, dot( eyeNormal, LightVector ) );

	v_Light = LightAmbient + nDotVP * LightDiffuse;
}
