Path: blob/master/servers/rendering/renderer_rd/effects/smaa.h
10279 views
/**************************************************************************/1/* smaa.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/smaa_blending.glsl.gen.h"34#include "servers/rendering/renderer_rd/shaders/effects/smaa_edge_detection.glsl.gen.h"35#include "servers/rendering/renderer_rd/shaders/effects/smaa_weight_calculation.glsl.gen.h"36#include "servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h"37#include "servers/rendering/renderer_scene_render.h"3839#include "servers/rendering_server.h"4041#define RB_SCOPE_SMAA SNAME("rb_smaa")4243#define RB_EDGES SNAME("edges")44#define RB_BLEND SNAME("blend")45#define RB_STENCIL SNAME("stencil")4647namespace RendererRD {4849class SMAA {50private:51enum SMAAMode {52SMAA_EDGE_DETECTION_COLOR,53SMAA_WEIGHT_FULL,54SMAA_BLENDING,55SMAA_MAX,56};5758struct SMAAEdgePushConstant {59float inv_size[2];60float threshold;61float pad;62};6364struct SMAAWeightPushConstant {65float inv_size[2];66uint32_t size[2];6768float subsample_indices[4];69};7071struct SMAABlendPushConstant {72float inv_size[2];73uint32_t flags;74float pad;75};7677enum SMAABlendFlags {78SMAA_BLEND_FLAG_USE_8_BIT_DEBANDING = (1 << 0),79SMAA_BLEND_FLAG_USE_10_BIT_DEBANDING = (1 << 1),80};8182struct SMAAEffect {83SMAAEdgePushConstant edge_push_constant;84SmaaEdgeDetectionShaderRD edge_shader;85RID edge_shader_version;8687SMAAWeightPushConstant weight_push_constant;88SmaaWeightCalculationShaderRD weight_shader;89RID weight_shader_version;9091SMAABlendPushConstant blend_push_constant;92SmaaBlendingShaderRD blend_shader;93RID blend_shader_version;9495RID search_tex;96RID area_tex;9798RD::DataFormat stencil_format;99100PipelineCacheRD pipelines[SMAA_MAX];101} smaa;102103float edge_detection_threshold;104105public:106SMAA();107~SMAA();108109void allocate_render_targets(Ref<RenderSceneBuffersRD> p_render_buffers);110void process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_source_color, RID p_dst_framebuffer);111112enum DebandingMode {113DEBANDING_MODE_DISABLED,114DEBANDING_MODE_8_BIT,115DEBANDING_MODE_10_BIT,116};117DebandingMode debanding_mode = DEBANDING_MODE_DISABLED;118};119120} // namespace RendererRD121122123