| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "servers/rendering/renderer_rd/pipeline_cache_rd.h" |
| 34 |
#include "servers/rendering/renderer_rd/shaders/effects/tonemap.glsl.gen.h" |
| 35 |
#include "servers/rendering/renderer_rd/shaders/effects/tonemap_mobile.glsl.gen.h" |
| 36 |
|
| 37 |
#include "servers/rendering/rendering_server.h" |
| 38 |
|
| 39 |
namespace RendererRD { |
| 40 |
|
| 41 |
class ToneMapper { |
| 42 |
private: |
| 43 |
bool using_mobile_version = false; |
| 44 |
enum TonemapMode { |
| 45 |
TONEMAP_MODE_NORMAL, |
| 46 |
TONEMAP_MODE_BICUBIC_GLOW_FILTER, |
| 47 |
TONEMAP_MODE_1D_LUT, |
| 48 |
TONEMAP_MODE_BICUBIC_GLOW_FILTER_1D_LUT, |
| 49 |
|
| 50 |
TONEMAP_MODE_NORMAL_MULTIVIEW, |
| 51 |
TONEMAP_MODE_BICUBIC_GLOW_FILTER_MULTIVIEW, |
| 52 |
TONEMAP_MODE_1D_LUT_MULTIVIEW, |
| 53 |
TONEMAP_MODE_BICUBIC_GLOW_FILTER_1D_LUT_MULTIVIEW, |
| 54 |
|
| 55 |
TONEMAP_MODE_MAX |
| 56 |
}; |
| 57 |
|
| 58 |
enum TonemapModeMobile { |
| 59 |
TONEMAP_MOBILE_MODE_NORMAL, |
| 60 |
TONEMAP_MOBILE_MODE_1D_LUT, |
| 61 |
TONEMAP_MOBILE_MODE_SUBPASS, |
| 62 |
TONEMAP_MOBILE_MODE_SUBPASS_1D_LUT, |
| 63 |
|
| 64 |
TONEMAP_MOBILE_MODE_NORMAL_MULTIVIEW, |
| 65 |
TONEMAP_MOBILE_MODE_1D_LUT_MULTIVIEW, |
| 66 |
TONEMAP_MOBILE_MODE_SUBPASS_MULTIVIEW, |
| 67 |
TONEMAP_MOBILE_MODE_SUBPASS_1D_LUT_MULTIVIEW, |
| 68 |
|
| 69 |
TONEMAP_MOBILE_MODE_MAX |
| 70 |
}; |
| 71 |
|
| 72 |
enum Flags { |
| 73 |
TONEMAP_FLAG_USE_BCS = (1 << 0), |
| 74 |
TONEMAP_FLAG_USE_GLOW = (1 << 1), |
| 75 |
TONEMAP_FLAG_USE_AUTO_EXPOSURE = (1 << 2), |
| 76 |
TONEMAP_FLAG_USE_COLOR_CORRECTION = (1 << 3), |
| 77 |
TONEMAP_FLAG_USE_FXAA = (1 << 4), |
| 78 |
TONEMAP_FLAG_USE_8_BIT_DEBANDING = (1 << 5), |
| 79 |
TONEMAP_FLAG_CONVERT_TO_SRGB = (1 << 6), |
| 80 |
}; |
| 81 |
|
| 82 |
enum FlagsMobile { |
| 83 |
TONEMAP_MOBILE_FLAG_USE_BCS = (1 << 0), |
| 84 |
TONEMAP_MOBILE_FLAG_USE_GLOW = (1 << 1), |
| 85 |
TONEMAP_MOBILE_FLAG_USE_GLOW_MAP = (1 << 2), |
| 86 |
TONEMAP_MOBILE_FLAG_USE_COLOR_CORRECTION = (1 << 3), |
| 87 |
TONEMAP_MOBILE_FLAG_USE_FXAA = (1 << 4), |
| 88 |
TONEMAP_MOBILE_FLAG_USE_8_BIT_DEBANDING = (1 << 5), |
| 89 |
TONEMAP_MOBILE_FLAG_USE_10_BIT_DEBANDING = (1 << 6), |
| 90 |
TONEMAP_MOBILE_FLAG_CONVERT_TO_SRGB = (1 << 7), |
| 91 |
|
| 92 |
TONEMAP_MOBILE_FLAG_TONEMAPPER_LINEAR = (1 << 8), |
| 93 |
TONEMAP_MOBILE_FLAG_TONEMAPPER_REINHARD = (1 << 9), |
| 94 |
TONEMAP_MOBILE_FLAG_TONEMAPPER_FILMIC = (1 << 10), |
| 95 |
TONEMAP_MOBILE_FLAG_TONEMAPPER_ACES = (1 << 11), |
| 96 |
TONEMAP_MOBILE_FLAG_TONEMAPPER_AGX = (1 << 12), |
| 97 |
|
| 98 |
TONEMAP_MOBILE_FLAG_GLOW_MODE_ADD = (1 << 13), |
| 99 |
TONEMAP_MOBILE_FLAG_GLOW_MODE_SCREEN = (1 << 14), |
| 100 |
TONEMAP_MOBILE_FLAG_GLOW_MODE_SOFTLIGHT = (1 << 15), |
| 101 |
TONEMAP_MOBILE_FLAG_GLOW_MODE_REPLACE = (1 << 16), |
| 102 |
TONEMAP_MOBILE_FLAG_GLOW_MODE_MIX = (1 << 17), |
| 103 |
TONEMAP_MOBILE_ADRENO_BUG = (1 << 18), |
| 104 |
}; |
| 105 |
|
| 106 |
struct TonemapPushConstant { |
| 107 |
float bcs[3]; |
| 108 |
uint32_t flags; |
| 109 |
|
| 110 |
float pixel_size[2]; |
| 111 |
uint32_t tonemapper; |
| 112 |
uint32_t pad; |
| 113 |
|
| 114 |
uint32_t glow_texture_size[2]; |
| 115 |
float glow_intensity; |
| 116 |
float glow_map_strength; |
| 117 |
|
| 118 |
uint32_t glow_mode; |
| 119 |
float glow_levels[7]; |
| 120 |
|
| 121 |
float exposure; |
| 122 |
float white; |
| 123 |
float auto_exposure_scale; |
| 124 |
float luminance_multiplier; |
| 125 |
|
| 126 |
float tonemapper_params[4]; |
| 127 |
}; |
| 128 |
|
| 129 |
struct TonemapPushConstantMobile { |
| 130 |
float bcs[3]; |
| 131 |
float luminance_multiplier; |
| 132 |
|
| 133 |
float src_pixel_size[2]; |
| 134 |
float dest_pixel_size[2]; |
| 135 |
|
| 136 |
float glow_intensity; |
| 137 |
float glow_map_strength; |
| 138 |
float exposure; |
| 139 |
float white; |
| 140 |
|
| 141 |
float tonemapper_params[4]; |
| 142 |
}; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
struct Tonemap { |
| 149 |
TonemapPushConstant push_constant; |
| 150 |
TonemapShaderRD shader; |
| 151 |
RID shader_version; |
| 152 |
PipelineCacheRD pipelines[TONEMAP_MODE_MAX]; |
| 153 |
} tonemap; |
| 154 |
|
| 155 |
struct TonemapMobile { |
| 156 |
TonemapPushConstantMobile push_constant; |
| 157 |
TonemapMobileShaderRD shader; |
| 158 |
RID shader_version; |
| 159 |
PipelineCacheRD pipelines[TONEMAP_MOBILE_MODE_MAX]; |
| 160 |
} tonemap_mobile; |
| 161 |
|
| 162 |
public: |
| 163 |
ToneMapper(bool p_use_mobile_version); |
| 164 |
~ToneMapper(); |
| 165 |
|
| 166 |
struct TonemapSettings { |
| 167 |
bool use_glow = false; |
| 168 |
RS::EnvironmentGlowBlendMode glow_mode = RS::ENV_GLOW_BLEND_MODE_SCREEN; |
| 169 |
float glow_intensity = 0.3; |
| 170 |
float glow_map_strength = 0.0f; |
| 171 |
float glow_levels[7] = { 1.0, 0.8, 0.4, 0.1, 0.0, 0.0, 0.0 }; |
| 172 |
Vector2i glow_texture_size; |
| 173 |
bool glow_use_bicubic_upscale = false; |
| 174 |
RID glow_texture; |
| 175 |
RID glow_map; |
| 176 |
|
| 177 |
RS::EnvironmentToneMapper tonemap_mode = RS::ENV_TONE_MAPPER_LINEAR; |
| 178 |
float tonemapper_params[4] = { 0.0, 0.0, 0.0, 0.0 }; |
| 179 |
float exposure = 1.0; |
| 180 |
float white = 1.0; |
| 181 |
|
| 182 |
bool use_auto_exposure = false; |
| 183 |
float auto_exposure_scale = 0.5; |
| 184 |
RID exposure_texture; |
| 185 |
float luminance_multiplier = 1.0; |
| 186 |
|
| 187 |
bool use_bcs = false; |
| 188 |
float brightness = 1.0; |
| 189 |
float contrast = 1.0; |
| 190 |
float saturation = 1.0; |
| 191 |
|
| 192 |
bool use_color_correction = false; |
| 193 |
bool use_1d_color_correction = false; |
| 194 |
RID color_correction_texture; |
| 195 |
|
| 196 |
bool use_fxaa = false; |
| 197 |
enum DebandingMode { |
| 198 |
DEBANDING_MODE_DISABLED, |
| 199 |
DEBANDING_MODE_8_BIT, |
| 200 |
DEBANDING_MODE_10_BIT, |
| 201 |
}; |
| 202 |
DebandingMode debanding_mode = DEBANDING_MODE_DISABLED; |
| 203 |
Vector2i texture_size; |
| 204 |
Vector2i dest_texture_size; |
| 205 |
uint32_t view_count = 1; |
| 206 |
|
| 207 |
bool convert_to_srgb = false; |
| 208 |
}; |
| 209 |
|
| 210 |
void tonemapper(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings); |
| 211 |
void tonemapper_mobile(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings); |
| 212 |
void tonemapper_subpass(RD::DrawListID p_subpass_draw_list, RID p_source_color, RD::FramebufferFormatID p_dst_format_id, const TonemapSettings &p_settings); |
| 213 |
}; |
| 214 |
|
| 215 |
} |