Skip to main content

post_effects

Macro post_effects 

Source
macro_rules! post_effects {
    ($(#[$attribute:meta])* $vis:vis enum $set:ident { $($effect:ident),+ $(,)? }) => { ... };
}
Expand description

Writes the set of every post effect a game passes its frame through: an enum with one variant wrapping each named type, which Game::PostEffects names.

Each type is spelled by its own name and must be in scope; a set that holds a type twice does not compile. EffectStage orders the effects first and the order the set lists them second, so two effects in one stage run in that order. A pub before enum makes the enum public, and /// lines before that are the enum’s.

use mirage_engine::prelude::*;

#[derive(ShaderValues)]
struct Grain {
    strength: f32,
}

impl PostEffect for Grain {
    const STAGE: EffectStage = EffectStage::ToneMapped;
    const SHADER: &'static str = "
        fn draw(pixel: Pixel) -> vec4<f32> {
            let noise = fract(sin(pixel.position.x + pixel.position.y) * 43758.5453);
            return vec4<f32>(pixel.color.rgb + noise * effect.strength, pixel.color.a);
        }";
}

post_effects! { enum Look { Grain } }