bevy_flash 0.1.0

A Bevy plugin for Flash Animation.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
use std::borrow::Cow;

use bevy::{
    asset::{Handle, uuid_handle},
    core_pipeline::FullscreenShader,
    ecs::{
        resource::Resource,
        system::{Commands, Res},
    },
    image::BevyDefault,
    math::{Mat4, Vec2},
    mesh::{Mesh, PrimitiveTopology, VertexBufferLayout},
    render::{
        render_resource::{
            AsBindGroup, BindGroupLayout, BindGroupLayoutEntries, BlendComponent, BlendFactor,
            BlendOperation, BlendState, BufferUsages, BufferVec, CachedRenderPipelineId,
            ColorTargetState, ColorWrites, DynamicUniformBuffer, FragmentState, FrontFace,
            MultisampleState, PipelineCache, PolygonMode, PrimitiveState, RenderPipelineDescriptor,
            Sampler, SamplerBindingType, SamplerDescriptor, ShaderStages, ShaderType,
            SpecializedMeshPipeline, TextureFormat, TextureSampleType, VertexFormat, VertexState,
            VertexStepMode,
            binding_types::{sampler, texture_2d, uniform_buffer},
        },
        renderer::{RenderDevice, RenderQueue},
        view::Msaa,
    },
    shader::Shader,
};
use bytemuck::{Pod, Zeroable};

use crate::render::material::{BitmapMaterial, ColorMaterial, GradientMaterial};

pub const OFFSCREEN_MESH2D_SHADER_HANDLE: Handle<Shader> =
    uuid_handle!("f1e2d3c4-b5a6-4978-8c9d-0e1f2a3b4c5d");

pub const OFFSCREEN_MESH2D_GRADIENT_SHADER_HANDLE: Handle<Shader> =
    uuid_handle!("a1b2c3d4-e5f6-4789-8a9b-0c1d2e3f4a5b");

pub const OFFSCREEN_MESH2D_BITMAP_SHADER_HANDLE: Handle<Shader> =
    uuid_handle!("e3f4a5b6-c7d8-4e9f-0a1b-2c3d4e5f6a7b");

pub const BLUR_FILTER_SHADER_HANDLE: Handle<Shader> =
    uuid_handle!("f59e3d1c-7a24-4b8c-82a3-1d94e6f2c705");

pub const COLOR_MATRIX_FILTER_SHADER_HANDLE: Handle<Shader> =
    uuid_handle!("1a2b3c4d-5e6f-4789-0123-456789abcdef");

pub const GLOW_FILTER_SHADER_HANDLE: Handle<Shader> =
    uuid_handle!("c1d2e3f4-a5b6-4789-0123-456789abcdef");

pub const BEVEL_FILTER_SHADER_HANDLE: Handle<Shader> =
    uuid_handle!("e2f8a9d6-3c7b-42f1-8e9d-5a6b4c3d2e1f");

bitflags::bitflags! {
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    #[repr(transparent)]
    pub struct OffscreenMesh2dKey:u16 {
        const NONE     = 0;

        const BLEND_ADD                         = 1 << 0;  // Additive blending
        const BLEND_SUBTRACT                    = 1 << 1;  // Subtractive blending
        const BLEND_SCREEN                      = 1 << 2;  // Screen blending
        const BLEND_LIGHTEN                     = 1 << 3;  // Lighten blending
        const BLEND_DARKEN                      = 1 << 4;  // Darken blending
        const BLEND_MULTIPLY                    = 1 << 5;  // Multiply blending
        const BLEND_ALPHA                       = 1 << 6;  // Alpha blending


        const COLOR    = 1 << 7;
        const GRADIENT = 1 << 8;
        const BITMAP   = 1 << 9;
        const MSAA     = 1 << 10;
    }
}

#[derive(Resource, Clone)]
pub struct OffscreenMesh2dPipeline {
    pub view_bind_group_layout: BindGroupLayout,
    pub color_bind_group_layout: BindGroupLayout,
    pub gradient_bind_group_layout: BindGroupLayout,
    pub bitmap_bind_group_layout: BindGroupLayout,
    /// 某些特殊的位图填充好像需要特殊处理,这个暂时保留
    #[allow(unused)]
    pub sampler: Sampler,
}

