Do not use ImageEffect in image example
@@ -16,7 +16,6 @@ pub async fn run() {
})
.unwrap();
let context = window.gl();
- let mut image_effect = ImageEffect::new(&context, include_str!("shader.frag")).unwrap();
// Source: https://polyhaven.com/
let mut loaded = if let Ok(loaded) =
@@ -34,8 +33,13 @@ pub async fn run() {
let mut gui = GUI::new(&context);
+ let mut image_viewer = ImageViewer {
+ image,
+ tone_mapping: 1.0,
+ };
+ let mut screen_quad = ScreenQuad::new(&context);
+
// main loop
- let mut tone_mapping = 1.0;
let mut texture_transform_scale = 1.0;
let mut texture_transform_x = 0.0;
let mut texture_transform_y = 0.0;
@@ -49,7 +53,10 @@ pub async fn run() {
use three_d::egui::*;
SidePanel::left("side_panel").show(gui_context, |ui| {
ui.heading("Debug Panel");
- ui.add(Slider::new(&mut tone_mapping, 0.0..=50.0).text("Tone mapping"));
+ ui.add(
+ Slider::new(&mut image_viewer.tone_mapping, 0.0..=50.0)
+ .text("Tone mapping"),
+ );
ui.add(
Slider::new(&mut texture_transform_scale, 0.0..=10.0)
.text("Texture transform scale"),
@@ -67,7 +74,7 @@ pub async fn run() {
},
);
- image_effect.set_texture_transform(
+ screen_quad.set_texture_transform(
Mat3::from_scale(texture_transform_scale)
* Mat3::from_translation(vec2(texture_transform_x, texture_transform_y)),
);
@@ -80,13 +87,43 @@ pub async fn run() {
height: frame_input.viewport.height,
};
- frame_input.screen().clear(ClearState::default()).write(|| {
- image_effect.use_texture("image", &image);
- image_effect.use_uniform("parameter", tone_mapping);
- image_effect.apply(RenderStates::default(), viewport);
+ frame_input
+ .screen()
+ .clear(ClearState::default())
+ .render_with_material(
+ &image_viewer,
+ &camera2d(frame_input.viewport),
+ &screen_quad,
+ &[],
+ )
+ .write(|| {
gui.render(frame_input.viewport);
});
FrameOutput::default()
});
}
+
+struct ImageViewer {
+ pub image: Texture2D,
+ pub tone_mapping: f32,
+}
+
+impl Material for ImageViewer {
+ fn fragment_shader_source(&self, _use_vertex_colors: bool, lights: &[&dyn Light]) -> String {
+ include_str!("shader.frag").to_owned()
+ }
+
+ fn use_uniforms(&self, program: &Program, camera: &Camera, lights: &[&dyn Light]) {
+ program.use_texture("image", &self.image);
+ program.use_uniform("parameter", self.tone_mapping);
+ }
+
+ fn render_states(&self) -> RenderStates {
+ RenderStates::default()
+ }
+
+ fn material_type(&self) -> MaterialType {
+ MaterialType::Opaque
+ }
+}
