Bez popisu

lights.frag 988B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. #define lightCount 6
  5. layout (location = 0) in vec3 inNormal;
  6. layout (location = 2) in vec3 inColor;
  7. layout (location = 3) in vec4 inLightVec[lightCount];
  8. layout (location = 0) out vec4 outFragColor;
  9. #define MAX_LIGHT_DIST 9.0 * 9.0
  10. void main()
  11. {
  12. vec3 lightColor[lightCount];
  13. lightColor[0] = vec3(1.0, 0.0, 0.0);
  14. lightColor[1] = vec3(0.0, 1.0, 0.0);
  15. lightColor[2] = vec3(0.0, 0.0, 1.0);
  16. lightColor[3] = vec3(1.0, 0.0, 1.0);
  17. lightColor[4] = vec3(0.0, 1.0, 1.0);
  18. lightColor[5] = vec3(1.0, 1.0, 0.0);
  19. vec3 diffuse = vec3(0.0);
  20. // Just some very basic attenuation
  21. for (int i = 0; i < lightCount; ++i)
  22. {
  23. float lRadius = MAX_LIGHT_DIST * inLightVec[i].w;
  24. float dist = min(dot(inLightVec[i], inLightVec[i]), lRadius) / lRadius;
  25. float distFactor = 1.0 - dist;
  26. diffuse += lightColor[i] * distFactor;
  27. }
  28. outFragColor.rgb = diffuse;
  29. }