pub fn init_offscreen_texture_pipeline(mut commands: Commands, render_device: Res<RenderDevice>) {
    let view_bind_group_layout = render_device.create_bind_group_layout(
        "纹理变换矩阵布局",
        &BindGroupLayoutEntries::single(ShaderStages::VERTEX, uniform_buffer::<Mat4>(true)),
    );

    let color_bind_group_layout = ColorMaterial::bind_group_layout(&render_device);
    let gradient_bind_group_layout = GradientMaterial::bind_group_layout(&render_device);
    let bitmap_bind_group_layout = BitmapMaterial::bind_group_layout(&render_device);

    let sampler = render_device.create_sampler(&SamplerDescriptor::default());

    commands.insert_resource(OffscreenMesh2dPipeline {
        view_bind_group_layout,
        color_bind_group_layout,
        gradient_bind_group_layout,
        bitmap_bind_group_layout,
        sampler,
    });
}

impl SpecializedMeshPipeline for OffscreenMesh2dPipeline {
    type Key = OffscreenMesh2dKey;

    fn specialize(
        &self,
        key: Self::Key,
        layout: &bevy::mesh::MeshVertexBufferLayoutRef,
    ) -> Result<RenderPipelineDescriptor, bevy::render::render_resource::SpecializedMeshPipelineError>
    {
        let mut vertex_attributes = Vec::new();

        if layout.0.contains(Mesh::ATTRIBUTE_POSITION) {
            vertex_attributes.push(Mesh::ATTRIBUTE_POSITION.at_shader_location(0));
        }

        if layout.0.contains(Mesh::ATTRIBUTE_UV_0) {
            vertex_attributes.push(Mesh::ATTRIBUTE_UV_0.at_shader_location(1));
        }

        if layout.0.contains(Mesh::ATTRIBUTE_COLOR) {
            vertex_attributes.push(Mesh::ATTRIBUTE_COLOR.at_shader_location(2));
        }

        let vertex_buffer_layout = layout.0.get_layout(&vertex_attributes)?;
        let format = TextureFormat::bevy_default();

        let label;
        let bind_group_layout = if key.contains(OffscreenMesh2dKey::COLOR) {
            label = "color_offscreen_mesh2d";
            vec![
                self.view_bind_group_layout.clone(),
                self.color_bind_group_layout.clone(),
            ]
        } else if key.contains(OffscreenMesh2dKey::GRADIENT) {
            label = "gradient_offscreen_mesh2d";
            vec![
                self.view_bind_group_layout.clone(),
                self.gradient_bind_group_layout.clone(),
            ]
        } else {
            label = "bitmap_offscreen_mesh2d";
            vec![
                self.view_bind_group_layout.clone(),
                self.bitmap_bind_group_layout.clone(),
            ]
        };

        let shader = if key.contains(OffscreenMesh2dKey::COLOR) {
            OFFSCREEN_MESH2D_SHADER_HANDLE
        } else if key.contains(OffscreenMesh2dKey::GRADIENT) {
            OFFSCREEN_MESH2D_GRADIENT_SHADER_HANDLE
        } else if key.contains(OffscreenMesh2dKey::BITMAP) {
            OFFSCREEN_MESH2D_BITMAP_SHADER_HANDLE
        } else {
            OFFSCREEN_MESH2D_SHADER_HANDLE
        };

        let blend = if key.contains(OffscreenMesh2dKey::BLEND_ADD) {
            Some(BlendState {
                color: BlendComponent {
                    src_factor: BlendFactor::One,
                    dst_factor: BlendFactor::One,
                    operation: BlendOperation::Add,
                },
                alpha: BlendComponent::OVER,
            })
        } else if key.contains(OffscreenMesh2dKey::BLEND_MULTIPLY) {
            Some(BlendState {
                color: BlendComponent {
                    src_factor: BlendFactor::Dst,
                    dst_factor: BlendFactor::OneMinusSrcAlpha,
                    operation: BlendOperation::Add,
                },
                alpha: BlendComponent::OVER,
            })
        } else if key.contains(OffscreenMesh2dKey::BLEND_SUBTRACT) {
            Some(BlendState {
                color: BlendComponent {
                    src_factor: BlendFactor::One,
                    dst_factor: BlendFactor::One,
                    operation: BlendOperation::ReverseSubtract,
                },
                alpha: BlendComponent::OVER,
            })
        } else if key.contains(OffscreenMesh2dKey::BLEND_SCREEN) {
            Some(BlendState {
                color: BlendComponent {
                    src_factor: BlendFactor::One,
                    dst_factor: BlendFactor::OneMinusSrc,
                    operation: BlendOperation::Add,
                },
                alpha: BlendComponent::OVER,
            })
        } else if key.contains(OffscreenMesh2dKey::BLEND_LIGHTEN) {
            Some(BlendState {
                color: BlendComponent {
                    src_factor: BlendFactor::One,
                    dst_factor: BlendFactor::One,
                    operation: BlendOperation::Max,
                },
                alpha: BlendComponent::OVER,
            })
        } else if key.contains(OffscreenMesh2dKey::BLEND_DARKEN) {
            Some(BlendState {
                color: BlendComponent {
                    src_factor: BlendFactor::One,
                    dst_factor: BlendFactor::One,
                    operation: BlendOperation::Min,
                },
                alpha: BlendComponent::OVER,
            })
        } else {
            Some(BlendState::PREMULTIPLIED_ALPHA_BLENDING)
        };

        Ok(RenderPipelineDescriptor {
            label: Some(label.into()),
            layout: bind_group_layout,
            push_constant_ranges: vec![],
            vertex: VertexState {
                shader: shader.clone(),
                shader_defs: vec![],
                entry_point: Some("vertex".into()),
                buffers: vec![vertex_buffer_layout],
            },
            primitive: PrimitiveState {
                topology: PrimitiveTopology::TriangleList,
                strip_index_format: None,
                front_face: FrontFace::Ccw,
                cull_mode: None,
                unclipped_depth: false,
                polygon_mode: PolygonMode::Fill,
                conservative: false,
            },
            depth_stencil: None,
            multisample: MultisampleState {
                count: Msaa::default().samples(),
                mask: !0,
                alpha_to_coverage_enabled: false,
            },
            fragment: Some(FragmentState {
                shader,
                shader_defs: vec![],
                entry_point: Some("fragment".into()),
                targets: vec![Some(ColorTargetState {
                    format,
                    blend,
                    write_mask: ColorWrites::ALL,
                })],
            }),
            zero_initialize_workgroup_memory: false,
        })
    }
}

