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

4 years ago
  1. #ifdef GL_ES
  2. precision mediump float;
  3. #endif
  4. uniform vec4 U_AmbientMaterial;
  5. uniform vec4 U_AmbientLight;
  6. uniform vec4 U_LightPos;
  7. uniform vec4 U_DiffuseMaterial;
  8. uniform vec4 U_DiffuseLight;
  9. uniform vec4 U_CameraPos;
  10. uniform vec4 U_SpecularMaterial;
  11. uniform vec4 U_SpecularLight;
  12. varying vec4 V_Normal;
  13. varying vec4 V_WorldPos;
  14. void main()
  15. {
  16. //ambient
  17. vec4 ambirntColor = U_AmbientMaterial*U_AmbientLight;
  18. //diffuse
  19. vec3 L = normalize(U_LightPos.xyz - vec3(0));
  20. vec3 n = normalize(V_Normal.xyz);
  21. float diffuseIntensity = max(0.0, dot(L,n));
  22. vec4 diffuseColor = U_DiffuseMaterial * U_DiffuseLight * diffuseIntensity;
  23. //specular blin
  24. vec4 specularColor = vec4(0);
  25. if(diffuseIntensity > 0.0) {
  26. vec3 vd = normalize((U_CameraPos - V_WorldPos).xyz);
  27. vec3 halfD = normalize(L+vd);
  28. float specularIntensity = pow(max(0.0, dot(n, halfD)),32.0);
  29. specularColor = U_SpecularMaterial * U_SpecularLight * specularIntensity;
  30. }
  31. gl_FragColor=ambirntColor + diffuseColor + specularColor;
  32. }