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.

33 lines
1.2 KiB

4 years ago
4 years ago
4 years ago
  1. uniform sampler2D U_MainTexture;
  2. varying vec3 V_Normal;
  3. varying vec4 V_WorldPos;//��ǰ��λ��
  4. varying vec2 V_Texcoord;
  5. void main() {
  6. vec3 lightPos = vec3(10.0, 10.0, 0.0);
  7. vec3 L=lightPos;
  8. L = normalize(L);
  9. vec3 n = normalize(V_Normal);
  10. //ambient
  11. vec4 AmbientLightColor = vec4(0.2, 0.2, 0.2, 1.0);
  12. vec4 AmbientMaterial = vec4(0.2, 0.2, 0.2, 1.0);
  13. vec4 AmbientColor = AmbientLightColor*AmbientMaterial;
  14. //diffuse
  15. vec4 DiffuseLightColor = vec4(1.0,1.0,1.0,1.0);
  16. vec4 DiffuseMaterial = vec4(0.8, 0.8, 0.8, 1.0);
  17. vec4 diffuseColor = DiffuseLightColor*DiffuseMaterial*max(0.0, dot(L,n));
  18. //specular
  19. vec4 SpecularLightColor = vec4(1.0,1.0,1.0,1.0);
  20. vec4 SpecularMaterial = vec4(0.9,0.9,0.9,1.0);
  21. vec3 reflectDir = normalize(reflect(-L,n));//-L���ǹ��ߵ����䷽���������Է���Ϊ�������㷽ʽ����
  22. vec3 viewDir = normalize(vec3(0.0) - V_WorldPos.xyz);//vec3(0.0)��ʾ������Ϊ�۲��㣬�����������۾�����������������
  23. vec4 specularColor = SpecularLightColor*SpecularMaterial*pow(max(0.0,dot(viewDir,reflectDir)),128.0);
  24. //gl_FragColor = texture2D(U_MainTexture, V_Texcoord) * (AmbientColor + diffuseColor + specularColor);
  25. gl_FragColor = AmbientColor + texture2D(U_MainTexture, V_Texcoord) * diffuseColor + specularColor;
  26. }