gemini_engine/containers/shader.rs
1use crate::{containers::PixelContainer, primitives::Pixel};
2
3/// To write a shader you must have a struct that implements this shader
4pub trait CanShade {
5 /// This function accepts a pixel and returns the adjusted pixel, as you wish to adjust it
6 fn shade(&mut self, pixel: Pixel) -> Pixel;
7}
8
9impl PixelContainer {
10 /// Applies the shader to the `PixelContainer`'s active pixels. A "shader" in this case is any object which implements [`CanShade`]
11 #[must_use]
12 pub fn shade_with(mut self, shader: &mut Box<dyn CanShade>) -> Self {
13 self.pixels.iter_mut().for_each(|p| *p = shader.shade(*p));
14 self
15 }
16}