1// 2// ShaderPlain.fsh 3// 4 5#define USE_PHONG (1) 6 7uniform lowp vec3 vMaterialAmbient; 8uniform mediump vec4 vMaterialSpecular; 9 10varying lowp vec4 colorDiffuse; 11 12#if USE_PHONG 13uniform highp vec3 vLight0; 14varying mediump vec3 position; 15varying mediump vec3 normal; 16#else 17varying lowp vec4 colorSpecular; 18#endif 19 20void 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