1//
2//  ShaderPlain.vsh
3//
4
5#define USE_PHONG (1)
6
7attribute highp vec3    myVertex;
8attribute highp vec3    myNormal;
9attribute mediump vec2  myUV;
10attribute mediump vec4  myBone;
11
12varying mediump vec2    texCoord;
13varying lowp    vec4    colorDiffuse;
14
15#if USE_PHONG
16varying mediump vec3 position;
17varying mediump vec3 normal;
18#else
19varying lowp    vec4    colorSpecular;
20#endif
21
22uniform highp mat4      uMVMatrix;
23uniform highp mat4      uPMatrix;
24
25uniform highp vec3      vLight0;
26
27uniform lowp vec4       vMaterialDiffuse;
28uniform lowp vec3       vMaterialAmbient;
29uniform lowp vec4       vMaterialSpecular;
30
31void main(void)
32{
33    highp vec4 p = vec4(myVertex,1);
34    gl_Position = uPMatrix * p;
35
36    texCoord = myUV;
37
38    highp vec3 worldNormal = vec3(mat3(uMVMatrix[0].xyz, uMVMatrix[1].xyz, uMVMatrix[2].xyz) * myNormal);
39    highp vec3 ecPosition = p.xyz;
40
41    colorDiffuse = dot( worldNormal, normalize(-vLight0+ecPosition) ) * vMaterialDiffuse  + vec4( vMaterialAmbient, 1 );
42
43#if USE_PHONG
44    normal = worldNormal;
45    position = ecPosition;
46#else
47    highp vec3 halfVector = normalize(ecPosition - vLight0);
48
49    highp float NdotH = max(-dot(worldNormal, halfVector), 0.0);
50    float fPower = vMaterialSpecular.w;
51    highp float specular = min( pow(NdotH, fPower), 1.0);
52    colorSpecular = vec4( vMaterialSpecular.xyz * specular, 1 );
53#endif
54}
55