fragment.fs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #version 430
  2. layout (location = 0) in vec2 pos;
  3. layout (location = 1) in vec2 tex;
  4. layout (location = 2) in vec4 vertexColor;
  5. layout (binding = 0) uniform sampler2D samp;
  6. uniform mat4 viewMatrix;
  7. uniform mat4 modelMatrix;
  8. uniform float depth;
  9. uniform vec3 ambientLight;
  10. struct Light
  11. {
  12. vec2 pos;
  13. float strength;
  14. vec3 color;
  15. };
  16. uniform Light lights[32];
  17. uniform bool useTexture;
  18. uniform bool useColor;
  19. uniform bool useLight;
  20. in vec2 tc;
  21. in vec2 loc;
  22. in vec4 vColor;
  23. out vec4 color;
  24. vec4 getLight()
  25. {
  26. vec3 light = vec3(0, 0, 0);
  27. for(int i = 0; i < 32; i++)
  28. {
  29. light += lights[i].color * max(1 - lights[i].strength * length(loc - lights[i].pos), 0);
  30. }
  31. return vec4(min(light, vec3(1, 1, 1)), 1);
  32. }
  33. void main(void)
  34. {
  35. if(useTexture)
  36. {
  37. color = texture(samp, tc);
  38. if(color.a != 1.0)
  39. {
  40. discard;
  41. }
  42. if(useColor)
  43. {
  44. color = vColor;
  45. }
  46. }
  47. else
  48. {
  49. color = vColor;
  50. }
  51. if(useLight)
  52. {
  53. color = pow(pow(color, vec4(1 / 2.2)) * vec4(ambientLight, 1.0) + getLight(), vec4(2.2));
  54. }
  55. }