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 {
60 cmd.stencil_reference = entity.GetStencilDepth();
63 cmd.pipeline = renderer.GetColorMatrixColorFilterPipeline(options);
65 auto size = input_snapshot->texture->GetSize();
67 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
68 vtx_builder.AddVertices({
76 auto& host_buffer = pass.GetTransientsBuffer();
77 auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
78 cmd.BindVertices(vtx_buffer);
80 VS::FrameInfo frame_info;
82 entity.GetTransformation() * input_snapshot->transform *
84 frame_info.texture_sampler_y_coord_scale =
85 input_snapshot->texture->GetYCoordScale();
87 FS::FragInfo frag_info;
88 const float* matrix = color_matrix.array;
89 frag_info.color_v = Vector4(matrix[4], matrix[9], matrix[14], matrix[19]);
91 frag_info.color_m = Matrix(
92 matrix[0], matrix[5], matrix[10], matrix[15],
93 matrix[1], matrix[6], matrix[11], matrix[16],
94 matrix[2], matrix[7], matrix[12], matrix[17],
95 matrix[3], matrix[8], matrix[13], matrix[18]
98 frag_info.input_alpha =
100 ? input_snapshot->opacity
102 auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
103 FS::BindInputTexture(cmd, input_snapshot->texture, sampler);
104 FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
106 VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
108 return pass.AddCommand(std::move(cmd));
112 [coverage](
const Entity& entity) -> std::optional<Rect> {
119 sub_entity.SetContents(std::move(contents));
120 sub_entity.SetStencilDepth(entity.GetStencilDepth());
121 sub_entity.SetBlendMode(entity.GetBlendMode());