Path: blob/master/servers/rendering/renderer_rd/effects/copy_effects.h
10279 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/shaders/effects/blur_raster.glsl.gen.h"34#include "servers/rendering/renderer_rd/shaders/effects/copy.glsl.gen.h"35#include "servers/rendering/renderer_rd/shaders/effects/copy_to_fb.glsl.gen.h"36#include "servers/rendering/renderer_rd/shaders/effects/cube_to_dp.glsl.gen.h"37#include "servers/rendering/renderer_rd/shaders/effects/cubemap_downsampler.glsl.gen.h"38#include "servers/rendering/renderer_rd/shaders/effects/cubemap_downsampler_raster.glsl.gen.h"39#include "servers/rendering/renderer_rd/shaders/effects/cubemap_filter.glsl.gen.h"40#include "servers/rendering/renderer_rd/shaders/effects/cubemap_filter_raster.glsl.gen.h"41#include "servers/rendering/renderer_rd/shaders/effects/cubemap_roughness.glsl.gen.h"42#include "servers/rendering/renderer_rd/shaders/effects/cubemap_roughness_raster.glsl.gen.h"43#include "servers/rendering/renderer_rd/shaders/effects/specular_merge.glsl.gen.h"44#include "servers/rendering/renderer_scene_render.h"4546#include "servers/rendering_server.h"4748namespace RendererRD {4950class CopyEffects {51private:52bool prefer_raster_effects;5354// Blur raster shader5556enum BlurRasterMode {57BLUR_MIPMAP,5859BLUR_MODE_GAUSSIAN_BLUR,60BLUR_MODE_GAUSSIAN_GLOW,61BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,62BLUR_MODE_COPY,6364BLUR_MODE_SET_COLOR,6566BLUR_MODE_MAX67};6869enum {70BLUR_FLAG_HORIZONTAL = (1 << 0),71BLUR_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 1),72BLUR_FLAG_GLOW_FIRST_PASS = (1 << 2),73};7475struct BlurRasterPushConstant {76float pixel_size[2];77uint32_t flags;78uint32_t pad;7980//glow81float glow_strength;82float glow_bloom;83float glow_hdr_threshold;84float glow_hdr_scale;8586float glow_exposure;87float glow_white;88float glow_luminance_cap;89float glow_auto_exposure_scale;9091float luminance_multiplier;92float res1;93float res2;94float res3;95};9697struct BlurRaster {98BlurRasterPushConstant push_constant;99BlurRasterShaderRD shader;100RID shader_version;101PipelineCacheRD pipelines[BLUR_MODE_MAX];102} blur_raster;103104// Copy shader105106enum CopyMode {107COPY_MODE_GAUSSIAN_COPY,108COPY_MODE_GAUSSIAN_COPY_8BIT,109COPY_MODE_GAUSSIAN_GLOW,110COPY_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,111COPY_MODE_SIMPLY_COPY,112COPY_MODE_SIMPLY_COPY_8BIT,113COPY_MODE_SIMPLY_COPY_DEPTH,114COPY_MODE_SET_COLOR,115COPY_MODE_SET_COLOR_8BIT,116COPY_MODE_MIPMAP,117COPY_MODE_LINEARIZE_DEPTH,118COPY_MODE_CUBE_TO_PANORAMA,119COPY_MODE_CUBE_ARRAY_TO_PANORAMA,120COPY_MODE_MAX,121122};123124enum {125COPY_FLAG_HORIZONTAL = (1 << 0),126COPY_FLAG_USE_COPY_SECTION = (1 << 1),127COPY_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 2),128COPY_FLAG_DOF_NEAR_FIRST_TAP = (1 << 3),129COPY_FLAG_GLOW_FIRST_PASS = (1 << 4),130COPY_FLAG_FLIP_Y = (1 << 5),131COPY_FLAG_FORCE_LUMINANCE = (1 << 6),132COPY_FLAG_ALL_SOURCE = (1 << 7),133COPY_FLAG_ALPHA_TO_ONE = (1 << 8),134};135136struct CopyPushConstant {137int32_t section[4];138int32_t target[2];139uint32_t flags;140uint32_t pad;141// Glow.142float glow_strength;143float glow_bloom;144float glow_hdr_threshold;145float glow_hdr_scale;146147float glow_exposure;148float glow_white;149float glow_luminance_cap;150float glow_auto_exposure_scale;151// DOF.152float camera_z_far;153float camera_z_near;154uint32_t pad2[2];155//SET color156float set_color[4];157};158159struct Copy {160CopyPushConstant push_constant;161CopyShaderRD shader;162RID shader_version;163RID pipelines[COPY_MODE_MAX];164165} copy;166167// Copy to FB shader168169enum CopyToFBMode {170COPY_TO_FB_COPY,171COPY_TO_FB_COPY_PANORAMA_TO_DP,172COPY_TO_FB_COPY2,173COPY_TO_FB_SET_COLOR,174175// These variants are disabled unless XR shaders are enabled.176// They should be listed last.177COPY_TO_FB_MULTIVIEW,178COPY_TO_FB_MULTIVIEW_WITH_DEPTH,179180COPY_TO_FB_MAX,181};182183enum CopyToFBFlags {184COPY_TO_FB_FLAG_FLIP_Y = (1 << 0),185COPY_TO_FB_FLAG_USE_SECTION = (1 << 1),186COPY_TO_FB_FLAG_FORCE_LUMINANCE = (1 << 2),187COPY_TO_FB_FLAG_ALPHA_TO_ZERO = (1 << 3),188COPY_TO_FB_FLAG_SRGB = (1 << 4),189COPY_TO_FB_FLAG_ALPHA_TO_ONE = (1 << 5),190COPY_TO_FB_FLAG_LINEAR = (1 << 6),191COPY_TO_FB_FLAG_NORMAL = (1 << 7),192COPY_TO_FB_FLAG_USE_SRC_SECTION = (1 << 8),193};194195struct CopyToFbPushConstant {196float section[4];197float pixel_size[2];198float luminance_multiplier;199uint32_t flags;200201float set_color[4];202};203204struct CopyToFb {205CopyToFbPushConstant push_constant;206CopyToFbShaderRD shader;207RID shader_version;208PipelineCacheRD pipelines[COPY_TO_FB_MAX];209210} copy_to_fb;211212// Copy to DP213214struct CopyToDPPushConstant {215float z_far;216float z_near;217float texel_size[2];218};219220struct CopyToDP {221CubeToDpShaderRD shader;222RID shader_version;223PipelineCacheRD pipeline;224} cube_to_dp;225226// Cubemap effects227228struct CubemapDownsamplerPushConstant {229uint32_t face_size;230uint32_t face_id;231float pad[2];232};233234struct CubemapDownsampler {235CubemapDownsamplerPushConstant push_constant;236CubemapDownsamplerShaderRD compute_shader;237CubemapDownsamplerRasterShaderRD raster_shader;238RID shader_version;239RID compute_pipeline;240PipelineCacheRD raster_pipeline;241} cubemap_downsampler;242243enum CubemapFilterMode {244FILTER_MODE_HIGH_QUALITY,245FILTER_MODE_LOW_QUALITY,246FILTER_MODE_HIGH_QUALITY_ARRAY,247FILTER_MODE_LOW_QUALITY_ARRAY,248FILTER_MODE_MAX,249};250251struct CubemapFilterRasterPushConstant {252uint32_t mip_level;253uint32_t face_id;254float pad[2];255};256257struct CubemapFilter {258CubemapFilterShaderRD compute_shader;259CubemapFilterRasterShaderRD raster_shader;260RID shader_version;261RID compute_pipelines[FILTER_MODE_MAX];262PipelineCacheRD raster_pipelines[FILTER_MODE_MAX];263264RID uniform_set;265RID image_uniform_set;266RID coefficient_buffer;267bool use_high_quality;268269} filter;270271struct CubemapRoughnessPushConstant {272uint32_t face_id;273uint32_t sample_count;274float roughness;275uint32_t use_direct_write;276float face_size;277float pad[3];278};279280struct CubemapRoughness {281CubemapRoughnessPushConstant push_constant;282CubemapRoughnessShaderRD compute_shader;283CubemapRoughnessRasterShaderRD raster_shader;284RID shader_version;285RID compute_pipeline;286PipelineCacheRD raster_pipeline;287} roughness;288289// Merge specular290291enum SpecularMergeMode {292SPECULAR_MERGE_ADD,293SPECULAR_MERGE_SSR,294SPECULAR_MERGE_ADDITIVE_ADD,295SPECULAR_MERGE_ADDITIVE_SSR,296297SPECULAR_MERGE_ADD_MULTIVIEW,298SPECULAR_MERGE_SSR_MULTIVIEW,299SPECULAR_MERGE_ADDITIVE_ADD_MULTIVIEW,300SPECULAR_MERGE_ADDITIVE_SSR_MULTIVIEW,301302SPECULAR_MERGE_MAX303};304305/* Specular merge must be done using raster, rather than compute306* because it must continue the existing color buffer307*/308309struct SpecularMerge {310SpecularMergeShaderRD shader;311RID shader_version;312PipelineCacheRD pipelines[SPECULAR_MERGE_MAX];313314} specular_merge;315316static CopyEffects *singleton;317318public:319static CopyEffects *get_singleton();320321CopyEffects(bool p_prefer_raster_effects);322~CopyEffects();323324bool get_prefer_raster_effects() { return prefer_raster_effects; }325326void 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);327void copy_cubemap_to_panorama(RID p_source_cube, RID p_dest_panorama, const Size2i &p_panorama_size, float p_lod, bool p_is_array);328void copy_depth_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false);329void 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);330void 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());331void 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);332void copy_to_drawlist(RD::DrawListID p_draw_list, RD::FramebufferFormatID p_fb_format, RID p_source_rd_texture, bool p_linear = false);333void copy_raster(RID p_source_texture, RID p_dest_framebuffer);334335void gaussian_blur(RID p_source_rd_texture, RID p_texture, const Rect2i &p_region, const Size2i &p_size, bool p_8bit_dst = false);336void gaussian_blur_raster(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_region, const Size2i &p_size);337void 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);338void gaussian_glow_raster(RID p_source_rd_texture, RID p_half_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, RID p_auto_exposure = RID(), float p_auto_exposure_scale = 1.0);339340void make_mipmap(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);341void make_mipmap_raster(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);342343void set_color(RID p_dest_texture, const Color &p_color, const Rect2i &p_region, bool p_8bit_dst = false);344void set_color_raster(RID p_dest_texture, const Color &p_color, const Rect2i &p_region);345346void 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);347void cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size);348void cubemap_downsample_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, const Size2i &p_size);349void cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array);350void cubemap_filter_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_mip_level);351352void cubemap_roughness(RID p_source_rd_texture, RID p_dest_texture, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size);353void cubemap_roughness_raster(RID p_source_rd_texture, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size);354355void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection, uint32_t p_view_count);356};357358} // namespace RendererRD359360361