Home | History | Annotate | Download | only in Shaders
      1 //
      2 //  ShaderPlain.vsh
      3 //
      4 
      5 #define USE_PHONG (1)
      6 
      7 attribute highp vec3    myVertex;
      8 attribute highp vec3    myNormal;
      9 attribute mediump vec2  myUV;
     10 attribute mediump vec4  myBone;
     11 
     12 varying mediump vec2    texCoord;
     13 varying lowp    vec4    colorDiffuse;
     14 
     15 #if USE_PHONG
     16 varying mediump vec3 position;
     17 varying mediump vec3 normal;
     18 #else
     19 varying lowp    vec4    colorSpecular;
     20 #endif
     21 
     22 uniform highp mat4      uMVMatrix;
     23 uniform highp mat4      uPMatrix;
     24 
     25 uniform highp vec3      vLight0;
     26 
     27 uniform lowp vec4       vMaterialDiffuse;
     28 uniform lowp vec3       vMaterialAmbient;
     29 uniform lowp vec4       vMaterialSpecular;
     30 
     31 void 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