Hide edge aliasing of hard brushes with a blur (#1189)

* [𝘀𝗽𝗿] initial version

Created using spr 1.3.4

* Formatting

Created using spr 1.3.4

* Rename aa to blur + add comment

Created using spr 1.3.4
This commit is contained in:
Dennis Kobert 2023-04-29 23:35:30 +02:00 committed by Keavon Chambers
parent 0bd96bee1d
commit cef1cf7587

View file

@ -99,12 +99,17 @@ impl<P: Pixel + Alpha> Sample for BrushStampGenerator<P> {
fn sample(&self, position: DVec2, area: DVec2) -> Option<P> {
let position = self.transform.inverse().transform_point2(position);
let area = self.transform.inverse().transform_vector2(area);
let aa_blur_radius = area.length() as f32 * 2.;
let center = DVec2::splat(0.5);
let distance = (position + area / 2. - center).length() as f32 * 2.;
let result = if distance < 1. {
let edge_opacity = 1. - (1. - aa_blur_radius).powf(self.feather_exponent);
let result = if distance < 1. - aa_blur_radius {
1. - distance.powf(self.feather_exponent)
} else if distance < 1. {
// TODO: Replace this with a proper analytical AA implementation
edge_opacity * ((1. - distance) / aa_blur_radius)
} else {
return None;
};