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.

70 lines
2.1 KiB

  1. #version 400 core
  2. subroutine vec4 SurfaceColor();
  3. uniform sampler2D U_MainTexture;
  4. subroutine uniform SurfaceColor U_SurfaceColor;
  5. varying vec3 V_Normal;
  6. varying vec4 V_WorldPos;//��ǰ��λ��
  7. varying vec2 V_Texcoord;
  8. subroutine (SurfaceColor) vec4 Ambient(){
  9. //ambient
  10. vec4 AmbientLightColor = vec4(0.4, 0.4, 0.4, 1.0);
  11. vec4 AmbientMaterial = vec4(0.2, 0.2, 0.2, 1.0);
  12. vec4 AmbientColor = AmbientLightColor*AmbientMaterial;
  13. vec4 ret = AmbientColor;
  14. return ret;
  15. }
  16. subroutine (SurfaceColor) vec4 Diffuse(){
  17. vec3 lightPos = vec3(10.0, 10.0, 0.0);
  18. vec3 L=lightPos;
  19. L = normalize(L);
  20. vec3 n = normalize(V_Normal);
  21. //ambient
  22. vec4 AmbientLightColor = vec4(0.4, 0.4, 0.4, 1.0);
  23. vec4 AmbientMaterial = vec4(0.2, 0.2, 0.2, 1.0);
  24. vec4 AmbientColor = AmbientLightColor*AmbientMaterial;
  25. //diffuse
  26. vec4 DiffuseLightColor = vec4(1.0,1.0,1.0,1.0);
  27. vec4 DiffuseMaterial = vec4(0.8, 0.8, 0.8, 1.0);
  28. vec4 diffuseColor = DiffuseLightColor*DiffuseMaterial*max(0.0, dot(L,n));
  29. vec4 ret = AmbientColor + texture2D(U_MainTexture, V_Texcoord) * diffuseColor;
  30. return ret;
  31. }
  32. subroutine (SurfaceColor) vec4 Specular(){
  33. vec3 lightPos = vec3(10.0, 10.0, 0.0);
  34. vec3 L=lightPos;
  35. L = normalize(L);
  36. vec3 n = normalize(V_Normal);
  37. //ambient
  38. vec4 AmbientLightColor = vec4(0.4, 0.4, 0.4, 1.0);
  39. vec4 AmbientMaterial = vec4(0.2, 0.2, 0.2, 1.0);
  40. vec4 AmbientColor = AmbientLightColor*AmbientMaterial;
  41. //diffuse
  42. vec4 DiffuseLightColor = vec4(1.0,1.0,1.0,1.0);
  43. vec4 DiffuseMaterial = vec4(0.8, 0.8, 0.8, 1.0);
  44. vec4 diffuseColor = DiffuseLightColor*DiffuseMaterial*max(0.0, dot(L,n));
  45. //specular
  46. vec4 SpecularLightColor = vec4(1.0,1.0,1.0,1.0);
  47. vec4 SpecularMaterial = vec4(0.9,0.9,0.9,1.0);
  48. vec3 reflectDir = normalize(reflect(-L,n));//-L���ǹ��ߵ����䷽���������Է���Ϊ�������㷽ʽ����
  49. vec3 viewDir = normalize(vec3(0.0) - V_WorldPos.xyz);//vec3(0.0)��ʾ������Ϊ�۲��㣬�����������۾�����������������
  50. vec4 specularColor = SpecularLightColor*SpecularMaterial*pow(max(0.0,dot(viewDir,reflectDir)),128.0);
  51. vec4 ret = AmbientColor + texture2D(U_MainTexture, V_Texcoord) * diffuseColor + specularColor;
  52. return ret;
  53. }
  54. void main() {
  55. gl_FragColor = U_SurfaceColor();
  56. }