tone_mapper.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /**************************************************************************/
  2. /* tone_mapper.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 TONE_MAPPER_RD_H
  31. #define TONE_MAPPER_RD_H
  32. #include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
  33. #include "servers/rendering/renderer_rd/shaders/effects/tonemap.glsl.gen.h"
  34. #include "servers/rendering/renderer_scene_render.h"
  35. #include "servers/rendering_server.h"
  36. namespace RendererRD {
  37. class ToneMapper {
  38. private:
  39. enum TonemapMode {
  40. TONEMAP_MODE_NORMAL,
  41. TONEMAP_MODE_BICUBIC_GLOW_FILTER,
  42. TONEMAP_MODE_1D_LUT,
  43. TONEMAP_MODE_BICUBIC_GLOW_FILTER_1D_LUT,
  44. TONEMAP_MODE_SUBPASS,
  45. TONEMAP_MODE_SUBPASS_1D_LUT,
  46. TONEMAP_MODE_NORMAL_MULTIVIEW,
  47. TONEMAP_MODE_BICUBIC_GLOW_FILTER_MULTIVIEW,
  48. TONEMAP_MODE_1D_LUT_MULTIVIEW,
  49. TONEMAP_MODE_BICUBIC_GLOW_FILTER_1D_LUT_MULTIVIEW,
  50. TONEMAP_MODE_SUBPASS_MULTIVIEW,
  51. TONEMAP_MODE_SUBPASS_1D_LUT_MULTIVIEW,
  52. TONEMAP_MODE_MAX
  53. };
  54. enum {
  55. TONEMAP_FLAG_USE_BCS = (1 << 0),
  56. TONEMAP_FLAG_USE_GLOW = (1 << 1),
  57. TONEMAP_FLAG_USE_AUTO_EXPOSURE = (1 << 2),
  58. TONEMAP_FLAG_USE_COLOR_CORRECTION = (1 << 3),
  59. TONEMAP_FLAG_USE_FXAA = (1 << 4),
  60. TONEMAP_FLAG_USE_DEBANDING = (1 << 5),
  61. TONEMAP_FLAG_CONVERT_TO_SRGB = (1 << 6),
  62. };
  63. struct TonemapPushConstant {
  64. float bcs[3]; // 12 - 12
  65. uint32_t flags; // 4 - 16
  66. float pixel_size[2]; // 8 - 24
  67. uint32_t tonemapper; // 4 - 28
  68. uint32_t pad; // 4 - 32
  69. uint32_t glow_texture_size[2]; // 8 - 40
  70. float glow_intensity; // 4 - 44
  71. float glow_map_strength; // 4 - 48
  72. uint32_t glow_mode; // 4 - 52
  73. float glow_levels[7]; // 28 - 80
  74. float exposure; // 4 - 84
  75. float white; // 4 - 88
  76. float auto_exposure_scale; // 4 - 92
  77. float luminance_multiplier; // 4 - 96
  78. };
  79. /* tonemap actually writes to a framebuffer, which is
  80. * better to do using the raster pipeline rather than
  81. * compute, as that framebuffer might be in different formats
  82. */
  83. struct Tonemap {
  84. TonemapPushConstant push_constant;
  85. TonemapShaderRD shader;
  86. RID shader_version;
  87. PipelineCacheRD pipelines[TONEMAP_MODE_MAX];
  88. } tonemap;
  89. public:
  90. ToneMapper();
  91. ~ToneMapper();
  92. struct TonemapSettings {
  93. bool use_glow = false;
  94. enum GlowMode {
  95. GLOW_MODE_ADD,
  96. GLOW_MODE_SCREEN,
  97. GLOW_MODE_SOFTLIGHT,
  98. GLOW_MODE_REPLACE,
  99. GLOW_MODE_MIX
  100. };
  101. GlowMode glow_mode = GLOW_MODE_ADD;
  102. float glow_intensity = 1.0;
  103. float glow_map_strength = 0.0f;
  104. float glow_levels[7] = { 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0 };
  105. Vector2i glow_texture_size;
  106. bool glow_use_bicubic_upscale = false;
  107. RID glow_texture;
  108. RID glow_map;
  109. RS::EnvironmentToneMapper tonemap_mode = RS::ENV_TONE_MAPPER_LINEAR;
  110. float exposure = 1.0;
  111. float white = 1.0;
  112. bool use_auto_exposure = false;
  113. float auto_exposure_scale = 0.5;
  114. RID exposure_texture;
  115. float luminance_multiplier = 1.0;
  116. bool use_bcs = false;
  117. float brightness = 1.0;
  118. float contrast = 1.0;
  119. float saturation = 1.0;
  120. bool use_color_correction = false;
  121. bool use_1d_color_correction = false;
  122. RID color_correction_texture;
  123. bool use_fxaa = false;
  124. bool use_debanding = false;
  125. Vector2i texture_size;
  126. uint32_t view_count = 1;
  127. bool convert_to_srgb = false;
  128. };
  129. void tonemapper(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings);
  130. void tonemapper(RD::DrawListID p_subpass_draw_list, RID p_source_color, RD::FramebufferFormatID p_dst_format_id, const TonemapSettings &p_settings);
  131. };
  132. } // namespace RendererRD
  133. #endif // TONE_MAPPER_RD_H