duck0FS.glsl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. precision highp float;
  2. varying vec3 v_normal;
  3. uniform vec3 u_light0Color;
  4. varying vec3 v_light0Direction;
  5. uniform float u_shininess;
  6. uniform vec4 u_ambient;
  7. varying vec2 v_texcoord0;
  8. uniform sampler2D u_diffuse;
  9. uniform vec4 u_emission;
  10. uniform vec4 u_specular;
  11. void main(void) {
  12. vec3 normal = normalize(v_normal);
  13. vec4 color = vec4(0., 0., 0., 0.);
  14. vec4 diffuse = vec4(0., 0., 0., 1.);
  15. vec3 diffuseLight = vec3(0., 0., 0.);
  16. vec4 emission;
  17. vec4 ambient;
  18. vec4 specular;
  19. vec3 specularLight = vec3(0., 0., 0.);
  20. {
  21. float diffuseIntensity;
  22. float specularIntensity;
  23. vec3 l = normalize(v_light0Direction);
  24. vec3 h = normalize(l+vec3(0.,0.,1.));
  25. diffuseIntensity = max(dot(normal,l), 0.);
  26. specularIntensity = pow(max(0.0,dot(normal,h)),u_shininess);
  27. specularLight += u_light0Color * specularIntensity;
  28. diffuseLight += u_light0Color * diffuseIntensity;
  29. }
  30. ambient = u_ambient;
  31. diffuse = texture2D(u_diffuse, v_texcoord0);
  32. emission = u_emission;
  33. specular = u_specular;
  34. specular.xyz *= specularLight;
  35. color.xyz += specular.xyz;
  36. diffuse.xyz *= diffuseLight;
  37. color.xyz += diffuse.xyz;
  38. color.xyz += emission.xyz;
  39. color = vec4(color.rgb * diffuse.a, diffuse.a);
  40. gl_FragColor = color;
  41. }