Skip to content
0.2.0-dev Download ZIP
114 lines ·4.4 KB Raw
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
31#pragma once
32
33#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
34#include "servers/rendering/renderer_rd/shaders/effects/luminance_reduce.glsl.gen.h"
35#include "servers/rendering/renderer_rd/shaders/effects/luminance_reduce_raster.glsl.gen.h"
36#include "servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h"
37
38#define RB_LUMINANCE_BUFFERS SNAME("luminance_buffers")
39
40namespace RendererRD {
41
42class Luminance {
43private:
44 bool prefer_raster_effects;
45
46 enum LuminanceReduceMode {
47 LUMINANCE_REDUCE_READ,
48 LUMINANCE_REDUCE,
49 LUMINANCE_REDUCE_WRITE,
50 LUMINANCE_REDUCE_MAX
51 };
52
53 struct LuminanceReducePushConstant {
54 int32_t source_size[2];
55 float max_luminance;
56 float min_luminance;
57 float exposure_adjust;
58 float pad[3];
59 };
60
61 struct LuminanceReduce {
62 LuminanceReduceShaderRD shader;
63 RID shader_version;
64 RID pipelines[LUMINANCE_REDUCE_MAX];
65 } luminance_reduce;
66
67 enum LuminanceReduceRasterMode {
68 LUMINANCE_REDUCE_FRAGMENT_FIRST,
69 LUMINANCE_REDUCE_FRAGMENT,
70 LUMINANCE_REDUCE_FRAGMENT_FINAL,
71 LUMINANCE_REDUCE_FRAGMENT_MAX
72 };
73
74 struct LuminanceReduceRasterPushConstant {
75 int32_t source_size[2];
76 int32_t dest_size[2];
77 float exposure_adjust;
78 float min_luminance;
79 float max_luminance;
80 uint32_t pad1;
81 };
82
83 struct LuminanceReduceFragment {
84 LuminanceReduceRasterShaderRD shader;
85 RID shader_version;
86 PipelineCacheRD pipelines[LUMINANCE_REDUCE_FRAGMENT_MAX];
87 } luminance_reduce_raster;
88
89public:
90 class LuminanceBuffers : public RenderBufferCustomDataRD {
91 GDCLASS(LuminanceBuffers, RenderBufferCustomDataRD);
92
93 private:
94 bool prefer_raster_effects;
95
96 public:
97 Vector<RID> reduce;
98 RID current;
99
100 virtual void configure(RenderSceneBuffersRD *p_render_buffers) override;
101 virtual void free_data() override;
102
103 void set_prefer_raster_effects(bool p_prefer_raster_effects);
104 };
105
106 Ref<LuminanceBuffers> get_luminance_buffers(Ref<RenderSceneBuffersRD> p_render_buffers);
107 RID get_current_luminance_buffer(Ref<RenderSceneBuffersRD> p_render_buffers);
108 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);
109
110 Luminance(bool p_prefer_raster_effects);
111 ~Luminance();
112};
113
114} // namespace RendererRD