Refl.frag.glsl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma anki type frag
  6. #pragma anki include "shaders/Pack.glsl"
  7. // Common
  8. layout(TEX_BINDING(0, 0)) uniform sampler2D u_depthRt;
  9. layout(TEX_BINDING(0, 1)) uniform sampler2D u_msRt1;
  10. layout(TEX_BINDING(0, 2)) uniform sampler2D u_msRt2;
  11. layout(std140, UBO_BINDING(0, 0)) uniform _blk0
  12. {
  13. vec4 u_projectionParams;
  14. mat4 u_projectionMat;
  15. };
  16. // IR
  17. #if IR_ENABLED
  18. #define IMAGE_REFLECTIONS_SET 0
  19. #define IMAGE_REFLECTIONS_FIRST_SS_BINDING 0
  20. #define IMAGE_REFLECTIONS_TEX_BINDING 4
  21. #pragma anki include "shaders/ImageReflections.glsl"
  22. #undef IMAGE_REFLECTIONS_SET
  23. #undef IMAGE_REFLECTIONS_FIRST_SS_BINDING
  24. #endif
  25. // SSLR
  26. #if SSLR_ENABLED
  27. layout(TEX_BINDING(0, 3)) uniform sampler2D u_isRt;
  28. #pragma anki include "shaders/Sslr.glsl"
  29. #endif
  30. // In/out
  31. layout(location = 0) in vec2 in_texCoord;
  32. layout(location = 0) out vec3 out_color;
  33. void main()
  34. {
  35. //
  36. // Decode the G-buffer
  37. //
  38. float depth = texture(u_depthRt, in_texCoord).r;
  39. vec3 posVSpace;
  40. posVSpace.z = u_projectionParams.z / (u_projectionParams.w + depth);
  41. posVSpace.xy =
  42. (2.0 * in_texCoord - 1.0) * u_projectionParams.xy * posVSpace.z;
  43. float roughness;
  44. readRoughnessFromGBuffer(u_msRt1, in_texCoord, roughness);
  45. vec3 normal;
  46. readNormalFromGBuffer(u_msRt2, in_texCoord, normal);
  47. // Compute relflection vector
  48. vec3 eye = normalize(posVSpace);
  49. vec3 r = reflect(eye, normal);
  50. //
  51. // SSLR
  52. //
  53. #if SSLR_ENABLED
  54. float sslrContribution;
  55. // Don't bother for very rough surfaces
  56. if(roughness > SSLR_START_ROUGHNESS)
  57. {
  58. sslrContribution = 1.0;
  59. out_color = vec3(1.0, 0.0, 1.0);
  60. }
  61. else
  62. {
  63. sslrContribution = 0.0;
  64. }
  65. #else
  66. const float sslrContribution = 0.0;
  67. #endif
  68. //
  69. // IR
  70. //
  71. #if IR_ENABLED
  72. float reflLod = float(IR_MIPMAP_COUNT) * roughness;
  73. vec3 imgRefl = doImageReflections(posVSpace, r, reflLod);
  74. out_color = mix(imgRefl, out_color, sslrContribution);
  75. #endif
  76. out_color *= (1.0 - roughness);
  77. }