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