/// 模糊滤镜
#[repr(C)]
#[derive(Debug, Clone, Copy, Default, ShaderType, Pod, Zeroable, PartialEq)]
pub struct BlurUniform {
    pub direction: [f32; 2],
    pub full_size: f32,
    pub m: f32,
    pub m2: f32,
    pub first_weight: f32,
    pub last_offset: f32,
    pub last_weight: f32,
}

/// 颜色矩阵滤镜
#[repr(C)]
#[derive(Debug, Clone, Copy, Default, ShaderType, Pod, Zeroable, PartialEq)]
pub struct ColorMatrixUniform {
    pub matrix: [f32; 20],
}

#[repr(C)]
#[derive(Debug, Clone, Copy, Default, ShaderType, Pod, Zeroable, PartialEq)]
pub struct GlowFilterUniform {
    pub color: [f32; 4],
    pub strength: f32,
    pub inner: u32,            // a wasteful bool, but we need to be aligned anyway
    pub knockout: u32,         // a wasteful bool, but we need to be aligned anyway
    pub composite_source: u32, // undocumented flash feature, another bool
}

#[repr(C)]
#[derive(Copy, Clone, Debug, ShaderType, Pod, Zeroable, PartialEq)]
pub struct BevelUniform {
    pub highlight_color: [f32; 4],
    pub shadow_color: [f32; 4],
    pub strength: f32,
    pub bevel_type: u32,       // 0 outer, 1 inner, 2 full
    pub knockout: u32,         // a wasteful bool, but we need to be aligned anyway
    pub composite_source: u32, // undocumented flash feature, another bool
}

