Path: blob/master/servers/rendering/renderer_rd/effects/tone_mapper.h
21372 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"34#include "servers/rendering/renderer_rd/shaders/effects/tonemap_mobile.glsl.gen.h"3536#include "servers/rendering/rendering_server.h"3738namespace RendererRD {3940class ToneMapper {41private:42bool using_mobile_version = false;43enum TonemapMode {44TONEMAP_MODE_NORMAL,45TONEMAP_MODE_BICUBIC_GLOW_FILTER,46TONEMAP_MODE_1D_LUT,47TONEMAP_MODE_BICUBIC_GLOW_FILTER_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,5354TONEMAP_MODE_MAX55};5657enum TonemapModeMobile {58TONEMAP_MOBILE_MODE_NORMAL,59TONEMAP_MOBILE_MODE_1D_LUT,60TONEMAP_MOBILE_MODE_SUBPASS,61TONEMAP_MOBILE_MODE_SUBPASS_1D_LUT,6263TONEMAP_MOBILE_MODE_NORMAL_MULTIVIEW,64TONEMAP_MOBILE_MODE_1D_LUT_MULTIVIEW,65TONEMAP_MOBILE_MODE_SUBPASS_MULTIVIEW,66TONEMAP_MOBILE_MODE_SUBPASS_1D_LUT_MULTIVIEW,6768TONEMAP_MOBILE_MODE_MAX69};7071enum Flags {72TONEMAP_FLAG_USE_BCS = (1 << 0),73TONEMAP_FLAG_USE_GLOW = (1 << 1),74TONEMAP_FLAG_USE_AUTO_EXPOSURE = (1 << 2),75TONEMAP_FLAG_USE_COLOR_CORRECTION = (1 << 3),76TONEMAP_FLAG_USE_FXAA = (1 << 4),77TONEMAP_FLAG_USE_8_BIT_DEBANDING = (1 << 5),78TONEMAP_FLAG_CONVERT_TO_SRGB = (1 << 6),79};8081enum FlagsMobile {82TONEMAP_MOBILE_FLAG_USE_BCS = (1 << 0),83TONEMAP_MOBILE_FLAG_USE_GLOW = (1 << 1),84TONEMAP_MOBILE_FLAG_USE_GLOW_MAP = (1 << 2),85TONEMAP_MOBILE_FLAG_USE_COLOR_CORRECTION = (1 << 3),86TONEMAP_MOBILE_FLAG_USE_FXAA = (1 << 4),87TONEMAP_MOBILE_FLAG_USE_8_BIT_DEBANDING = (1 << 5),88TONEMAP_MOBILE_FLAG_USE_10_BIT_DEBANDING = (1 << 6),89TONEMAP_MOBILE_FLAG_CONVERT_TO_SRGB = (1 << 7),9091TONEMAP_MOBILE_FLAG_TONEMAPPER_LINEAR = (1 << 8),92TONEMAP_MOBILE_FLAG_TONEMAPPER_REINHARD = (1 << 9),93TONEMAP_MOBILE_FLAG_TONEMAPPER_FILMIC = (1 << 10),94TONEMAP_MOBILE_FLAG_TONEMAPPER_ACES = (1 << 11),95TONEMAP_MOBILE_FLAG_TONEMAPPER_AGX = (1 << 12),9697TONEMAP_MOBILE_FLAG_GLOW_MODE_ADD = (1 << 13),98TONEMAP_MOBILE_FLAG_GLOW_MODE_SCREEN = (1 << 14),99TONEMAP_MOBILE_FLAG_GLOW_MODE_SOFTLIGHT = (1 << 15),100TONEMAP_MOBILE_FLAG_GLOW_MODE_REPLACE = (1 << 16),101TONEMAP_MOBILE_FLAG_GLOW_MODE_MIX = (1 << 17),102TONEMAP_MOBILE_ADRENO_BUG = (1 << 18), // Needs to be last so we force the pipeline cache to specify specializations for all variants.103};104105struct TonemapPushConstant {106float bcs[3]; // 12 - 12107uint32_t flags; // 4 - 16108109float pixel_size[2]; // 8 - 24110uint32_t tonemapper; // 4 - 28111uint32_t pad; // 4 - 32112113uint32_t glow_texture_size[2]; // 8 - 40114float glow_intensity; // 4 - 44115float glow_map_strength; // 4 - 48116117uint32_t glow_mode; // 4 - 52118float glow_levels[7]; // 28 - 80119120float exposure; // 4 - 84121float white; // 4 - 88122float auto_exposure_scale; // 4 - 92123float luminance_multiplier; // 4 - 96124125float tonemapper_params[4]; // 16 - 112126};127128struct TonemapPushConstantMobile {129float bcs[3]; // 12 - 12130float luminance_multiplier; // 4 - 16131132float src_pixel_size[2]; // 8 - 24133float dest_pixel_size[2]; // 8 - 32134135float glow_intensity; // 4 - 36136float glow_map_strength; // 4 - 40137float exposure; // 4 - 44138float white; // 4 - 48139140float tonemapper_params[4]; // 16 - 64141};142143/* tonemap actually writes to a framebuffer, which is144* better to do using the raster pipeline rather than145* compute, as that framebuffer might be in different formats146*/147struct Tonemap {148TonemapPushConstant push_constant;149TonemapShaderRD shader;150RID shader_version;151PipelineCacheRD pipelines[TONEMAP_MODE_MAX];152} tonemap;153154struct TonemapMobile {155TonemapPushConstantMobile push_constant;156TonemapMobileShaderRD shader;157RID shader_version;158PipelineCacheRD pipelines[TONEMAP_MOBILE_MODE_MAX];159} tonemap_mobile;160161public:162ToneMapper(bool p_use_mobile_version);163~ToneMapper();164165struct TonemapSettings {166bool use_glow = false;167RS::EnvironmentGlowBlendMode glow_mode = RS::ENV_GLOW_BLEND_MODE_SCREEN;168float glow_intensity = 0.3;169float glow_map_strength = 0.0f;170float glow_levels[7] = { 1.0, 0.8, 0.4, 0.1, 0.0, 0.0, 0.0 };171Vector2i glow_texture_size;172bool glow_use_bicubic_upscale = false;173RID glow_texture;174RID glow_map;175176RS::EnvironmentToneMapper tonemap_mode = RS::ENV_TONE_MAPPER_LINEAR;177float tonemapper_params[4] = { 0.0, 0.0, 0.0, 0.0 };178float exposure = 1.0;179float white = 1.0;180181bool use_auto_exposure = false;182float auto_exposure_scale = 0.5;183RID exposure_texture;184float luminance_multiplier = 1.0;185186bool use_bcs = false;187float brightness = 1.0;188float contrast = 1.0;189float saturation = 1.0;190191bool use_color_correction = false;192bool use_1d_color_correction = false;193RID color_correction_texture;194195bool use_fxaa = false;196enum DebandingMode {197DEBANDING_MODE_DISABLED,198DEBANDING_MODE_8_BIT,199DEBANDING_MODE_10_BIT,200};201DebandingMode debanding_mode = DEBANDING_MODE_DISABLED;202Vector2i texture_size;203Vector2i dest_texture_size;204uint32_t view_count = 1;205206bool convert_to_srgb = false;207};208209void tonemapper(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings);210void tonemapper_mobile(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings);211void tonemapper_subpass(RD::DrawListID p_subpass_draw_list, RID p_source_color, RD::FramebufferFormatID p_dst_format_id, const TonemapSettings &p_settings);212};213214} // namespace RendererRD215216217