Skip to content
0.2.0-dev Download ZIP
111 lines ·4.0 KB Raw
1/**************************************************************************/
2/* smaa.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#pragma once
32
33#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
34#include "servers/rendering/renderer_rd/shaders/effects/smaa_blending.glsl.gen.h"
35#include "servers/rendering/renderer_rd/shaders/effects/smaa_edge_detection.glsl.gen.h"
36#include "servers/rendering/renderer_rd/shaders/effects/smaa_weight_calculation.glsl.gen.h"
37#include "servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h"
38
39#define RB_SCOPE_SMAA SNAME("rb_smaa")
40
41#define RB_EDGES SNAME("edges")
42#define RB_BLEND SNAME("blend")
43#define RB_STENCIL SNAME("stencil")
44
45namespace RendererRD {
46
47class SMAA {
48private:
49 enum SMAAMode {
50 SMAA_EDGE_DETECTION_COLOR,
51 SMAA_WEIGHT_FULL,
52 SMAA_BLENDING,
53 SMAA_MAX,
54 };
55
56 struct SMAAEdgePushConstant {
57 float inv_size[2];
58 float threshold;
59 float pad;
60 };
61
62 struct SMAAWeightPushConstant {
63 float inv_size[2];
64 uint32_t size[2];
65
66 float subsample_indices[4];
67 };
68
69 struct SMAABlendPushConstant {
70 float inv_size[2];
71 uint32_t use_debanding;
72 float pad;
73 };
74
75 enum SMAABlendFlags {
76 SMAA_BLEND_FLAG_USE_8_BIT_DEBANDING = (1 << 0),
77 SMAA_BLEND_FLAG_USE_10_BIT_DEBANDING = (1 << 1),
78 };
79
80 struct SMAAEffect {
81 SMAAEdgePushConstant edge_push_constant;
82 SmaaEdgeDetectionShaderRD edge_shader;
83 RID edge_shader_version;
84
85 SMAAWeightPushConstant weight_push_constant;
86 SmaaWeightCalculationShaderRD weight_shader;
87 RID weight_shader_version;
88
89 SMAABlendPushConstant blend_push_constant;
90 SmaaBlendingShaderRD blend_shader;
91 RID blend_shader_version;
92
93 RID search_tex;
94 RID area_tex;
95
96 RD::DataFormat stencil_format;
97
98 PipelineCacheRD pipelines[SMAA_MAX];
99 } smaa;
100
101 float edge_detection_threshold;
102
103public:
104 SMAA();
105 ~SMAA();
106
107 void allocate_render_targets(Ref<RenderSceneBuffersRD> p_render_buffers);
108 void process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_source_color, RID p_dst_framebuffer, bool p_use_debanding);
109};
110
111} // namespace RendererRD