1 // 2 // ShaderPlain.fsh 3 // 4 5 #define USE_PHONG (1) 6 7 uniform lowp vec3 vMaterialAmbient; 8 uniform mediump vec4 vMaterialSpecular; 9 10 varying lowp vec4 colorDiffuse; 11 12 #if USE_PHONG 13 uniform highp vec3 vLight0; 14 varying mediump vec3 position; 15 varying mediump vec3 normal; 16 #else 17 varying lowp vec4 colorSpecular; 18 #endif 19 20 void main() 21 { 22 #if USE_PHONG 23 mediump vec3 halfVector = normalize(-vLight0 + position); 24 mediump float NdotH = max(dot(normalize(normal), halfVector), 0.0); 25 mediump float fPower = vMaterialSpecular.w; 26 mediump float specular = pow(NdotH, fPower); 27 28 lowp vec4 colorSpecular = vec4( vMaterialSpecular.xyz * specular, 1 ); 29 gl_FragColor = colorDiffuse + colorSpecular; 30 #else 31 gl_FragColor = colorDiffuse + colorSpecular; 32 #endif 33 } 34