Pps.glsl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #pragma anki start vertexShader
  2. #pragma anki include "shaders/SimpleVert.glsl"
  3. #pragma anki start fragmentShader
  4. #pragma anki include "shaders/Common.glsl"
  5. #pragma anki include "shaders/photoshop_filters.glsl"
  6. #pragma anki include "shaders/LinearDepth.glsl"
  7. uniform highp sampler2D msDepthFai;
  8. uniform lowp sampler2D isFai;
  9. uniform lowp sampler2D ppsHdrFai;
  10. uniform lowp sampler2D ppsSsaoFai;
  11. uniform lowp sampler2D ppsLfFai;
  12. in vec2 vTexCoords;
  13. layout(location = 0) out vec3 fColor;
  14. const vec2 TEX_OFFSET = vec2(1.0 / float(FBO_WIDTH), 1.0 / float(FBO_HEIGHT));
  15. const vec2 KERNEL[8] = vec2[](
  16. vec2(TEX_OFFSET.x, TEX_OFFSET.y),
  17. vec2(0.0, TEX_OFFSET.y),
  18. vec2(-TEX_OFFSET.x, TEX_OFFSET.y),
  19. vec2(-TEX_OFFSET.x, 0.0),
  20. vec2(-TEX_OFFSET.x, -TEX_OFFSET.y),
  21. vec2(0.0, -TEX_OFFSET.y),
  22. vec2(TEX_OFFSET.x, -TEX_OFFSET.y),
  23. vec2(TEX_OFFSET.x, 0.0));
  24. //==============================================================================
  25. vec3 grayScale(in vec3 col)
  26. {
  27. float grey = (col.r + col.g + col.b) * 0.333333333; // aka: / 3.0
  28. return vec3(grey);
  29. }
  30. //==============================================================================
  31. vec3 saturation(in vec3 col, in float factor)
  32. {
  33. const vec3 lumCoeff = vec3(0.2125, 0.7154, 0.0721);
  34. vec3 intensity = vec3(dot(col, lumCoeff));
  35. return mix(intensity, col, factor);
  36. }
  37. //==============================================================================
  38. vec3 gammaCorrection(in float gamma, in vec3 col)
  39. {
  40. return pow(col, vec3(1.0 / gamma));
  41. }
  42. //==============================================================================
  43. vec3 gammaCorrectionRgb(in vec3 gamma, in vec3 col)
  44. {
  45. return pow(col, 1.0 / gamma);
  46. }
  47. //==============================================================================
  48. vec3 sharpen(in sampler2D tex, in vec2 texCoords)
  49. {
  50. const float sharpenFactor = 0.25;
  51. vec3 col = textureFai(tex, texCoords).rgb;
  52. vec3 col2 = textureFai(tex, texCoords + KERNEL[0]).rgb;
  53. for(int i = 1; i < 8; i++)
  54. {
  55. col2 += textureFai(tex, texCoords + KERNEL[i]).rgb;
  56. }
  57. return col * (8.0 * sharpenFactor + 1.0) - sharpenFactor * col2;
  58. }
  59. //==============================================================================
  60. vec3 erosion(in sampler2D tex, in vec2 texCoords)
  61. {
  62. vec3 minValue = textureFai(tex, texCoords).rgb;
  63. for (int i = 0; i < 8; i++)
  64. {
  65. vec3 tmpCol = textureFai(tex, texCoords + KERNEL[i]).rgb;
  66. minValue = min(tmpCol, minValue);
  67. }
  68. return minValue;
  69. }
  70. //==============================================================================
  71. void main(void)
  72. {
  73. #if defined(SHARPEN_ENABLED)
  74. fColor = sharpen(isFai, vTexCoords);
  75. #else
  76. fColor = textureFai(isFai, vTexCoords).rgb;
  77. #endif
  78. //fColor = erosion(isFai, vTexCoords);
  79. #if defined(HDR_ENABLED)
  80. vec3 hdr = textureFai(ppsHdrFai, vTexCoords).rgb;
  81. fColor += hdr;
  82. #endif
  83. #if defined(SSAO_ENABLED)
  84. float ssao = textureFai(ppsSsaoFai, vTexCoords).r;
  85. fColor *= ssao;
  86. #endif
  87. #if defined(LF_ENABLED)
  88. vec3 lf = textureFai(ppsLfFai, vTexCoords).rgb;
  89. fColor += lf;
  90. #endif
  91. #ifdef GAMMA_CORRECTION_ENABLED
  92. //fColor = BlendHardLight(vec3(0.7, 0.72, 0.4), fColor);
  93. fColor = gammaCorrectionRgb(vec3(0.9, 0.92, 0.75), fColor);
  94. #endif
  95. #if 0
  96. if(fColor.r != 0.00000001)
  97. {
  98. fColor = vec3(ssao);
  99. }
  100. #endif
  101. #if 0
  102. if(fColor.r != 0.00000001)
  103. {
  104. fColor = hdr;
  105. }
  106. #endif
  107. }