luminance.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #include "servers/rendering/renderer_scene_render.h"
  37. #include "servers/rendering_server.h"
  38. #define RB_LUMINANCE_BUFFERS SNAME("luminance_buffers")
  39. namespace RendererRD {
  40. class Luminance {
  41. private:
  42. bool prefer_raster_effects;
  43. enum LuminanceReduceMode {
  44. LUMINANCE_REDUCE_READ,
  45. LUMINANCE_REDUCE,
  46. LUMINANCE_REDUCE_WRITE,
  47. LUMINANCE_REDUCE_MAX
  48. };
  49. struct LuminanceReducePushConstant {
  50. int32_t source_size[2];
  51. float max_luminance;
  52. float min_luminance;
  53. float exposure_adjust;
  54. float pad[3];
  55. };
  56. struct LuminanceReduce {
  57. LuminanceReduceShaderRD shader;
  58. RID shader_version;
  59. RID pipelines[LUMINANCE_REDUCE_MAX];
  60. } luminance_reduce;
  61. enum LuminanceReduceRasterMode {
  62. LUMINANCE_REDUCE_FRAGMENT_FIRST,
  63. LUMINANCE_REDUCE_FRAGMENT,
  64. LUMINANCE_REDUCE_FRAGMENT_FINAL,
  65. LUMINANCE_REDUCE_FRAGMENT_MAX
  66. };
  67. struct LuminanceReduceRasterPushConstant {
  68. int32_t source_size[2];
  69. int32_t dest_size[2];
  70. float exposure_adjust;
  71. float min_luminance;
  72. float max_luminance;
  73. uint32_t pad1;
  74. };
  75. struct LuminanceReduceFragment {
  76. LuminanceReduceRasterShaderRD shader;
  77. RID shader_version;
  78. PipelineCacheRD pipelines[LUMINANCE_REDUCE_FRAGMENT_MAX];
  79. } luminance_reduce_raster;
  80. public:
  81. class LuminanceBuffers : public RenderBufferCustomDataRD {
  82. GDCLASS(LuminanceBuffers, RenderBufferCustomDataRD);
  83. private:
  84. bool prefer_raster_effects;
  85. public:
  86. Vector<RID> reduce;
  87. RID current;
  88. virtual void configure(RenderSceneBuffersRD *p_render_buffers) override;
  89. virtual void free_data() override;
  90. void set_prefer_raster_effects(bool p_prefer_raster_effects);
  91. };
  92. Ref<LuminanceBuffers> get_luminance_buffers(Ref<RenderSceneBuffersRD> p_render_buffers);
  93. RID get_current_luminance_buffer(Ref<RenderSceneBuffersRD> p_render_buffers);
  94. 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);
  95. Luminance(bool p_prefer_raster_effects);
  96. ~Luminance();
  97. };
  98. } // namespace RendererRD
  99. #endif // LUMINANCE_RD_H