CesiumMilkTruck3.frag 1.1 KB

12345678910111213141516171819202122232425262728
  1. precision highp float;
  2. uniform vec4 u_diffuse;
  3. uniform vec4 u_specular;
  4. uniform float u_shininess;
  5. uniform float u_transparency;
  6. varying vec3 v_position;
  7. varying vec3 v_normal;
  8. void main(void) {
  9. vec3 normal = normalize(v_normal);
  10. vec4 diffuse = u_diffuse;
  11. vec3 diffuseLight = vec3(0.0, 0.0, 0.0);
  12. vec3 specular = u_specular.rgb;
  13. vec3 specularLight = vec3(0.0, 0.0, 0.0);
  14. vec3 ambient = diffuse.rgb;
  15. vec3 viewDir = -normalize(v_position);
  16. vec3 ambientLight = vec3(0.0, 0.0, 0.0);
  17. ambientLight += vec3(0.2, 0.2, 0.2);
  18. vec3 l = vec3(0.0, 0.0, 1.0);
  19. diffuseLight += vec3(1.0, 1.0, 1.0) * max(dot(normal, l), 0.);
  20. vec3 reflectDir = reflect(-l, normal);
  21. float specularIntensity = max(0., pow(max(dot(reflectDir, viewDir), 0.), u_shininess));
  22. specularLight += vec3(1.0, 1.0, 1.0) * specularIntensity;
  23. vec3 color = vec3(0.0, 0.0, 0.0);
  24. color += diffuse.rgb * diffuseLight;
  25. color += specular * specularLight;
  26. color += ambient * ambientLight;
  27. gl_FragColor = vec4(color * diffuse.a * u_transparency, diffuse.a * u_transparency);
  28. }