Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 8be33ff

Browse files
committed
pulled out the rotation from the uv calculation
1 parent b738985 commit 8be33ff

File tree

1 file changed

+58
-21
lines changed

1 file changed

+58
-21
lines changed

impeller/entity/contents/filters/gaussian_blur_filter_contents.cc

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,19 @@ void BindVertices(Command& cmd,
3939

4040
/// @brief This performs the conversion from an entity's local coordinates to
4141
/// a subpasses uv coordinates.
42-
std::array<Point, 4> CalculateUVs(const Rect& coverage,
43-
const ISize& pass_size,
44-
const Matrix& entity_transform) {
45-
return coverage.GetTransformedPoints(
46-
Matrix::MakeScale(
47-
{1.0f / pass_size.width, 1.0f / pass_size.height, 1.0f}) *
48-
entity_transform.Invert());
49-
}
42+
// std::array<Point, 4> CalculateUVs(const std::array<Point, 4>& coverage,
43+
// const ISize& pass_size,
44+
// const Matrix& entity_transform) {
45+
// Matrix transform = Matrix::MakeScale({1.0f / pass_size.width,
46+
// 1.0f / pass_size.height, 1.0f}) *
47+
// entity_transform.Invert();
48+
// return {
49+
// transform * coverage[0],
50+
// transform * coverage[1],
51+
// transform * coverage[2],
52+
// transform * coverage[3],
53+
// };
54+
// }
5055

5156
std::shared_ptr<Texture> MakeDownsampleSubpass(
5257
const ContentContext& renderer,
@@ -200,7 +205,7 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
200205

201206
std::optional<Snapshot> input_snapshot =
202207
inputs[0]->GetSnapshot("GaussianBlur", renderer, entity,
203-
/*coverage_hint=*/{});
208+
/*coverage_hint=*/coverage_hint);
204209
if (!input_snapshot.has_value()) {
205210
return std::nullopt;
206211
}
@@ -213,8 +218,39 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
213218
ISize subpass_size =
214219
ISize(input_snapshot->texture->GetSize().width / downsample.x,
215220
input_snapshot->texture->GetSize().height / downsample.y);
216-
std::array<Point, 4> uvs = CalculateUVs(
217-
coverage, input_snapshot->texture->GetSize(), entity.GetTransformation());
221+
222+
///////////////////////////////
223+
Matrix input_transform = inputs[0]->GetTransform(entity);
224+
Rect snapshot_rect =
225+
Rect::MakeXYWH(0, 0, input_snapshot->texture->GetSize().width,
226+
input_snapshot->texture->GetSize().height);
227+
std::array<Point, 4> coverage_quad =
228+
snapshot_rect.GetTransformedPoints(input_transform);
229+
if (coverage_hint.has_value()) {
230+
// Perform an intersection with the quad and the rect. If the coverage_hint
231+
// doesn't contain any of the coverage_quads points that means it inside of
232+
// the quad (or they are completely disjoint which isn't considered here).
233+
if (!coverage_hint.value().Contains(coverage_quad[0]) &&
234+
!coverage_hint.value().Contains(coverage_quad[1]) &&
235+
!coverage_hint.value().Contains(coverage_quad[2]) &&
236+
!coverage_hint.value().Contains(coverage_quad[3])) {
237+
coverage_quad = coverage_hint.value().GetPoints();
238+
}
239+
}
240+
241+
Matrix uv_transform =
242+
Matrix::MakeScale({1.0f / input_snapshot->texture->GetSize().width,
243+
1.0f / input_snapshot->texture->GetSize().height,
244+
1.0f}) *
245+
entity.GetTransformation().Invert();
246+
std::array<Point, 4> uvs = {
247+
uv_transform * coverage_quad[0],
248+
uv_transform * coverage_quad[1],
249+
uv_transform * coverage_quad[2],
250+
uv_transform * coverage_quad[3],
251+
};
252+
253+
/////////////////////////////////
218254
std::shared_ptr<Texture> pass1_out_texture = MakeDownsampleSubpass(
219255
renderer, input_snapshot->texture, input_snapshot->sampler_descriptor,
220256
uvs, subpass_size);
@@ -245,16 +281,17 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
245281
MinMagFilter::kLinear, SamplerAddressMode::kClampToEdge);
246282

247283
return Entity::FromSnapshot(
248-
Snapshot{
249-
.texture = pass3_out_texture,
250-
.transform =
251-
Matrix::MakeTranslation(coverage.origin) *
252-
Matrix::MakeScale(
253-
{coverage.size.width / pass1_out_texture->GetSize().width,
254-
coverage.size.height / pass1_out_texture->GetSize().height,
255-
1.0}),
256-
.sampler_descriptor = sampler_desc,
257-
.opacity = input_snapshot->opacity},
284+
Snapshot{.texture = pass3_out_texture,
285+
.transform =
286+
// TODO(gaaclarke): Put the entity rotation into here to
287+
// capture rotations.
288+
Matrix::MakeTranslation(coverage.origin) *
289+
Matrix::MakeScale(
290+
{coverage.size.width / pass1_out_texture->GetSize().width,
291+
coverage.size.height / pass1_out_texture->GetSize().height,
292+
1.0}),
293+
.sampler_descriptor = sampler_desc,
294+
.opacity = input_snapshot->opacity},
258295
entity.GetBlendMode(), entity.GetClipDepth());
259296
}
260297

0 commit comments

Comments
 (0)