You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

  1. #ifdef GL_ES
  2. precision mediump float;
  3. #endif;
  4. attribute vec4 position;
  5. attribute vec4 texcoord;
  6. attribute vec4 normal;
  7. uniform mat4 ModelMatrix;
  8. uniform mat4 ViewMatrix;
  9. uniform mat4 ProjectionMatrix;
  10. uniform mat4 IT_ModelMatrix;
  11. uniform vec4 U_AmbientMaterial;
  12. uniform vec4 U_AmbientLight;
  13. uniform vec4 U_LightPos;
  14. uniform vec4 U_DiffuseMaterial;
  15. uniform vec4 U_DiffuseLight;
  16. uniform vec4 U_CameraPos;
  17. uniform vec4 U_SpecularMaterial;
  18. uniform vec4 U_SpecualrLight;
  19. varying vec4 V_Color;
  20. void main(){
  21. //ambient
  22. vec4 ambientColor = U_AmbientMaterial*U_AmbientLight;
  23. //diffuse
  24. vec3 L = normalize(U_LightPos.xyz - vec3(0));
  25. vec3 n = normalize((IT_ModelMatrix * normal).xyz);
  26. float diffuseIntensity = max(0.0, dot(L,n));
  27. vec4 diffuseColor = U_DiffuseMaterial * U_DiffuseLight * diffuseIntensity;
  28. //spacular
  29. vec4 specularColor = vec4(0.0, 0.0, 0.0, 0.0);
  30. if(diffuseIntensity > 0) {
  31. vec3 UL = normalize(vec3(0) - U_LightPos.xyz); //��������
  32. vec3 rd = normalize(reflect(UL,n));
  33. vec3 worldPos = (ModelMatrix * position).xyz;
  34. vec3 vd = normalize(U_CameraPos.xyz - worldPos);
  35. float specularIntensity = pow(max(0.0, dot(vd, rd)),4.0);
  36. specularColor = U_SpecularMaterial * U_SpecualrLight * specularIntensity;
  37. }
  38. V_Color = ambientColor + diffuseColor + specularColor;
  39. gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * position;
  40. }