Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/renderer_rd/effects/tone_mapper.h
21372 views
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
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), // Needs to be last so we force the pipeline cache to specify specializations for all variants.
104
};
105
106
struct TonemapPushConstant {
107
float bcs[3]; // 12 - 12
108
uint32_t flags; // 4 - 16
109
110
float pixel_size[2]; // 8 - 24
111
uint32_t tonemapper; // 4 - 28
112
uint32_t pad; // 4 - 32
113
114
uint32_t glow_texture_size[2]; // 8 - 40
115
float glow_intensity; // 4 - 44
116
float glow_map_strength; // 4 - 48
117
118
uint32_t glow_mode; // 4 - 52
119
float glow_levels[7]; // 28 - 80
120
121
float exposure; // 4 - 84
122
float white; // 4 - 88
123
float auto_exposure_scale; // 4 - 92
124
float luminance_multiplier; // 4 - 96
125
126
float tonemapper_params[4]; // 16 - 112
127
};
128
129
struct TonemapPushConstantMobile {
130
float bcs[3]; // 12 - 12
131
float luminance_multiplier; // 4 - 16
132
133
float src_pixel_size[2]; // 8 - 24
134
float dest_pixel_size[2]; // 8 - 32
135
136
float glow_intensity; // 4 - 36
137
float glow_map_strength; // 4 - 40
138
float exposure; // 4 - 44
139
float white; // 4 - 48
140
141
float tonemapper_params[4]; // 16 - 64
142
};
143
144
/* tonemap actually writes to a framebuffer, which is
145
* better to do using the raster pipeline rather than
146
* compute, as that framebuffer might be in different formats
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
} // namespace RendererRD
216
217