@@ -20,42 +20,28 @@ using PipelineProc =
2020 std::shared_ptr<Pipeline> (ContentContext::*)(ContentContextOptions) const ;
2121
2222template <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) {
3627 if (input_textures.size () < 2 ) {
3728 return false ;
3829 }
3930
4031 auto & host_buffer = pass.GetTransientsBuffer ();
4132
33+ auto size = pass.GetRenderTargetSize ();
4234 VertexBufferBuilder<typename VS::PerVertexData> vtx_builder;
4335 vtx_builder.AddVertices ({
4436 {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 )},
4739 {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 )},
5042 });
5143 auto vtx_buffer = vtx_builder.CreateVertexBuffer (host_buffer);
5244
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-
5945 auto options = OptionsFromPass (pass);
6046 options.blend_mode = Entity::BlendMode::kSource ;
6147 std::shared_ptr<Pipeline> pipeline =
@@ -65,10 +51,27 @@ static bool AdvancedBlend(
6551 cmd.label = " Advanced Blend Filter" ;
6652 cmd.BindVertices (vtx_buffer);
6753 cmd.pipeline = std::move (pipeline);
68- VS::BindFrameInfo (cmd, uniform_view);
6954
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);
7275 pass.AddCommand (cmd);
7376
7477 return true ;
@@ -88,46 +91,42 @@ void BlendFilterContents::SetBlendMode(Entity::BlendMode blend_mode) {
8891
8992 switch (blend_mode) {
9093 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+ };
99102 break ;
100103 default :
101104 FML_UNREACHABLE ();
102105 }
103106 }
104107}
105108
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) {
111113 using VS = TextureBlendPipeline::VertexShader;
112114 using FS = TextureBlendPipeline::FragmentShader;
113115
114116 auto & host_buffer = pass.GetTransientsBuffer ();
115117
118+ auto size = pass.GetRenderTargetSize ();
116119 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
117120 vtx_builder.AddVertices ({
118121 {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 )},
121124 {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 )},
124127 });
125128 auto vtx_buffer = vtx_builder.CreateVertexBuffer (host_buffer);
126129
127- VS::FrameInfo frame_info;
128- frame_info.mvp = Matrix::MakeOrthographic (ISize (1 , 1 ));
129-
130- auto uniform_view = host_buffer.EmplaceUniform (frame_info);
131130 auto sampler = renderer.GetContext ()->GetSamplerLibrary ()->GetSampler ({});
132131
133132 // Draw the first texture using kSource.
@@ -138,8 +137,19 @@ static bool BasicBlend(
138137 auto options = OptionsFromPass (pass);
139138 options.blend_mode = Entity::BlendMode::kSource ;
140139 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+ }
143153 pass.AddCommand (cmd);
144154
145155 if (input_textures.size () < 2 ) {
@@ -153,17 +163,28 @@ static bool BasicBlend(
153163
154164 for (auto texture_i = input_textures.begin () + 1 ;
155165 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);
157177 pass.AddCommand (cmd);
158178 }
159179
160180 return true ;
161181}
162182
163183bool BlendFilterContents::RenderFilter (
164- const std::vector<std::shared_ptr<Texture> >& input_textures,
184+ const std::vector<Snapshot >& input_textures,
165185 const ContentContext& renderer,
166- RenderPass& pass) const {
186+ RenderPass& pass,
187+ const Matrix& transform) const {
167188 if (input_textures.empty ()) {
168189 return true ;
169190 }
0 commit comments