Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/renderer_rd/effects/smaa.h
10279 views
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
#include "servers/rendering/renderer_scene_render.h"
39
40
#include "servers/rendering_server.h"
41
42
#define RB_SCOPE_SMAA SNAME("rb_smaa")
43
44
#define RB_EDGES SNAME("edges")
45
#define RB_BLEND SNAME("blend")
46
#define RB_STENCIL SNAME("stencil")
47
48
namespace RendererRD {
49
50
class SMAA {
51
private:
52
enum SMAAMode {
53
SMAA_EDGE_DETECTION_COLOR,
54
SMAA_WEIGHT_FULL,
55
SMAA_BLENDING,
56
SMAA_MAX,
57
};
58
59
struct SMAAEdgePushConstant {
60
float inv_size[2];
61
float threshold;
62
float pad;
63
};
64
65
struct SMAAWeightPushConstant {
66
float inv_size[2];
67
uint32_t size[2];
68
69
float subsample_indices[4];
70
};
71
72
struct SMAABlendPushConstant {
73
float inv_size[2];
74
uint32_t flags;
75
float pad;
76
};
77
78
enum SMAABlendFlags {
79
SMAA_BLEND_FLAG_USE_8_BIT_DEBANDING = (1 << 0),
80
SMAA_BLEND_FLAG_USE_10_BIT_DEBANDING = (1 << 1),
81
};
82
83
struct SMAAEffect {
84
SMAAEdgePushConstant edge_push_constant;
85
SmaaEdgeDetectionShaderRD edge_shader;
86
RID edge_shader_version;
87
88
SMAAWeightPushConstant weight_push_constant;
89
SmaaWeightCalculationShaderRD weight_shader;
90
RID weight_shader_version;
91
92
SMAABlendPushConstant blend_push_constant;
93
SmaaBlendingShaderRD blend_shader;
94
RID blend_shader_version;
95
96
RID search_tex;
97
RID area_tex;
98
99
RD::DataFormat stencil_format;
100
101
PipelineCacheRD pipelines[SMAA_MAX];
102
} smaa;
103
104
float edge_detection_threshold;
105
106
public:
107
SMAA();
108
~SMAA();
109
110
void allocate_render_targets(Ref<RenderSceneBuffersRD> p_render_buffers);
111
void process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_source_color, RID p_dst_framebuffer);
112
113
enum DebandingMode {
114
DEBANDING_MODE_DISABLED,
115
DEBANDING_MODE_8_BIT,
116
DEBANDING_MODE_10_BIT,
117
};
118
DebandingMode debanding_mode = DEBANDING_MODE_DISABLED;
119
};
120
121
} // namespace RendererRD
122
123