#[repr(C)]
#[derive(Copy, Clone, Debug, ShaderType, Pod, Zeroable, PartialEq)]
pub struct FilterVertexWithDoubleBlur {
    pub position: [f32; 2],
    pub source_uv: [f32; 2],
    pub blur_uv_left: [f32; 2],
    pub blur_uv_right: [f32; 2],
}

#[derive(Resource)]
pub struct BlurFilterPipeline {
    pub layout: BindGroupLayout,
    pub sampler: Sampler,
    pub pipeline_id: CachedRenderPipelineId,
}

pub(crate) fn init_blur_filter_pipeline(
    mut commands: Commands,
    render_device: Res<RenderDevice>,
    pipeline_cache: Res<PipelineCache>,
    fullscreen_shader: Res<FullscreenShader>,
) {
    let layout = render_device.create_bind_group_layout(
        "blur_filter_bind_group_layout",
        &BindGroupLayoutEntries::sequential(
            ShaderStages::FRAGMENT,
            (
                texture_2d(TextureSampleType::Float { filterable: true }),
                sampler(SamplerBindingType::Filtering),
                uniform_buffer::<BlurUniform>(false),
            ),
        ),
    );

    let sampler = render_device.create_sampler(&SamplerDescriptor::default());

    let descriptor = RenderPipelineDescriptor {
        label: Some(Cow::from("blur_filter_render_pipeline")),
        layout: vec![layout.clone()],
        push_constant_ranges: vec![],
        vertex: fullscreen_shader.to_vertex_state(),
        primitive: PrimitiveState::default(),
        depth_stencil: None,
        multisample: MultisampleState::default(),
        fragment: Some(FragmentState {
            shader: BLUR_FILTER_SHADER_HANDLE,
            shader_defs: vec![],
            entry_point: Some("fragment".into()),
            targets: vec![Some(ColorTargetState {
                format: TextureFormat::bevy_default(),
                blend: None,
                write_mask: ColorWrites::ALL,
            })],
        }),
        zero_initialize_workgroup_memory: false,
    };

    let pipeline_id = pipeline_cache.queue_render_pipeline(descriptor);

    commands.insert_resource(BlurFilterPipeline {
        layout,
        sampler,
        pipeline_id,
    });
}

#[derive(Resource)]
pub struct ColorMatrixFilterPipeline {
    pub layout: BindGroupLayout,
    pub sampler: Sampler,
    pub pipeline_id: CachedRenderPipelineId,
}

pub(crate) fn init_color_matrix_filter_pipeline(
    mut commands: Commands,
    render_device: Res<RenderDevice>,
    pipeline_cache: Res<PipelineCache>,
    fullscreen_shader: Res<FullscreenShader>,
) {
    let layout = render_device.create_bind_group_layout(
        "color_matrix_bind_group_layout",
        &BindGroupLayoutEntries::sequential(
            ShaderStages::FRAGMENT,
            (
                texture_2d(TextureSampleType::Float { filterable: true }),
                sampler(SamplerBindingType::Filtering),
                uniform_buffer::<ColorMatrixUniform>(false),
            ),
        ),
    );
    let sampler = render_device.create_sampler(&SamplerDescriptor::default());

    let descriptor = RenderPipelineDescriptor {
        label: Some(Cow::from("color_matrix_filter_render_pipeline")),
        layout: vec![layout.clone()],
        push_constant_ranges: vec![],
        vertex: fullscreen_shader.to_vertex_state(),
        primitive: PrimitiveState::default(),
        depth_stencil: None,
        multisample: MultisampleState::default(),
        fragment: Some(FragmentState {
            shader: COLOR_MATRIX_FILTER_SHADER_HANDLE,
            shader_defs: vec![],
            entry_point: Some("fragment".into()),
            targets: vec![Some(ColorTargetState {
                format: TextureFormat::bevy_default(),
                blend: None,
                write_mask: ColorWrites::ALL,
            })],
        }),
        zero_initialize_workgroup_memory: false,
    };

    let pipeline_id = pipeline_cache.queue_render_pipeline(descriptor);

    commands.insert_resource(ColorMatrixFilterPipeline {
        layout,
        sampler,
        pipeline_id,
    });
}

