Rotating filter
This commit is contained in:
parent
05ecbbbbec
commit
5ac4b4711c
6 changed files with 58 additions and 24 deletions
|
|
@ -1,20 +1,48 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_rapier2d::prelude::*;
|
||||
|
||||
#[derive(Component, Default)]
|
||||
pub struct FilterColor(pub Color);
|
||||
|
||||
#[derive(Component)]
|
||||
pub enum PassThroughFilter {
|
||||
Absorbing,
|
||||
/// Absorbs this color (ignoring alpha)
|
||||
Absorbing(Color),
|
||||
/// Rotates hue by this angle (in degrees)
|
||||
Rotating(f32),
|
||||
}
|
||||
|
||||
impl PassThroughFilter {
|
||||
pub fn apply(&self, color: Color) -> Color {
|
||||
match self {
|
||||
PassThroughFilter::Absorbing(filter_color) => Vec4::from(color)
|
||||
.mul_add(
|
||||
-Vec4::from(*filter_color) * Vec4::from([1., 1., 1., 0.]),
|
||||
Vec4::from(color),
|
||||
)
|
||||
.into(),
|
||||
PassThroughFilter::Rotating(filter_angle) => {
|
||||
let mut hsla = color.as_hsla_f32();
|
||||
hsla[0] = (hsla[0] + filter_angle) % 360.;
|
||||
Color::hsla(hsla[0], hsla[1], hsla[2], hsla[3])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
pub struct AbsorbingFilter {
|
||||
pub color: FilterColor,
|
||||
#[bundle]
|
||||
pub mesh: ColorMesh2dBundle,
|
||||
pub collider: Collider,
|
||||
pub sensor: Sensor,
|
||||
pub filter_type: PassThroughFilter,
|
||||
pub filter: PassThroughFilter,
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
pub struct RotatingFilter {
|
||||
#[bundle]
|
||||
pub sprite: SpriteBundle,
|
||||
pub collider: Collider,
|
||||
pub sensor: Sensor,
|
||||
pub filter: PassThroughFilter,
|
||||
pub velocity: Velocity,
|
||||
pub rigid_body: RigidBody,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue