Ingen beskrivning

composition.frag 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (input_attachment_index = 0, binding = 0) uniform subpassInput samplerposition;
  5. layout (input_attachment_index = 1, binding = 1) uniform subpassInput samplerNormal;
  6. layout (input_attachment_index = 2, binding = 2) uniform subpassInput samplerAlbedo;
  7. layout (location = 0) in vec2 inUV;
  8. layout (location = 0) out vec4 outColor;
  9. layout (constant_id = 0) const int NUM_LIGHTS = 64;
  10. struct Light {
  11. vec4 position;
  12. vec3 color;
  13. float radius;
  14. };
  15. layout (binding = 3) uniform UBO
  16. {
  17. vec4 viewPos;
  18. Light lights[NUM_LIGHTS];
  19. } ubo;
  20. void main()
  21. {
  22. // Read G-Buffer values from previous sub pass
  23. vec3 fragPos = subpassLoad(samplerposition).rgb;
  24. vec3 normal = subpassLoad(samplerNormal).rgb;
  25. vec4 albedo = subpassLoad(samplerAlbedo);
  26. #define ambient 0.15
  27. // Ambient part
  28. vec3 fragcolor = albedo.rgb * ambient;
  29. for(int i = 0; i < NUM_LIGHTS; ++i)
  30. {
  31. // Vector to light
  32. vec3 L = ubo.lights[i].position.xyz - fragPos;
  33. // Distance from light to fragment position
  34. float dist = length(L);
  35. // Viewer to fragment
  36. vec3 V = ubo.viewPos.xyz - fragPos;
  37. V = normalize(V);
  38. // Light to fragment
  39. L = normalize(L);
  40. // Attenuation
  41. float atten = ubo.lights[i].radius / (pow(dist, 2.0) + 1.0);
  42. // Diffuse part
  43. vec3 N = normalize(normal);
  44. float NdotL = max(0.0, dot(N, L));
  45. vec3 diff = ubo.lights[i].color * albedo.rgb * NdotL * atten;
  46. // Specular part
  47. // Specular map values are stored in alpha of albedo mrt
  48. vec3 R = reflect(-L, N);
  49. float NdotR = max(0.0, dot(R, V));
  50. //vec3 spec = ubo.lights[i].color * albedo.a * pow(NdotR, 32.0) * atten;
  51. fragcolor += diff;// + spec;
  52. }
  53. outColor = vec4(fragcolor, 1.0);
  54. }