@@ -20,42 +20,28 @@ using PipelineProc =
20
20
std::shared_ptr<Pipeline> (ContentContext::*)(ContentContextOptions) const ;
21
21
22
22
template <typename VS, typename FS>
23
- static void AdvancedBlendPass (std::shared_ptr<Texture> input_d,
24
- std::shared_ptr<Texture> input_s,
25
- std::shared_ptr<const Sampler> sampler,
26
- const ContentContext& renderer,
27
- RenderPass& pass,
28
- Command& cmd) {}
29
-
30
- template <typename VS, typename FS>
31
- static bool AdvancedBlend (
32
- const std::vector<std::shared_ptr<Texture>>& input_textures,
33
- const ContentContext& renderer,
34
- RenderPass& pass,
35
- PipelineProc pipeline_proc) {
23
+ static bool AdvancedBlend (const std::vector<Contents::Snapshot>& input_textures,
24
+ const ContentContext& renderer,
25
+ RenderPass& pass,
26
+ PipelineProc pipeline_proc) {
36
27
if (input_textures.size () < 2 ) {
37
28
return false ;
38
29
}
39
30
40
31
auto & host_buffer = pass.GetTransientsBuffer ();
41
32
33
+ auto size = pass.GetRenderTargetSize ();
42
34
VertexBufferBuilder<typename VS::PerVertexData> vtx_builder;
43
35
vtx_builder.AddVertices ({
44
36
{Point (0 , 0 ), Point (0 , 0 )},
45
- {Point (1 , 0 ), Point (1 , 0 )},
46
- {Point (1 , 1 ), Point (1 , 1 )},
37
+ {Point (size. width , 0 ), Point (1 , 0 )},
38
+ {Point (size. width , size. height ), Point (1 , 1 )},
47
39
{Point (0 , 0 ), Point (0 , 0 )},
48
- {Point (1 , 1 ), Point (1 , 1 )},
49
- {Point (0 , 1 ), Point (0 , 1 )},
40
+ {Point (size. width , size. height ), Point (1 , 1 )},
41
+ {Point (0 , size. height ), Point (0 , 1 )},
50
42
});
51
43
auto vtx_buffer = vtx_builder.CreateVertexBuffer (host_buffer);
52
44
53
- typename VS::FrameInfo frame_info;
54
- frame_info.mvp = Matrix::MakeOrthographic (ISize (1 , 1 ));
55
-
56
- auto uniform_view = host_buffer.EmplaceUniform (frame_info);
57
- auto sampler = renderer.GetContext ()->GetSamplerLibrary ()->GetSampler ({});
58
-
59
45
auto options = OptionsFromPass (pass);
60
46
options.blend_mode = Entity::BlendMode::kSource ;
61
47
std::shared_ptr<Pipeline> pipeline =
@@ -65,10 +51,27 @@ static bool AdvancedBlend(
65
51
cmd.label = " Advanced Blend Filter" ;
66
52
cmd.BindVertices (vtx_buffer);
67
53
cmd.pipeline = std::move (pipeline);
68
- VS::BindFrameInfo (cmd, uniform_view);
69
54
70
- FS::BindTextureSamplerDst (cmd, input_textures[0 ], sampler);
71
- FS::BindTextureSamplerSrc (cmd, input_textures[1 ], sampler);
55
+ auto sampler = renderer.GetContext ()->GetSamplerLibrary ()->GetSampler ({});
56
+ typename VS::FrameInfo frame_info;
57
+ frame_info.mvp = Matrix::MakeOrthographic (size);
58
+
59
+ auto dst_snapshot = input_textures[1 ];
60
+ FS::BindTextureSamplerSrc (cmd, dst_snapshot.texture , sampler);
61
+ frame_info.dst_uv_transform =
62
+ Matrix::MakeTranslation (-dst_snapshot.position / size) *
63
+ Matrix::MakeScale (
64
+ Vector3 (Size (size) / Size (dst_snapshot.texture ->GetSize ())));
65
+
66
+ auto src_snapshot = input_textures[0 ];
67
+ FS::BindTextureSamplerDst (cmd, src_snapshot.texture , sampler);
68
+ frame_info.src_uv_transform =
69
+ Matrix::MakeTranslation (-src_snapshot.position / size) *
70
+ Matrix::MakeScale (
71
+ Vector3 (Size (size) / Size (src_snapshot.texture ->GetSize ())));
72
+
73
+ auto uniform_view = host_buffer.EmplaceUniform (frame_info);
74
+ VS::BindFrameInfo (cmd, uniform_view);
72
75
pass.AddCommand (cmd);
73
76
74
77
return true ;
@@ -88,46 +91,42 @@ void BlendFilterContents::SetBlendMode(Entity::BlendMode blend_mode) {
88
91
89
92
switch (blend_mode) {
90
93
case Entity::BlendMode::kScreen :
91
- advanced_blend_proc_ =
92
- []( const std::vector<std::shared_ptr<Texture>>& input_textures ,
93
- const ContentContext& renderer, RenderPass& pass) {
94
- PipelineProc p = &ContentContext::GetTextureBlendScreenPipeline;
95
- return AdvancedBlend<TextureBlendScreenPipeline::VertexShader,
96
- TextureBlendScreenPipeline::FragmentShader>(
97
- input_textures, renderer, pass, p);
98
- };
94
+ advanced_blend_proc_ = []( const std::vector<Snapshot>& input_textures,
95
+ const ContentContext& renderer ,
96
+ RenderPass& pass) {
97
+ PipelineProc p = &ContentContext::GetTextureBlendScreenPipeline;
98
+ return AdvancedBlend<TextureBlendScreenPipeline::VertexShader,
99
+ TextureBlendScreenPipeline::FragmentShader>(
100
+ input_textures, renderer, pass, p);
101
+ };
99
102
break ;
100
103
default :
101
104
FML_UNREACHABLE ();
102
105
}
103
106
}
104
107
}
105
108
106
- static bool BasicBlend (
107
- const std::vector<std::shared_ptr<Texture>>& input_textures,
108
- const ContentContext& renderer,
109
- RenderPass& pass,
110
- Entity::BlendMode basic_blend) {
109
+ static bool BasicBlend (const std::vector<Contents::Snapshot>& input_textures,
110
+ const ContentContext& renderer,
111
+ RenderPass& pass,
112
+ Entity::BlendMode basic_blend) {
111
113
using VS = TextureBlendPipeline::VertexShader;
112
114
using FS = TextureBlendPipeline::FragmentShader;
113
115
114
116
auto & host_buffer = pass.GetTransientsBuffer ();
115
117
118
+ auto size = pass.GetRenderTargetSize ();
116
119
VertexBufferBuilder<VS::PerVertexData> vtx_builder;
117
120
vtx_builder.AddVertices ({
118
121
{Point (0 , 0 ), Point (0 , 0 )},
119
- {Point (1 , 0 ), Point (1 , 0 )},
120
- {Point (1 , 1 ), Point (1 , 1 )},
122
+ {Point (size. width , 0 ), Point (1 , 0 )},
123
+ {Point (size. width , size. height ), Point (1 , 1 )},
121
124
{Point (0 , 0 ), Point (0 , 0 )},
122
- {Point (1 , 1 ), Point (1 , 1 )},
123
- {Point (0 , 1 ), Point (0 , 1 )},
125
+ {Point (size. width , size. height ), Point (1 , 1 )},
126
+ {Point (0 , size. height ), Point (0 , 1 )},
124
127
});
125
128
auto vtx_buffer = vtx_builder.CreateVertexBuffer (host_buffer);
126
129
127
- VS::FrameInfo frame_info;
128
- frame_info.mvp = Matrix::MakeOrthographic (ISize (1 , 1 ));
129
-
130
- auto uniform_view = host_buffer.EmplaceUniform (frame_info);
131
130
auto sampler = renderer.GetContext ()->GetSamplerLibrary ()->GetSampler ({});
132
131
133
132
// Draw the first texture using kSource.
@@ -138,8 +137,19 @@ static bool BasicBlend(
138
137
auto options = OptionsFromPass (pass);
139
138
options.blend_mode = Entity::BlendMode::kSource ;
140
139
cmd.pipeline = renderer.GetTextureBlendPipeline (options);
141
- FS::BindTextureSamplerSrc (cmd, input_textures[0 ], sampler);
142
- VS::BindFrameInfo (cmd, uniform_view);
140
+ {
141
+ auto input = input_textures[0 ];
142
+ FS::BindTextureSamplerSrc (cmd, input.texture , sampler);
143
+
144
+ VS::FrameInfo frame_info;
145
+ frame_info.mvp =
146
+ Matrix::MakeOrthographic (size) *
147
+ Matrix::MakeTranslation (input.position ) *
148
+ Matrix::MakeScale (Size (input.texture ->GetSize ()) / Size (size));
149
+
150
+ auto uniform_view = host_buffer.EmplaceUniform (frame_info);
151
+ VS::BindFrameInfo (cmd, uniform_view);
152
+ }
143
153
pass.AddCommand (cmd);
144
154
145
155
if (input_textures.size () < 2 ) {
@@ -153,17 +163,28 @@ static bool BasicBlend(
153
163
154
164
for (auto texture_i = input_textures.begin () + 1 ;
155
165
texture_i < input_textures.end (); texture_i++) {
156
- FS::BindTextureSamplerSrc (cmd, *texture_i, sampler);
166
+ auto input = *texture_i;
167
+ FS::BindTextureSamplerSrc (cmd, input.texture , sampler);
168
+
169
+ VS::FrameInfo frame_info;
170
+ frame_info.mvp = frame_info.mvp =
171
+ Matrix::MakeOrthographic (size) *
172
+ Matrix::MakeTranslation (input.position ) *
173
+ Matrix::MakeScale (Size (input.texture ->GetSize ()) / Size (size));
174
+
175
+ auto uniform_view = host_buffer.EmplaceUniform (frame_info);
176
+ VS::BindFrameInfo (cmd, uniform_view);
157
177
pass.AddCommand (cmd);
158
178
}
159
179
160
180
return true ;
161
181
}
162
182
163
183
bool BlendFilterContents::RenderFilter (
164
- const std::vector<std::shared_ptr<Texture> >& input_textures,
184
+ const std::vector<Snapshot >& input_textures,
165
185
const ContentContext& renderer,
166
- RenderPass& pass) const {
186
+ RenderPass& pass,
187
+ const Matrix& transform) const {
167
188
if (input_textures.empty ()) {
168
189
return true ;
169
190
}
0 commit comments