BsPostProcessing.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsRenderBeastPrerequisites.h"
  5. #include "BsRendererMaterial.h"
  6. #include "BsParamBlocks.h"
  7. #include "BsRenderTexturePool.h"
  8. namespace BansheeEngine
  9. {
  10. /** @addtogroup RenderBeast
  11. * @{
  12. */
  13. /** Settings that control the post-process operation. */
  14. struct PostProcessSettings
  15. {
  16. /**
  17. * Determines minimum luminance value in the eye adaptation histogram. In log2 units (-8 = 1/256). In the range
  18. * [-16, 0].
  19. */
  20. float histogramLog2Min = -8.0f;
  21. /**
  22. * Determines maximum luminance value in the eye adaptation histogram. In log2 units (4 = 16). In the range
  23. * [0, 16].
  24. */
  25. float histogramLog2Max = 4.0f;
  26. };
  27. /** Contains per-camera data used by post process effects. */
  28. struct PostProcessInfo
  29. {
  30. PostProcessSettings settings;
  31. SPtr<PooledRenderTexture> downsampledSceneTex;
  32. SPtr<PooledRenderTexture> histogramTex;
  33. SPtr<PooledRenderTexture> eyeAdaptationTex;
  34. };
  35. BS_PARAM_BLOCK_BEGIN(DownsampleParams)
  36. BS_PARAM_BLOCK_ENTRY(Vector2, gInvTexSize)
  37. BS_PARAM_BLOCK_END
  38. /** Shader that downsamples a texture to half its size. */
  39. class DownsampleMat : public RendererMaterial<DownsampleMat>
  40. {
  41. RMAT_DEF("PPDownsample.bsl");
  42. public:
  43. DownsampleMat();
  44. /** Updates the parameter buffers used by the material. */
  45. void setParameters(const SPtr<RenderTextureCore>& target);
  46. /** Renders the post-process effect on the provided target. */
  47. void render(const SPtr<RenderTextureCore>& target, PostProcessInfo& ppInfo);
  48. private:
  49. DownsampleParams mParams;
  50. MaterialParamVec2Core mInvTexSize;
  51. MaterialParamTextureCore mInputTexture;
  52. POOLED_RENDER_TEXTURE_DESC mOutputDesc;
  53. };
  54. BS_PARAM_BLOCK_BEGIN(EyeAdaptHistogramParams)
  55. BS_PARAM_BLOCK_ENTRY(Vector4I, gPixelOffsetAndSize)
  56. BS_PARAM_BLOCK_ENTRY(Vector2, gHistogramParams)
  57. BS_PARAM_BLOCK_ENTRY(Vector2I, gThreadGroupCount)
  58. BS_PARAM_BLOCK_END
  59. /** Shader that creates a luminance histogram used for eye adaptation. */
  60. class EyeAdaptHistogramMat : public RendererMaterial<EyeAdaptHistogramMat>
  61. {
  62. RMAT_DEF("PPEyeAdaptHistogram.bsl");
  63. public:
  64. EyeAdaptHistogramMat();
  65. /** Updates the parameter buffers used by the material. */
  66. void setParameters(const SPtr<RenderTextureCore>& target, PostProcessInfo& ppInfo);
  67. private:
  68. EyeAdaptHistogramParams mParams;
  69. MaterialParamTextureCore mSceneColor;
  70. MaterialParamLoadStoreTextureCore mOutputTex;
  71. static const INT32 THREAD_GROUP_SIZE_X = 4;
  72. static const INT32 THREAD_GROUP_SIZE_Y = 4;
  73. static const INT32 LOOP_COUNT_X = 8;
  74. static const INT32 LOOP_COUNT_Y = 8;
  75. };
  76. /**
  77. * Renders post-processing effects for the provided render target.
  78. *
  79. * @note Core thread only.
  80. */
  81. class BS_BSRND_EXPORT PostProcessing
  82. {
  83. public:
  84. /** Renders post-processing effects for the provided render target. */
  85. static void postProcess(const SPtr<RenderTextureCore>& target, PostProcessInfo& ppInfo);
  86. private:
  87. };
  88. /** @} */
  89. }