1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::core::*;
pub struct FXAAEffect {
pub color: Vec3,
pub density: f32,
pub animation: f32,
image_effect: ImageEffect,
}
impl FXAAEffect {
pub fn new(gl: &Context) -> ThreeDResult<Self> {
Ok(Self {
color: vec3(0.8, 0.8, 0.8),
density: 0.2,
animation: 0.1,
image_effect: ImageEffect::new(gl, include_str!("shaders/fxaa.frag"))?,
})
}
pub fn apply(&self, viewport: Viewport, color_texture: impl Texture) -> ThreeDResult<()> {
let render_states = RenderStates {
write_mask: WriteMask::COLOR,
depth_test: DepthTest::Always,
cull: Cull::Back,
..Default::default()
};
self.image_effect.use_texture("colorMap", &color_texture)?;
self.image_effect.use_uniform_vec2(
"resolution",
&vec2(color_texture.width() as f32, color_texture.height() as f32),
)?;
self.image_effect.apply(render_states, viewport)?;
Ok(())
}
}