@@ -39,14 +39,19 @@ void BindVertices(Command& cmd,
39
39
40
40
// / @brief This performs the conversion from an entity's local coordinates to
41
41
// / 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
+ // }
50
55
51
56
std::shared_ptr<Texture> MakeDownsampleSubpass (
52
57
const ContentContext& renderer,
@@ -200,7 +205,7 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
200
205
201
206
std::optional<Snapshot> input_snapshot =
202
207
inputs[0 ]->GetSnapshot (" GaussianBlur" , renderer, entity,
203
- /* coverage_hint=*/ {} );
208
+ /* coverage_hint=*/ coverage_hint );
204
209
if (!input_snapshot.has_value ()) {
205
210
return std::nullopt;
206
211
}
@@ -213,8 +218,39 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
213
218
ISize subpass_size =
214
219
ISize (input_snapshot->texture ->GetSize ().width / downsample.x ,
215
220
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
+ // ///////////////////////////////
218
254
std::shared_ptr<Texture> pass1_out_texture = MakeDownsampleSubpass (
219
255
renderer, input_snapshot->texture , input_snapshot->sampler_descriptor ,
220
256
uvs, subpass_size);
@@ -245,16 +281,17 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
245
281
MinMagFilter::kLinear , SamplerAddressMode::kClampToEdge );
246
282
247
283
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 },
258
295
entity.GetBlendMode (), entity.GetClipDepth ());
259
296
}
260
297
0 commit comments