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.

38 lines
1.0 KiB

  1. uniform vec4 U_AmbientLightColor;
  2. uniform vec4 U_AmbientMaterial;
  3. uniform vec4 U_LightPos;
  4. uniform vec4 U_DiffuseLightColor;
  5. uniform vec4 U_DiffuseMaterial;
  6. uniform vec3 U_EyePos;
  7. uniform vec4 U_SpecularLightColor;
  8. uniform vec4 U_SpecularMaterial;
  9. varying vec3 V_Normal;
  10. varying vec3 V_WorldPos;
  11. void main()
  12. {
  13. //ambient
  14. vec4 ambientColor = U_AmbientLightColor * U_AmbientMaterial;
  15. //diffuse
  16. vec3 L = vec3(0.0);
  17. if(U_LightPos.w==0.0){
  18. //���Ƿ�����
  19. L = normalize(U_LightPos.xyz);
  20. } else {
  21. //���ǵ���Դ
  22. //model point -> light pos
  23. }
  24. vec3 N = normalize(V_Normal);
  25. float diffuseIntensity = max(0.0, dot(L,N));
  26. vec4 diffuseColor = U_DiffuseLightColor * U_DiffuseMaterial * diffuseIntensity;
  27. //specular
  28. vec3 reflectDir = normalize(reflect(-L,N));//-L��������������ͨ��reflect�����󵽷����ⷽ��
  29. vec3 viewDir = normalize(U_EyePos - V_WorldPos);
  30. vec4 specularColor = U_SpecularLightColor * U_SpecularMaterial * pow(max(0.0, dot(viewDir,reflectDir)), 64.0);
  31. gl_FragColor = ambientColor + diffuseColor + specularColor;
  32. }