impl EffectMaterial for FXAA
-use crate::core::*;
+use crate::renderer::*;
///
/// A simple anti-aliasing approach which smooths otherwise jagged edges (for example lines) but also
/// smooths the rest of the image.
///
pub struct FXAAEffect {
- image_effect: ImageEffect,
+ context: Context,
}
impl FXAAEffect {
@@ -14,28 +14,38 @@ impl FXAAEffect {
///
pub fn new(context: &Context) -> Self {
Self {
- image_effect: ImageEffect::new(context, include_str!("shaders/fxaa.frag")).unwrap(),
+ context: context.clone(),
+ }
}
}
- ///
- /// Applies the FXAA effect to the image in the given texture and writes the result to the given viewport of the current render target.
- /// Must be called in the callback given as input to a [RenderTarget], [ColorTarget] or [DepthTarget] write method.
- ///
- pub fn apply(&self, viewport: Viewport, texture: &Texture2D) {
- let render_states = RenderStates {
- write_mask: WriteMask::COLOR,
- depth_test: DepthTest::Always,
- cull: Cull::Back,
- ..Default::default()
- };
+impl EffectMaterial for FXAAEffect {
+ fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String {
+ include_str!("shaders/fxaa.frag").to_owned()
+ }
- self.image_effect.use_texture("colorMap", &texture);
- self.image_effect.use_uniform(
+ fn use_uniforms(
+ &self,
+ program: &Program,
+ _camera: &Camera,
+ _lights: &[&dyn Light],
+ color_texture: Option<&Texture2D>,
+ _depth_texture: Option<&DepthTargetTexture2D>,
+ ) {
+ let texture = color_texture.expect("Must supply a color texture to apply a fog effect");
+ program.use_texture("colorMap", texture);
+ program.use_uniform(
"resolution",
vec2(texture.width() as f32, texture.height() as f32),
);
+ }
- self.image_effect.apply(render_states, viewport);
+ fn render_states(&self) -> RenderStates {
+ RenderStates {
+ write_mask: WriteMask::COLOR,
+ depth_test: DepthTest::Always,
+ cull: Cull::Back,
+ ..Default::default()
+ }
}
}
