PPEyeAdaptHistogramReduce.bsl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "$ENGINE$\PPBase.bslinc"
  2. Parameters =
  3. {
  4. Texture2D gHistogramTex;
  5. Texture2D gEyeAdaptationTex;
  6. };
  7. Blocks =
  8. {
  9. Block Input;
  10. };
  11. Technique : inherits("PPBase") =
  12. {
  13. Language = "HLSL11";
  14. Pass =
  15. {
  16. Fragment =
  17. {
  18. cbuffer Input
  19. {
  20. uint gThreadGroupCount;
  21. }
  22. Texture2D gHistogramTex;
  23. Texture2D gEyeAdaptationTex;
  24. float4 main(VStoFS input) : SV_Target0
  25. {
  26. int2 iUV = trunc(input.uv0);
  27. float4 outputValue = 0.0f;
  28. // Output texture only has two rows, store histogram on the first
  29. if(input.uv0.y < 1.0f)
  30. {
  31. // TODO - Potentially optimize using bilinear filtering
  32. for(uint i = 0; i < gThreadGroupCount; i++)
  33. outputValue += gHistogramTex.Load(int3(iUV.x, i, 0));
  34. return outputValue / gThreadGroupCount;
  35. }
  36. else
  37. {
  38. // Store eye adaptation from last frame in the second row of the texture
  39. return gEyeAdaptationTex.Load(int3(0, 0, 0)).x;
  40. }
  41. }
  42. };
  43. };
  44. };
  45. Technique : inherits("PPBase") =
  46. {
  47. Language = "GLSL";
  48. Pass =
  49. {
  50. Fragment =
  51. {
  52. in VStoFS
  53. {
  54. vec2 uv0;
  55. } input;
  56. uniform Input
  57. {
  58. uint gThreadGroupCount;
  59. };
  60. uniform sampler2D gHistogramTex;
  61. uniform sampler2D gEyeAdaptationTex;
  62. out vec4 fragColor;
  63. void main()
  64. {
  65. ivec2 iUV = ivec2(trunc(input.uv0));
  66. vec4 outputValue = vec4(0.0f);
  67. // Output texture only has two rows, store histogram on the first
  68. if(input.uv0.y < 1.0f)
  69. {
  70. // TODO - Potentially optimize using bilinear filtering
  71. for(uint i = 0; i < gThreadGroupCount; i++)
  72. outputValue += texelFetch(gHistogramTex, ivec2(iUV.x, i), 0);
  73. fragColor = outputValue / gThreadGroupCount;
  74. }
  75. else
  76. {
  77. // Store eye adaptation from last frame in the second row of the texture
  78. fragColor = texelFetch(gEyeAdaptationTex, ivec2(0, 0), 0).xxxx;
  79. }
  80. }
  81. };
  82. };
  83. };