use crate::ZDepth;
use crate::pipeline::effects::{DitherConfig, FogConfig};
use embedded_graphics_core::pixelcolor::Rgb565;
const _: fn(crate::pipeline::effects::FogConfig) -> FogConfig = core::convert::identity;
const _: fn(crate::pipeline::effects::DitherConfig) -> DitherConfig = core::convert::identity;
pub mod blend;
pub mod depth_darken;
pub mod dither;
pub mod fog;
pub mod retro;
pub mod screen_door;
pub mod water_reflect;
pub use blend::{
fast_blend_rgb565, fast_blend_rgba8888, fast_blend_rgba8888_to_rgb565, reverse_color_rgb565,
reverse_color_rgba8888,
};
pub use depth_darken::{DepthDarkenConfig, DepthDarkenShader};
pub use dither::DitherShader;
pub use fog::FogShader;
pub use retro::{PaletteShader, ScreenTintShader};
pub use screen_door::ScreenDoorShader;
pub use water_reflect::{WaterReflectConfig, WaterReflectShader};
pub trait FragmentShader {
type Interpolants: Copy;
fn shade(&self, x: i32, y: i32, z: ZDepth, interps: Self::Interpolants) -> Rgb565;
}
#[derive(Debug, Clone, Copy)]
pub struct FlatColorShader {
pub color: Rgb565,
}
impl FragmentShader for FlatColorShader {
type Interpolants = ();
#[inline(always)]
fn shade(&self, _x: i32, _y: i32, _z: ZDepth, _interps: ()) -> Rgb565 {
self.color
}
}
#[derive(Debug, Clone, Copy)]
pub struct GouraudShader;
impl FragmentShader for GouraudShader {
type Interpolants = Rgb565;
#[inline(always)]
fn shade(&self, _x: i32, _y: i32, _z: ZDepth, color: Rgb565) -> Rgb565 {
color
}
}
#[cfg(test)]
mod tests {
use super::*;
use embedded_graphics_core::pixelcolor::{Rgb565, RgbColor};
#[test]
fn flat_color_shader_returns_constant_color() {
let shader = FlatColorShader { color: Rgb565::RED };
let out = shader.shade(5, 10, 0, ());
assert_eq!(out, Rgb565::RED);
}
#[test]
fn gouraud_shader_returns_interpolant() {
let shader = GouraudShader;
let out = shader.shade(0, 0, 0, Rgb565::BLUE);
assert_eq!(out, Rgb565::BLUE);
}
}