Possible to enable/disable fog in effect example
@@ -22,6 +22,7 @@ async fn run() {
let mut fog_effect = effects::FogEffect::new(&gl).unwrap();
fog_effect.color = vec3(0.8, 0.8, 0.8);
+ let mut fog_enabled = true;
let fxaa_effect = effects::FXAAEffect::new(&gl).unwrap();
let mut fxaa_enabled = true;
@@ -52,6 +53,11 @@ async fn run() {
println!("{:?}", renderer.debug_type());
}
if kind == "F" && *state == State::Pressed
+ {
+ fog_enabled = !fog_enabled;
+ println!("Fog: {:?}", fog_enabled);
+ }
+ if kind == "X" && *state == State::Pressed
{
fxaa_enabled = !fxaa_enabled;
println!("FXAA: {:?}", fxaa_enabled);
@@ -67,23 +73,22 @@ async fn run() {
monkey.render(&transformation, &camera);
}).unwrap();
- if fxaa_enabled {
- let color_texture = Texture2D::new(&gl, width, height, Interpolation::Nearest,
- Interpolation::Nearest, None, Wrapping::ClampToEdge, Wrapping::ClampToEdge, Format::RGBA8).unwrap();
- RenderTarget::write_to_color(&gl,0, 0, width, height,Some(&vec4(0.0, 0.0, 0.0, 0.0)), Some(&color_texture), &||
- {
+ let render = || {
renderer.light_pass(&camera, Some(&ambient_light), &[&directional_light], &[], &[]).unwrap();
+ if fog_enabled {
fog_effect.apply(time as f32, &camera, renderer.geometry_pass_depth_texture()).unwrap();
- }).unwrap();
+ }
+ };
+ if fxaa_enabled {
+ let color_texture = Texture2D::new(&gl, width, height, Interpolation::Nearest,
+ Interpolation::Nearest, None, Wrapping::ClampToEdge, Wrapping::ClampToEdge, Format::RGBA8).unwrap();
+ RenderTarget::write_to_color(&gl,0, 0, width, height,Some(&vec4(0.0, 0.0, 0.0, 0.0)), Some(&color_texture), &render).unwrap();
Screen::write(&gl, 0, 0, width, height, Some(&vec4(0.0, 0.0, 0.0, 1.0)), None, &|| {
fxaa_effect.apply(&color_texture).unwrap();
}).unwrap();
} else {
- Screen::write(&gl, 0, 0, width, height, Some(&vec4(0.0, 0.0, 0.0, 1.0)), None, &|| {
- renderer.light_pass(&camera, Some(&ambient_light), &[&directional_light], &[], &[]).unwrap();
- fog_effect.apply(time as f32, &camera, renderer.geometry_pass_depth_texture()).unwrap();
- }).unwrap();
+ Screen::write(&gl, 0, 0, width, height, Some(&vec4(0.0, 0.0, 0.0, 1.0)), None, &render).unwrap();
}
if let Some(ref path) = screenshot_path {
