35 morph_type_ = morph_type;
38 std::optional<Entity> DirectionalMorphologyFilterContents::RenderFilter(
42 const Matrix& effect_transform,
44 const std::optional<Rect>& coverage_hint)
const {
56 auto input_snapshot = inputs[0]->GetSnapshot(
"Morphology", renderer, entity);
57 if (!input_snapshot.has_value()) {
65 auto maybe_input_uvs = input_snapshot->GetCoverageUVs(coverage);
66 if (!maybe_input_uvs.has_value()) {
69 auto input_uvs = maybe_input_uvs.value();
77 auto& host_buffer = renderer.GetTransientsBuffer();
79 std::array<VS::PerVertexData, 4> vertices = {
80 VS::PerVertexData{
Point(0, 0), input_uvs[0]},
81 VS::PerVertexData{
Point(1, 0), input_uvs[1]},
82 VS::PerVertexData{
Point(0, 1), input_uvs[2]},
83 VS::PerVertexData{
Point(1, 1), input_uvs[3]},
86 VS::FrameInfo frame_info;
88 frame_info.texture_sampler_y_coord_scale =
89 input_snapshot->texture->GetYCoordScale();
92 auto transformed_radius =
94 auto transformed_texture_vertices =
97 auto transformed_texture_width =
98 transformed_texture_vertices[0].GetDistance(
99 transformed_texture_vertices[1]);
100 auto transformed_texture_height =
101 transformed_texture_vertices[0].GetDistance(
102 transformed_texture_vertices[2]);
104 FS::FragInfo frag_info;
105 frag_info.radius = std::round(transformed_radius.GetLength());
106 frag_info.morph_type =
static_cast<Scalar>(morph_type_);
107 frag_info.uv_offset =
108 input_snapshot->transform.Invert()
109 .TransformDirection(transformed_radius)
111 Point(transformed_texture_width, transformed_texture_height);
113 pass.SetCommandLabel(
"Morphology Filter");
117 pass.SetPipeline(renderer.GetMorphologyFilterPipeline(options));
120 auto sampler_descriptor = input_snapshot->sampler_descriptor;
121 if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
126 FS::BindTextureSampler(
127 pass, input_snapshot->texture,
128 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
129 sampler_descriptor));
130 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
131 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
133 return pass.Draw().ok();
135 std::shared_ptr<CommandBuffer> command_buffer =
136 renderer.GetContext()->CreateCommandBuffer();
137 if (command_buffer ==
nullptr) {
141 fml::StatusOr<RenderTarget> render_target =
142 renderer.MakeSubpass(
"Directional Morphology Filter",
149 if (!render_target.ok()) {
153 if (!renderer.GetContext()->EnqueueCommandBuffer(std::move(command_buffer))) {
157 SamplerDescriptor sampler_desc;
162 Snapshot{.texture = render_target.value().GetRenderTargetTexture(),
164 .sampler_descriptor = sampler_desc,
165 .opacity = input_snapshot->opacity},
172 const Matrix& effect_transform)
const {
173 if (inputs.empty()) {
177 auto coverage = inputs[0]->GetCoverage(entity);
178 if (!coverage.has_value()) {
181 auto transform = inputs[0]->GetTransform(entity) * effect_transform.
Basis();
182 auto transformed_vector =
187 switch (morph_type_) {
189 origin -= transformed_vector;
190 size += transformed_vector * 2;
193 origin += transformed_vector;
194 size -= transformed_vector * 2;
197 if (size.x < 0 || size.y < 0) {
205 const Matrix& effect_transform,
206 const Rect& output_limit)
const {
207 auto transformed_vector =
209 switch (morph_type_) {
211 return output_limit.
Expand(-transformed_vector);
213 return output_limit.
Expand(transformed_vector);
std::function< bool(const ContentContext &, RenderPass &)> SubpassCallback
DirectionalMorphologyFilterContents()
void SetRadius(Radius radius)
std::optional< Rect > GetFilterCoverage(const FilterInput::Vector &inputs, const Entity &entity, const Matrix &effect_transform) const override
Internal utility method for |GetLocalCoverage| that computes the output coverage of this filter acros...
void SetMorphType(MorphType morph_type)
std::optional< Rect > GetFilterSourceCoverage(const Matrix &effect_transform, const Rect &output_limit) const override
Internal utility method for |GetSourceCoverage| that computes the inverse effect of this transform on...
~DirectionalMorphologyFilterContents() override
void SetDirection(Vector2 direction)
BlendMode GetBlendMode() const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
static Entity FromSnapshot(const Snapshot &snapshot, BlendMode blend_mode=BlendMode::kSrcOver)
Create an entity that can be used to render a given snapshot.
VertexShader_ VertexShader
FragmentShader_ FragmentShader
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
constexpr float kEhCloseEnough
LinePipeline::FragmentShader FS
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &host_buffer)
Create an index-less vertex buffer from a fixed size array.
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPass(const RenderPass &pass)
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeOrthographic(TSize< T > size)
static constexpr Matrix MakeTranslation(const Vector3 &t)
constexpr Matrix Basis() const
The Matrix without its w components (without translation).
constexpr Vector4 TransformDirection(const Vector4 &v) const
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
constexpr TPoint Normalize() const
constexpr bool IsZero() const
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
constexpr TPoint< Type > GetOrigin() const
Returns the upper left corner of the rectangle as specified by the left/top or x/y values when it was...
constexpr static TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
constexpr static TRect MakeSize(const TSize< U > &size)