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.

31 lines
895 B

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #ifdef GL_ES
  2. precision mediump float;
  3. #endif
  4. uniform vec4 U_LightPos;
  5. uniform vec4 U_LightAmbient;
  6. uniform vec4 U_LightDiffuse;
  7. uniform vec4 U_AmbientMaterial;
  8. uniform vec4 U_DiffuseMaterial;
  9. varying vec4 V_Color;
  10. varying vec3 V_Normal;
  11. varying vec3 V_WorldPos;
  12. void main()
  13. {
  14. vec4 color=vec4(0.0,0.0,0.0,0.0);
  15. vec4 ambientColor=U_LightAmbient*U_AmbientMaterial;
  16. float distance=0.0;
  17. float constantFactor=1.0;
  18. float linearFactor=0.0;
  19. float quadricFactor=0.0;
  20. vec3 L=U_LightPos.xyz-V_WorldPos;
  21. distance=length(L);
  22. float attenuation=1.0/(constantFactor+linearFactor*distance+quadricFactor*quadricFactor*distance);
  23. L=normalize(L);
  24. vec3 n=normalize(V_Normal);
  25. float diffuseIntensity=max(0.0,dot(L,n));
  26. vec4 diffuseColor=U_LightDiffuse*U_DiffuseMaterial*diffuseIntensity*attenuation*4.0;
  27. color=ambientColor+diffuseColor;
  28. gl_FragData[0]=color*V_Color;
  29. gl_FragData[1]=color*V_Color;
  30. }