luminance.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**************************************************************************/
  2. /* luminance.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef LUMINANCE_RD_H
  31. #define LUMINANCE_RD_H
  32. #include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
  33. #include "servers/rendering/renderer_rd/shaders/effects/luminance_reduce.glsl.gen.h"
  34. #include "servers/rendering/renderer_rd/shaders/effects/luminance_reduce_raster.glsl.gen.h"
  35. #include "servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h"
  36. #define RB_LUMINANCE_BUFFERS SNAME("luminance_buffers")
  37. namespace RendererRD {
  38. class Luminance {
  39. private:
  40. bool prefer_raster_effects;
  41. enum LuminanceReduceMode {
  42. LUMINANCE_REDUCE_READ,
  43. LUMINANCE_REDUCE,
  44. LUMINANCE_REDUCE_WRITE,
  45. LUMINANCE_REDUCE_MAX
  46. };
  47. struct LuminanceReducePushConstant {
  48. int32_t source_size[2];
  49. float max_luminance;
  50. float min_luminance;
  51. float exposure_adjust;
  52. float pad[3];
  53. };
  54. struct LuminanceReduce {
  55. LuminanceReduceShaderRD shader;
  56. RID shader_version;
  57. RID pipelines[LUMINANCE_REDUCE_MAX];
  58. } luminance_reduce;
  59. enum LuminanceReduceRasterMode {
  60. LUMINANCE_REDUCE_FRAGMENT_FIRST,
  61. LUMINANCE_REDUCE_FRAGMENT,
  62. LUMINANCE_REDUCE_FRAGMENT_FINAL,
  63. LUMINANCE_REDUCE_FRAGMENT_MAX
  64. };
  65. struct LuminanceReduceRasterPushConstant {
  66. int32_t source_size[2];
  67. int32_t dest_size[2];
  68. float exposure_adjust;
  69. float min_luminance;
  70. float max_luminance;
  71. uint32_t pad1;
  72. };
  73. struct LuminanceReduceFragment {
  74. LuminanceReduceRasterShaderRD shader;
  75. RID shader_version;
  76. PipelineCacheRD pipelines[LUMINANCE_REDUCE_FRAGMENT_MAX];
  77. } luminance_reduce_raster;
  78. public:
  79. class LuminanceBuffers : public RenderBufferCustomDataRD {
  80. GDCLASS(LuminanceBuffers, RenderBufferCustomDataRD);
  81. private:
  82. bool prefer_raster_effects;
  83. public:
  84. Vector<RID> reduce;
  85. RID current;
  86. virtual void configure(RenderSceneBuffersRD *p_render_buffers) override;
  87. virtual void free_data() override;
  88. void set_prefer_raster_effects(bool p_prefer_raster_effects);
  89. };
  90. Ref<LuminanceBuffers> get_luminance_buffers(Ref<RenderSceneBuffersRD> p_render_buffers);
  91. RID get_current_luminance_buffer(Ref<RenderSceneBuffersRD> p_render_buffers);
  92. void luminance_reduction(RID p_source_texture, const Size2i p_source_size, Ref<LuminanceBuffers> p_luminance_buffers, float p_min_luminance, float p_max_luminance, float p_adjust, bool p_set = false);
  93. Luminance(bool p_prefer_raster_effects);
  94. ~Luminance();
  95. };
  96. } // namespace RendererRD
  97. #endif // LUMINANCE_RD_H