comparison examples/anmrenderer.rs @ 675:6be3320a1cb3

Use the same RenderState as PyTouhou in anmrenderer, and normalize color, thanks phaazon!
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 15 Aug 2019 00:26:01 +0200
parents 988e5130fb00
children ccb739c5b66c
comparison
equal deleted inserted replaced
674:3e4cc64a254d 675:6be3320a1cb3
1 use image::GenericImageView; 1 use image::GenericImageView;
2 use luminance::blending::{Equation, Factor};
2 use luminance::context::GraphicsContext; 3 use luminance::context::GraphicsContext;
3 use luminance::framebuffer::Framebuffer; 4 use luminance::framebuffer::Framebuffer;
4 use luminance::pipeline::BoundTexture; 5 use luminance::pipeline::BoundTexture;
5 use luminance::pixel::{NormRGB8UI, Floating}; 6 use luminance::pixel::{NormRGB8UI, Floating};
6 use luminance::render_state::RenderState; 7 use luminance::render_state::RenderState;
22 use std::path::Path; 23 use std::path::Path;
23 24
24 const VS: &str = r#" 25 const VS: &str = r#"
25 in ivec3 in_position; 26 in ivec3 in_position;
26 in vec2 in_texcoord; 27 in vec2 in_texcoord;
27 in uvec4 in_color; 28 in vec4 in_color;
28 29
29 uniform mat4 mvp; 30 uniform mat4 mvp;
30 31
31 out vec2 texcoord; 32 out vec2 texcoord;
32 out vec4 color; 33 out vec4 color;
34 void main() 35 void main()
35 { 36 {
36 gl_Position = mvp * vec4(vec3(in_position), 1.0); 37 gl_Position = mvp * vec4(vec3(in_position), 1.0);
37 texcoord = vec2(in_texcoord); 38 texcoord = vec2(in_texcoord);
38 39
39 // Normalized from the u8 being passed. 40 // It’s already normalized from the u8 being passed.
40 color = vec4(in_color) / 255.; 41 color = in_color;
41 } 42 }
42 "#; 43 "#;
43 44
44 const FS: &str = r#" 45 const FS: &str = r#"
45 in vec2 texcoord; 46 in vec2 texcoord;
71 #[derive(Clone, Copy, Debug, PartialEq, Vertex)] 72 #[derive(Clone, Copy, Debug, PartialEq, Vertex)]
72 #[vertex(sem = "Semantics")] 73 #[vertex(sem = "Semantics")]
73 struct Vertex { 74 struct Vertex {
74 pos: VertexPosition, 75 pos: VertexPosition,
75 uv: VertexTexcoord, 76 uv: VertexTexcoord,
77 #[vertex(normalized = "true")]
76 rgba: VertexColor, 78 rgba: VertexColor,
77 } 79 }
78 80
79 #[derive(UniformInterface)] 81 #[derive(UniformInterface)]
80 struct ShaderInterface { 82 struct ShaderInterface {
179 let mvp = view * proj; 181 let mvp = view * proj;
180 //println!("{:#?}", mvp); 182 //println!("{:#?}", mvp);
181 // TODO: check how to pass by reference. 183 // TODO: check how to pass by reference.
182 iface.mvp.update(*mvp.borrow_inner()); 184 iface.mvp.update(*mvp.borrow_inner());
183 185
184 rdr_gate.render(RenderState::default(), |tess_gate| { 186 let render_state = RenderState::default()
187 .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement));
188
189 rdr_gate.render(render_state, |tess_gate| {
185 // render the tessellation to the surface the regular way and let the vertex shader’s 190 // render the tessellation to the surface the regular way and let the vertex shader’s
186 // magic do the rest! 191 // magic do the rest!
187 tess_gate.render(&mut surface, (&tess).into()); 192 tess_gate.render(&mut surface, (&tess).into());
188 }); 193 });
189 }); 194 });
193 } 198 }
194 } 199 }
195 200
196 fn fill_vertices_ptr(sprite: Rc<RefCell<Sprite>>, vertices: *mut Vertex) { 201 fn fill_vertices_ptr(sprite: Rc<RefCell<Sprite>>, vertices: *mut Vertex) {
197 let mut fake_vertices = unsafe { std::mem::transmute::<*mut Vertex, &mut [FakeVertex; 4]>(vertices) }; 202 let mut fake_vertices = unsafe { std::mem::transmute::<*mut Vertex, &mut [FakeVertex; 4]>(vertices) };
198 sprite.borrow().fill_vertices(&mut fake_vertices); 203 sprite.borrow().fill_vertices(&mut fake_vertices, 0., 0., 0.);
199 } 204 }
200 205
201 fn fill_vertices(sprite: Rc<RefCell<Sprite>>, vertices: &mut [Vertex; 4]) { 206 fn fill_vertices(sprite: Rc<RefCell<Sprite>>, vertices: &mut [Vertex; 4]) {
202 let mut fake_vertices = unsafe { std::mem::transmute::<&mut [Vertex; 4], &mut [FakeVertex; 4]>(vertices) }; 207 let mut fake_vertices = unsafe { std::mem::transmute::<&mut [Vertex; 4], &mut [FakeVertex; 4]>(vertices) };
203 sprite.borrow().fill_vertices(&mut fake_vertices); 208 sprite.borrow().fill_vertices(&mut fake_vertices, 0., 0., 0.);
204 } 209 }
205 210
206 fn load_from_disk(surface: &mut GlfwSurface, path: &Path) -> Option<Texture<Flat, Dim2, NormRGB8UI>> { 211 fn load_from_disk(surface: &mut GlfwSurface, path: &Path) -> Option<Texture<Flat, Dim2, NormRGB8UI>> {
207 // load the texture into memory as a whole bloc (i.e. no streaming) 212 // load the texture into memory as a whole bloc (i.e. no streaming)
208 match image::open(&path) { 213 match image::open(&path) {