#[derive(Resource)]
pub struct GlowFilterPipeline {
    pub layout: BindGroupLayout,
    pub sampler: Sampler,
    pub pipeline_id: CachedRenderPipelineId,
}

pub(crate) fn init_glow_filter_pipeline(
    mut commands: Commands,
    render_device: Res<RenderDevice>,
    pipeline_cache: Res<PipelineCache>,
    fullscreen_shader: Res<FullscreenShader>,
) {
    let layout = render_device.create_bind_group_layout(
        "glow_filter_bind_group_layout",
        &BindGroupLayoutEntries::sequential(
            ShaderStages::FRAGMENT,
            (
                texture_2d(TextureSampleType::Float { filterable: true }),
                sampler(SamplerBindingType::Filtering),
                uniform_buffer::<GlowFilterUniform>(false),
                texture_2d(TextureSampleType::Float { filterable: true }),
            ),
        ),
    );
    let sampler = render_device.create_sampler(&SamplerDescriptor::default());

    let descriptor = RenderPipelineDescriptor {
        label: Some(Cow::from("glow_filter_filter_render_pipeline")),
        layout: vec![layout.clone()],
        push_constant_ranges: vec![],
        vertex: fullscreen_shader.to_vertex_state(),
        primitive: PrimitiveState::default(),
        depth_stencil: None,
        multisample: MultisampleState::default(),
        fragment: Some(FragmentState {
            shader: GLOW_FILTER_SHADER_HANDLE,
            shader_defs: vec![],
            entry_point: Some("fragment".into()),
            targets: vec![Some(ColorTargetState {
                format: TextureFormat::bevy_default(),
                blend: None,
                write_mask: ColorWrites::ALL,
            })],
        }),
        zero_initialize_workgroup_memory: false,
    };

    let pipeline_id = pipeline_cache.queue_render_pipeline(descriptor);

    commands.insert_resource(GlowFilterPipeline {
        layout,
        sampler,
        pipeline_id,
    });
}

#[derive(Resource)]
pub struct BevelFilterPipeline {
    pub layout: BindGroupLayout,
    pub sampler: Sampler,
    pub pipeline_id: CachedRenderPipelineId,
}

pub(crate) fn init_bevel_filter_pipeline(
    mut commands: Commands,
    render_device: Res<RenderDevice>,
    pipeline_cache: Res<PipelineCache>,
) {
    let layout = render_device.create_bind_group_layout(
        "glow_filter_bind_group_layout",
        &BindGroupLayoutEntries::sequential(
            ShaderStages::FRAGMENT,
            (
                texture_2d(TextureSampleType::Float { filterable: true }),
                sampler(SamplerBindingType::Filtering),
                uniform_buffer::<BevelUniform>(false),
                texture_2d(TextureSampleType::Float { filterable: true }),
            ),
        ),
    );
    let sampler = render_device.create_sampler(&SamplerDescriptor::default());

    let descriptor = RenderPipelineDescriptor {
        label: Some(Cow::from("bevel_filter_render_pipeline")),
        layout: vec![layout.clone()],
        push_constant_ranges: vec![],
        vertex: VertexState {
            shader: BEVEL_FILTER_SHADER_HANDLE,
            shader_defs: vec![],
            entry_point: Some("vertex".into()),
            buffers: vec![VertexBufferLayout::from_vertex_formats(
                VertexStepMode::Vertex,
                vec![
                    VertexFormat::Float32x2,
                    VertexFormat::Float32x2,
                    VertexFormat::Float32x2,
                    VertexFormat::Float32x2,
                ],
            )],
        },
        primitive: PrimitiveState::default(),
        depth_stencil: None,
        multisample: MultisampleState::default(),
        fragment: Some(FragmentState {
            shader: BEVEL_FILTER_SHADER_HANDLE,
            shader_defs: vec![],
            entry_point: Some("fragment".into()),
            targets: vec![Some(ColorTargetState {
                format: TextureFormat::bevy_default(),
                blend: None,
                write_mask: ColorWrites::ALL,
            })],
        }),
        zero_initialize_workgroup_memory: false,
    };

    let pipeline_id = pipeline_cache.queue_render_pipeline(descriptor);

    commands.insert_resource(BevelFilterPipeline {
        layout,
        sampler,
        pipeline_id,
    });
}

