Path: blob/master/servers/rendering/renderer_rd/effects/copy_effects.h
21420 views
/**************************************************************************/1/* copy_effects.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/pipeline_deferred_rd.h"34#include "servers/rendering/renderer_rd/shaders/effects/blur_raster.glsl.gen.h"35#include "servers/rendering/renderer_rd/shaders/effects/copy.glsl.gen.h"36#include "servers/rendering/renderer_rd/shaders/effects/copy_to_fb.glsl.gen.h"37#include "servers/rendering/renderer_rd/shaders/effects/cube_to_dp.glsl.gen.h"38#include "servers/rendering/renderer_rd/shaders/effects/cube_to_octmap.glsl.gen.h"39#include "servers/rendering/renderer_rd/shaders/effects/octmap_downsampler.glsl.gen.h"40#include "servers/rendering/renderer_rd/shaders/effects/octmap_downsampler_raster.glsl.gen.h"41#include "servers/rendering/renderer_rd/shaders/effects/octmap_filter.glsl.gen.h"42#include "servers/rendering/renderer_rd/shaders/effects/octmap_filter_raster.glsl.gen.h"43#include "servers/rendering/renderer_rd/shaders/effects/octmap_roughness.glsl.gen.h"44#include "servers/rendering/renderer_rd/shaders/effects/octmap_roughness_raster.glsl.gen.h"45#include "servers/rendering/renderer_rd/shaders/effects/specular_merge.glsl.gen.h"46#include "servers/rendering/renderer_scene_render.h"4748#include "servers/rendering/rendering_server.h"4950namespace RendererRD {5152class CopyEffects {53public:54enum RasterEffects {55RASTER_EFFECT_COPY = 1 << 0,56RASTER_EFFECT_GAUSSIAN_BLUR = 1 << 1,57RASTER_EFFECT_OCTMAP = 1 << 2,58};5960private:61BitField<RasterEffects> raster_effects;6263// Blur raster shader6465enum BlurRasterMode {66BLUR_MIPMAP,6768BLUR_MODE_GAUSSIAN_BLUR,69BLUR_MODE_GAUSSIAN_GLOW_GATHER,70BLUR_MODE_GAUSSIAN_GLOW_DOWNSAMPLE,71BLUR_MODE_GAUSSIAN_GLOW_UPSAMPLE,72BLUR_MODE_COPY,7374BLUR_MODE_SET_COLOR,7576BLUR_MODE_MAX77};7879enum {80BLUR_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 1),81};8283struct BlurRasterPushConstant {84float dest_pixel_size[2];85float source_pixel_size[2];8687float pad[2];88uint32_t flags;89float level;9091//glow92float glow_strength;93float glow_bloom;94float glow_hdr_threshold;95float glow_hdr_scale;9697float glow_exposure;98float glow_white;99float glow_luminance_cap;100float luminance_multiplier;101};102103struct BlurRaster {104BlurRasterPushConstant push_constant;105BlurRasterShaderRD shader;106RID shader_version;107PipelineCacheRD pipelines[BLUR_MODE_MAX];108RID glow_sampler;109} blur_raster;110111// Copy shader112113enum CopyMode {114COPY_MODE_GAUSSIAN_COPY,115COPY_MODE_GAUSSIAN_COPY_8BIT,116COPY_MODE_GAUSSIAN_GLOW,117COPY_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,118COPY_MODE_SIMPLY_COPY,119COPY_MODE_SIMPLY_COPY_8BIT,120COPY_MODE_SIMPLY_COPY_DEPTH,121COPY_MODE_SET_COLOR,122COPY_MODE_SET_COLOR_8BIT,123COPY_MODE_MIPMAP,124COPY_MODE_LINEARIZE_DEPTH,125COPY_MODE_OCTMAP_TO_PANORAMA,126COPY_MODE_OCTMAP_ARRAY_TO_PANORAMA,127COPY_MODE_MAX,128129};130131enum {132COPY_FLAG_HORIZONTAL = (1 << 0),133COPY_FLAG_USE_COPY_SECTION = (1 << 1),134COPY_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 2),135COPY_FLAG_DOF_NEAR_FIRST_TAP = (1 << 3),136COPY_FLAG_GLOW_FIRST_PASS = (1 << 4),137COPY_FLAG_FLIP_Y = (1 << 5),138COPY_FLAG_FORCE_LUMINANCE = (1 << 6),139COPY_FLAG_ALL_SOURCE = (1 << 7),140COPY_FLAG_ALPHA_TO_ONE = (1 << 8),141COPY_FLAG_SANITIZE_INF_NAN = (1 << 9),142};143144struct CopyPushConstant {145int32_t section[4];146int32_t target[2];147uint32_t flags;148float luminance_multiplier;149// Glow.150float glow_strength;151float glow_bloom;152float glow_hdr_threshold;153float glow_hdr_scale;154155float glow_exposure;156float glow_white;157float glow_luminance_cap;158float glow_auto_exposure_scale;159// DOF.160float camera_z_far;161float camera_z_near;162// Octmap.163float octmap_border_size[2];164//SET color165float set_color[4];166};167168struct Copy {169CopyPushConstant push_constant;170CopyShaderRD shader;171RID shader_version;172PipelineDeferredRD pipelines[COPY_MODE_MAX];173174} copy;175176// Copy to FB shader177178enum CopyToFBMode {179COPY_TO_FB_COPY,180COPY_TO_FB_COPY_PANORAMA_TO_DP,181COPY_TO_FB_COPY2,182COPY_TO_FB_SET_COLOR,183184// These variants are disabled unless XR shaders are enabled.185// They should be listed last.186COPY_TO_FB_MULTIVIEW,187COPY_TO_FB_MULTIVIEW_WITH_DEPTH,188189COPY_TO_FB_MAX,190};191192enum CopyToFBFlags {193COPY_TO_FB_FLAG_FLIP_Y = (1 << 0),194COPY_TO_FB_FLAG_USE_SECTION = (1 << 1),195COPY_TO_FB_FLAG_FORCE_LUMINANCE = (1 << 2),196COPY_TO_FB_FLAG_ALPHA_TO_ZERO = (1 << 3),197COPY_TO_FB_FLAG_SRGB = (1 << 4),198COPY_TO_FB_FLAG_ALPHA_TO_ONE = (1 << 5),199COPY_TO_FB_FLAG_LINEAR = (1 << 6),200COPY_TO_FB_FLAG_NORMAL = (1 << 7),201COPY_TO_FB_FLAG_USE_SRC_SECTION = (1 << 8),202};203204struct CopyToFbPushConstant {205float section[4];206float pixel_size[2];207float luminance_multiplier;208uint32_t flags;209210float set_color[4];211};212213struct CopyToFb {214CopyToFbPushConstant push_constant;215CopyToFbShaderRD shader;216RID shader_version;217PipelineCacheRD pipelines[COPY_TO_FB_MAX];218219} copy_to_fb;220221// Copy to DP222223struct CopyToDPPushConstant {224float z_far;225float z_near;226float texel_size[2];227};228229struct CopyToDP {230CubeToDpShaderRD shader;231RID shader_version;232PipelineCacheRD pipeline;233} cube_to_dp;234235// Copy to Octmap236237struct CopyToOctmapPushConstant {238float border_size;239uint32_t pad[3];240};241242struct CopyToOctmap {243CopyToOctmapPushConstant push_constant;244CubeToOctmapShaderRD shader;245RID shader_version;246PipelineCacheRD pipeline;247} cube_to_octmap;248249// Octmap effects250251struct OctmapDownsamplerPushConstant {252float border_size;253uint32_t size;254uint32_t pad[2];255};256257enum OctmapDownsamplerMode {258DOWNSAMPLER_MODE_FLAG_RGB10_A2 = (1 << 0),259260DOWNSAMPLER_MODE_COMPUTE_MAX = (DOWNSAMPLER_MODE_FLAG_RGB10_A2 + 1),261DOWNSAMPLER_MODE_RASTER_MAX = 1,262};263264struct OctmapDownsampler {265OctmapDownsamplerPushConstant push_constant;266OctmapDownsamplerShaderRD compute_shader;267OctmapDownsamplerRasterShaderRD raster_shader;268RID shader_version;269PipelineDeferredRD compute_pipelines[DOWNSAMPLER_MODE_COMPUTE_MAX];270PipelineCacheRD raster_pipeline;271} octmap_downsampler;272273enum OctmapFilterMode {274FILTER_MODE_FLAG_HIGH_QUALITY = (1 << 0),275FILTER_MODE_FLAG_ARRAY = (1 << 1),276FILTER_MODE_FLAG_RGB10_A2 = (1 << 2),277278FILTER_MODE_COMPUTE_MAX = ((FILTER_MODE_FLAG_HIGH_QUALITY | FILTER_MODE_FLAG_ARRAY | FILTER_MODE_FLAG_RGB10_A2) + 1),279FILTER_MODE_RASTER_MAX = (FILTER_MODE_FLAG_HIGH_QUALITY + 1),280};281282struct OctmapFilterPushConstant {283float border_size[2];284uint32_t pad1;285uint32_t pad2;286};287288struct OctmapFilterRasterPushConstant {289float border_size[2];290uint32_t mip_level;291uint32_t pad;292};293294struct OctmapFilter {295OctmapFilterShaderRD compute_shader;296OctmapFilterRasterShaderRD raster_shader;297RID shader_version;298PipelineDeferredRD compute_pipelines[FILTER_MODE_COMPUTE_MAX];299PipelineCacheRD raster_pipelines[FILTER_MODE_RASTER_MAX];300301RID uniform_set;302RID image_uniform_set;303RID coefficient_buffer;304bool use_high_quality;305306} filter;307308enum OctmapRoughnessMode {309ROUGHNESS_MODE_RGBA16F,310ROUGHNESS_MODE_RGB10_A2,311ROUGHNESS_MODE_MAX,312};313314struct OctmapRoughnessPushConstant {315uint32_t sample_count;316float roughness;317uint32_t source_size;318uint32_t dest_size;319320float border_size[2];321uint32_t use_direct_write;322uint32_t pad;323};324325struct OctmapRoughness {326OctmapRoughnessPushConstant push_constant;327OctmapRoughnessShaderRD compute_shader;328OctmapRoughnessRasterShaderRD raster_shader;329RID shader_version;330PipelineDeferredRD compute_pipelines[ROUGHNESS_MODE_MAX];331PipelineCacheRD raster_pipeline;332} roughness;333334// Merge specular335336enum SpecularMergeMode {337SPECULAR_MERGE_ADD,338SPECULAR_MERGE_SSR,339SPECULAR_MERGE_ADDITIVE_ADD,340SPECULAR_MERGE_ADDITIVE_SSR,341342SPECULAR_MERGE_ADD_MULTIVIEW,343SPECULAR_MERGE_SSR_MULTIVIEW,344SPECULAR_MERGE_ADDITIVE_ADD_MULTIVIEW,345SPECULAR_MERGE_ADDITIVE_SSR_MULTIVIEW,346347SPECULAR_MERGE_MAX348};349350/* Specular merge must be done using raster, rather than compute351* because it must continue the existing color buffer352*/353354struct SpecularMerge {355SpecularMergeShaderRD shader;356RID shader_version;357PipelineCacheRD pipelines[SPECULAR_MERGE_MAX];358359} specular_merge;360361static CopyEffects *singleton;362363public:364static CopyEffects *get_singleton();365366CopyEffects(BitField<RasterEffects> p_raster_effects);367~CopyEffects();368369BitField<RasterEffects> get_raster_effects() { return raster_effects; }370371void copy_to_rect(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_rect, bool p_flip_y = false, bool p_force_luminance = false, bool p_all_source = false, bool p_8_bit_dst = false, bool p_alpha_to_one = false, bool p_sanitize_inf_nan = false);372void copy_octmap_to_panorama(RID p_source_octmap, RID p_dest_panorama, const Size2i &p_panorama_size, float p_lod, bool p_is_array, const Size2 &p_source_octmap_border_size);373void copy_depth_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false);374void copy_depth_to_rect_and_linearize(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_rect, bool p_flip_y, float p_z_near, float p_z_far);375void copy_to_fb_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false, bool p_force_luminance = false, bool p_alpha_to_zero = false, bool p_srgb = false, RID p_secondary = RID(), bool p_multiview = false, bool alpha_to_one = false, bool p_linear = false, bool p_normal = false, const Rect2 &p_src_rect = Rect2(), float p_linear_luminance_multiplier = 1.0);376void copy_to_atlas_fb(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_uv_rect, RD::DrawListID p_draw_list, bool p_flip_y = false, bool p_panorama = false);377void copy_to_drawlist(RD::DrawListID p_draw_list, RD::FramebufferFormatID p_fb_format, RID p_source_rd_texture, bool p_linear = false, float p_linear_luminance_multiplier = 1.0);378void copy_raster(RID p_source_texture, RID p_dest_framebuffer);379380void gaussian_blur(RID p_source_rd_texture, RID p_texture, const Rect2i &p_region, const Size2i &p_size, bool p_8bit_dst = false);381void gaussian_blur_raster(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_region, const Size2i &p_size);382void gaussian_glow(RID p_source_rd_texture, RID p_back_texture, const Size2i &p_size, float p_strength = 1.0, bool p_first_pass = false, float p_luminance_cap = 16.0, float p_exposure = 1.0, float p_bloom = 0.0, float p_hdr_bleed_threshold = 1.0, float p_hdr_bleed_scale = 1.0, RID p_auto_exposure = RID(), float p_auto_exposure_scale = 1.0);383void gaussian_glow_downsample_raster(RID p_source_rd_texture, RID p_dest_texture, float p_luminance_multiplier, const Size2i &p_size, float p_strength = 1.0, bool p_first_pass = false, float p_luminance_cap = 16.0, float p_exposure = 1.0, float p_bloom = 0.0, float p_hdr_bleed_threshold = 1.0, float p_hdr_bleed_scale = 1.0);384void gaussian_glow_upsample_raster(RID p_source_rd_texture, RID p_dest_texture, RID p_blend_texture, float p_luminance_multiplier, const Size2i &p_source_size, const Size2i &p_dest_size, float p_level, float p_base_strength, bool p_use_debanding);385386void make_mipmap(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);387void make_mipmap_raster(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);388389void set_color(RID p_dest_texture, const Color &p_color, const Rect2i &p_region, bool p_8bit_dst = false);390void set_color_raster(RID p_dest_texture, const Color &p_color, const Rect2i &p_region);391392void copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dst_framebuffer, const Rect2 &p_rect, const Vector2 &p_dst_size, float p_z_near, float p_z_far, bool p_dp_flip);393void copy_cubemap_to_octmap(RID p_source_rd_texture, RID p_dst_framebuffer, float p_border_size);394void octmap_downsample(RID p_source_octmap, RID p_dest_octmap, const Size2i &p_size, float p_border_size);395void octmap_downsample_raster(RID p_source_octmap, RID p_dest_framebuffer, const Size2i &p_size, float p_border_size);396void octmap_filter(RID p_source_octmap, const Vector<RID> &p_dest_octmap, bool p_use_array, float p_border_size);397void octmap_filter_raster(RID p_source_octmap, RID p_dest_framebuffer, uint32_t p_mip_level, float p_border_size);398void octmap_roughness(RID p_source_rd_texture, RID p_dest_texture, uint32_t p_sample_count, float p_roughness, uint32_t p_source_size, uint32_t p_dest_size, float p_border_size);399void octmap_roughness_raster(RID p_source_rd_texture, RID p_dest_framebuffer, uint32_t p_sample_count, float p_roughness, uint32_t p_source_size, uint32_t p_dest_size, float p_border_size);400401void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection, uint32_t p_view_count);402};403404} // namespace RendererRD405406407