CesiumMilkTruck1.frag 1.1 KB

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