#[derive(Resource)]
pub struct FilterUniformBuffers {
    pub view_uniform_buffer: DynamicUniformBuffer<Mat4>,
    pub color_matrix_uniform_buffer: DynamicUniformBuffer<ColorMatrixUniform>,
    pub blur_uniform_buffer: DynamicUniformBuffer<BlurUniform>,
    pub glow_uniform_buffer: DynamicUniformBuffer<GlowFilterUniform>,
    pub bevel_uniform_buffer: DynamicUniformBuffer<BevelUniform>,
    pub filter_vertex_with_double_blur_buffer: BufferVec<FilterVertexWithDoubleBlur>,
}

impl Default for FilterUniformBuffers {
    fn default() -> Self {
        Self {
            view_uniform_buffer: DynamicUniformBuffer::default(),
            color_matrix_uniform_buffer: DynamicUniformBuffer::default(),
            blur_uniform_buffer: DynamicUniformBuffer::default(),
            glow_uniform_buffer: DynamicUniformBuffer::default(),
            bevel_uniform_buffer: DynamicUniformBuffer::default(),
            filter_vertex_with_double_blur_buffer: BufferVec::new(BufferUsages::VERTEX),
        }
    }
}

impl FilterUniformBuffers {
    pub fn clear(&mut self) {
        self.view_uniform_buffer.clear();
        self.color_matrix_uniform_buffer.clear();
        self.blur_uniform_buffer.clear();
        self.glow_uniform_buffer.clear();
        self.bevel_uniform_buffer.clear();
        self.filter_vertex_with_double_blur_buffer.clear();
    }

    pub fn write_buffer(&mut self, device: &RenderDevice, queue: &RenderQueue) {
        self.view_uniform_buffer.write_buffer(device, queue);
        self.color_matrix_uniform_buffer.write_buffer(device, queue);
        self.blur_uniform_buffer.write_buffer(device, queue);
        self.glow_uniform_buffer.write_buffer(device, queue);
        self.bevel_uniform_buffer.write_buffer(device, queue);
        self.filter_vertex_with_double_blur_buffer
            .write_buffer(device, queue);
    }
}

pub fn get_filter_vertex_with_double_blur(
    distance: f32,
    angle: f32,
    size: Vec2,
) -> Vec<FilterVertexWithDoubleBlur> {
    let blur_offset_x = angle.cos() * distance;
    let blur_offset_y = angle.sin() * distance;
    let width = size.x;
    let height = size.y;
    vec![
        FilterVertexWithDoubleBlur {
            position: [0.0, 0.0],
            source_uv: [0.0, 0.0],
            blur_uv_left: [blur_offset_x / width, blur_offset_y / height],
            blur_uv_right: [
                (0.0 - blur_offset_x) / width,
                (0.0 - blur_offset_y) / height,
            ],
        },
        FilterVertexWithDoubleBlur {
            position: [1.0, 0.0],
            source_uv: [1.0, 0.0],
            blur_uv_left: [(width + blur_offset_x) / width, blur_offset_y / height],
            blur_uv_right: [
                (width - blur_offset_x) / width,
                (0.0 - blur_offset_y) / height,
            ],
        },
        FilterVertexWithDoubleBlur {
            position: [1.0, 1.0],
            source_uv: [1.0, 1.0],
            blur_uv_left: [
                (width + blur_offset_x) / width,
                (height + blur_offset_y) / height,
            ],
            blur_uv_right: [
                (width - blur_offset_x) / width,
                (height - blur_offset_y) / height,
            ],
        },
        FilterVertexWithDoubleBlur {
            position: [0.0, 1.0],
            source_uv: [0.0, 1.0],
            blur_uv_left: [blur_offset_x / width, (blur_offset_y + height) / height],
            blur_uv_right: [
                (0.0 - blur_offset_x) / width,
                (height - blur_offset_y) / height,
            ],
        },
    ]
}