map_fragment.glsl 690 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #version 330 core
  2. in vec2 uv;
  3. in vec3 normal;
  4. in vec3 to_cam;
  5. in vec3 light0_to;
  6. out vec4 final_colour;
  7. uniform sampler2D texture0;
  8. vec4 light0_colour = vec4(1.0,1.0,1.0,1.0);
  9. float light0_att = 0.0;
  10. void main(void)
  11. {
  12. vec3 n = normalize(normal);
  13. vec3 diffuse = vec3(0.0);
  14. float att = 1.0;
  15. if (light0_att > 0.0) {
  16. float dist = length(light0_to);
  17. if (dist > light0_att) {
  18. att = 0.0;
  19. }else{
  20. att = 1.0-((1.0/light0_att)*dist);
  21. }
  22. }
  23. if (att > 0.0) {
  24. vec3 to = normalize(light0_to);
  25. diffuse += max((max(dot(n,to),0.0)*light0_colour.rgb)*att,0.2);
  26. }else{
  27. diffuse += vec3(0.2);
  28. }
  29. vec4 texdata = texture(texture0,uv);
  30. final_colour = vec4(diffuse,1.0)*texdata;
  31. }