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
10279 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
36
#include "servers/rendering_server.h"
37
38
namespace RendererRD {
39
40
class ToneMapper {
41
private:
42
enum TonemapMode {
43
TONEMAP_MODE_NORMAL,
44
TONEMAP_MODE_BICUBIC_GLOW_FILTER,
45
TONEMAP_MODE_1D_LUT,
46
TONEMAP_MODE_BICUBIC_GLOW_FILTER_1D_LUT,
47
TONEMAP_MODE_SUBPASS,
48
TONEMAP_MODE_SUBPASS_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
TONEMAP_MODE_SUBPASS_MULTIVIEW,
55
TONEMAP_MODE_SUBPASS_1D_LUT_MULTIVIEW,
56
57
TONEMAP_MODE_MAX
58
};
59
60
enum {
61
TONEMAP_FLAG_USE_BCS = (1 << 0),
62
TONEMAP_FLAG_USE_GLOW = (1 << 1),
63
TONEMAP_FLAG_USE_AUTO_EXPOSURE = (1 << 2),
64
TONEMAP_FLAG_USE_COLOR_CORRECTION = (1 << 3),
65
TONEMAP_FLAG_USE_FXAA = (1 << 4),
66
TONEMAP_FLAG_USE_8_BIT_DEBANDING = (1 << 5),
67
TONEMAP_FLAG_USE_10_BIT_DEBANDING = (1 << 6),
68
TONEMAP_FLAG_CONVERT_TO_SRGB = (1 << 7),
69
};
70
71
struct TonemapPushConstant {
72
float bcs[3]; // 12 - 12
73
uint32_t flags; // 4 - 16
74
75
float pixel_size[2]; // 8 - 24
76
uint32_t tonemapper; // 4 - 28
77
uint32_t pad; // 4 - 32
78
79
uint32_t glow_texture_size[2]; // 8 - 40
80
float glow_intensity; // 4 - 44
81
float glow_map_strength; // 4 - 48
82
83
uint32_t glow_mode; // 4 - 52
84
float glow_levels[7]; // 28 - 80
85
86
float exposure; // 4 - 84
87
float white; // 4 - 88
88
float auto_exposure_scale; // 4 - 92
89
float luminance_multiplier; // 4 - 96
90
};
91
92
/* tonemap actually writes to a framebuffer, which is
93
* better to do using the raster pipeline rather than
94
* compute, as that framebuffer might be in different formats
95
*/
96
struct Tonemap {
97
TonemapPushConstant push_constant;
98
TonemapShaderRD shader;
99
RID shader_version;
100
PipelineCacheRD pipelines[TONEMAP_MODE_MAX];
101
} tonemap;
102
103
public:
104
ToneMapper();
105
~ToneMapper();
106
107
struct TonemapSettings {
108
bool use_glow = false;
109
enum GlowMode {
110
GLOW_MODE_ADD,
111
GLOW_MODE_SCREEN,
112
GLOW_MODE_SOFTLIGHT,
113
GLOW_MODE_REPLACE,
114
GLOW_MODE_MIX
115
};
116
117
GlowMode glow_mode = GLOW_MODE_ADD;
118
float glow_intensity = 1.0;
119
float glow_map_strength = 0.0f;
120
float glow_levels[7] = { 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0 };
121
Vector2i glow_texture_size;
122
bool glow_use_bicubic_upscale = false;
123
RID glow_texture;
124
RID glow_map;
125
126
RS::EnvironmentToneMapper tonemap_mode = RS::ENV_TONE_MAPPER_LINEAR;
127
float exposure = 1.0;
128
float white = 1.0;
129
130
bool use_auto_exposure = false;
131
float auto_exposure_scale = 0.5;
132
RID exposure_texture;
133
float luminance_multiplier = 1.0;
134
135
bool use_bcs = false;
136
float brightness = 1.0;
137
float contrast = 1.0;
138
float saturation = 1.0;
139
140
bool use_color_correction = false;
141
bool use_1d_color_correction = false;
142
RID color_correction_texture;
143
144
bool use_fxaa = false;
145
enum DebandingMode {
146
DEBANDING_MODE_DISABLED,
147
DEBANDING_MODE_8_BIT,
148
DEBANDING_MODE_10_BIT,
149
};
150
DebandingMode debanding_mode = DEBANDING_MODE_DISABLED;
151
Vector2i texture_size;
152
uint32_t view_count = 1;
153
154
bool convert_to_srgb = false;
155
};
156
157
void tonemapper(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings);
158
void tonemapper(RD::DrawListID p_subpass_draw_list, RID p_source_color, RD::FramebufferFormatID p_dst_format_id, const TonemapSettings &p_settings);
159
};
160
161
} // namespace RendererRD
162
163