28 std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
32 const Matrix& effect_transform,
34 const std::optional<Rect>& coverage_hint)
const {
46 auto input_snapshot = inputs[0]->GetSnapshot(
"ColorMatrix", renderer, entity);
47 if (!input_snapshot.has_value()) {
54 RenderProc render_proc = [input_snapshot, color_matrix = matrix_,
56 const ContentContext& renderer,
57 const Entity& entity, RenderPass& pass) ->
bool {
58 pass.SetCommandLabel(
"Color Matrix Filter");
59 pass.SetStencilReference(entity.GetClipDepth());
63 pass.SetPipeline(renderer.GetColorMatrixColorFilterPipeline(options));
65 auto size = input_snapshot->texture->GetSize();
67 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
68 vtx_builder.AddVertices({
74 auto& host_buffer = renderer.GetTransientsBuffer();
75 pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
77 VS::FrameInfo frame_info;
79 entity.GetShaderClipDepth(), pass,
80 entity.GetTransform() * input_snapshot->transform *
82 frame_info.texture_sampler_y_coord_scale =
83 input_snapshot->texture->GetYCoordScale();
85 FS::FragInfo frag_info;
86 const float* matrix = color_matrix.array;
87 frag_info.color_v = Vector4(matrix[4], matrix[9], matrix[14], matrix[19]);
89 frag_info.color_m = Matrix(
90 matrix[0], matrix[5], matrix[10], matrix[15],
91 matrix[1], matrix[6], matrix[11], matrix[16],
92 matrix[2], matrix[7], matrix[12], matrix[17],
93 matrix[3], matrix[8], matrix[13], matrix[18]
96 frag_info.input_alpha =
98 ? input_snapshot->opacity
100 const std::unique_ptr<const Sampler>& sampler =
101 renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
102 FS::BindInputTexture(pass, input_snapshot->texture, sampler);
103 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
105 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
107 return pass.Draw().ok();
111 [coverage](
const Entity& entity) -> std::optional<Rect> {
118 sub_entity.SetContents(std::move(contents));
119 sub_entity.SetClipDepth(entity.GetClipDepth());
120 sub_entity.SetBlendMode(entity.GetBlendMode());