Path: blob/master/servers/rendering/renderer_rd/effects/tone_mapper.h
10279 views
/**************************************************************************/1/* tone_mapper.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"33#include "servers/rendering/renderer_rd/shaders/effects/tonemap.glsl.gen.h"3435#include "servers/rendering_server.h"3637namespace RendererRD {3839class ToneMapper {40private:41enum TonemapMode {42TONEMAP_MODE_NORMAL,43TONEMAP_MODE_BICUBIC_GLOW_FILTER,44TONEMAP_MODE_1D_LUT,45TONEMAP_MODE_BICUBIC_GLOW_FILTER_1D_LUT,46TONEMAP_MODE_SUBPASS,47TONEMAP_MODE_SUBPASS_1D_LUT,4849TONEMAP_MODE_NORMAL_MULTIVIEW,50TONEMAP_MODE_BICUBIC_GLOW_FILTER_MULTIVIEW,51TONEMAP_MODE_1D_LUT_MULTIVIEW,52TONEMAP_MODE_BICUBIC_GLOW_FILTER_1D_LUT_MULTIVIEW,53TONEMAP_MODE_SUBPASS_MULTIVIEW,54TONEMAP_MODE_SUBPASS_1D_LUT_MULTIVIEW,5556TONEMAP_MODE_MAX57};5859enum {60TONEMAP_FLAG_USE_BCS = (1 << 0),61TONEMAP_FLAG_USE_GLOW = (1 << 1),62TONEMAP_FLAG_USE_AUTO_EXPOSURE = (1 << 2),63TONEMAP_FLAG_USE_COLOR_CORRECTION = (1 << 3),64TONEMAP_FLAG_USE_FXAA = (1 << 4),65TONEMAP_FLAG_USE_8_BIT_DEBANDING = (1 << 5),66TONEMAP_FLAG_USE_10_BIT_DEBANDING = (1 << 6),67TONEMAP_FLAG_CONVERT_TO_SRGB = (1 << 7),68};6970struct TonemapPushConstant {71float bcs[3]; // 12 - 1272uint32_t flags; // 4 - 167374float pixel_size[2]; // 8 - 2475uint32_t tonemapper; // 4 - 2876uint32_t pad; // 4 - 327778uint32_t glow_texture_size[2]; // 8 - 4079float glow_intensity; // 4 - 4480float glow_map_strength; // 4 - 488182uint32_t glow_mode; // 4 - 5283float glow_levels[7]; // 28 - 808485float exposure; // 4 - 8486float white; // 4 - 8887float auto_exposure_scale; // 4 - 9288float luminance_multiplier; // 4 - 9689};9091/* tonemap actually writes to a framebuffer, which is92* better to do using the raster pipeline rather than93* compute, as that framebuffer might be in different formats94*/95struct Tonemap {96TonemapPushConstant push_constant;97TonemapShaderRD shader;98RID shader_version;99PipelineCacheRD pipelines[TONEMAP_MODE_MAX];100} tonemap;101102public:103ToneMapper();104~ToneMapper();105106struct TonemapSettings {107bool use_glow = false;108enum GlowMode {109GLOW_MODE_ADD,110GLOW_MODE_SCREEN,111GLOW_MODE_SOFTLIGHT,112GLOW_MODE_REPLACE,113GLOW_MODE_MIX114};115116GlowMode glow_mode = GLOW_MODE_ADD;117float glow_intensity = 1.0;118float glow_map_strength = 0.0f;119float glow_levels[7] = { 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0 };120Vector2i glow_texture_size;121bool glow_use_bicubic_upscale = false;122RID glow_texture;123RID glow_map;124125RS::EnvironmentToneMapper tonemap_mode = RS::ENV_TONE_MAPPER_LINEAR;126float exposure = 1.0;127float white = 1.0;128129bool use_auto_exposure = false;130float auto_exposure_scale = 0.5;131RID exposure_texture;132float luminance_multiplier = 1.0;133134bool use_bcs = false;135float brightness = 1.0;136float contrast = 1.0;137float saturation = 1.0;138139bool use_color_correction = false;140bool use_1d_color_correction = false;141RID color_correction_texture;142143bool use_fxaa = false;144enum DebandingMode {145DEBANDING_MODE_DISABLED,146DEBANDING_MODE_8_BIT,147DEBANDING_MODE_10_BIT,148};149DebandingMode debanding_mode = DEBANDING_MODE_DISABLED;150Vector2i texture_size;151uint32_t view_count = 1;152153bool convert_to_srgb = false;154};155156void tonemapper(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings);157void tonemapper(RD::DrawListID p_subpass_draw_list, RID p_source_color, RD::FramebufferFormatID p_dst_format_id, const TonemapSettings &p_settings);158};159160} // namespace RendererRD161162163