From 28878dc345728b7b665cc402626a79568fb9ec82 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Mon, 5 Aug 2019 18:26:43 -0700 Subject: [PATCH] fixed minor regression, cleaned up source tree --- {src => resources/examples}/vulkan_example.rs | 0 .../examples}/vulkano_img_example.rs | 0 resources/shaders/color-passthrough.fragment | 21 ++++ resources/shaders/color-passthrough.vertex | 13 ++ resources/shaders/simple_texture.fragment | 1 + resources/shaders/simple_texture.vertex | 2 + src/vkprocessor.rs | 2 +- src/vkprocessor/shader_kernels.rs | 2 +- src/workpiece.rs | 114 ------------------ 9 files changed, 39 insertions(+), 116 deletions(-) rename {src => resources/examples}/vulkan_example.rs (100%) rename {src => resources/examples}/vulkano_img_example.rs (100%) create mode 100644 resources/shaders/color-passthrough.fragment create mode 100644 resources/shaders/color-passthrough.vertex delete mode 100644 src/workpiece.rs diff --git a/src/vulkan_example.rs b/resources/examples/vulkan_example.rs similarity index 100% rename from src/vulkan_example.rs rename to resources/examples/vulkan_example.rs diff --git a/src/vulkano_img_example.rs b/resources/examples/vulkano_img_example.rs similarity index 100% rename from src/vulkano_img_example.rs rename to resources/examples/vulkano_img_example.rs diff --git a/resources/shaders/color-passthrough.fragment b/resources/shaders/color-passthrough.fragment new file mode 100644 index 00000000..69fef39f --- /dev/null +++ b/resources/shaders/color-passthrough.fragment @@ -0,0 +1,21 @@ +#version 450 +layout(location = 0) in vec2 tex_coords; +layout(location = 1) in vec4 out_color; + +layout(location = 0) out vec4 f_color; + +layout(set = 0, binding = 0) uniform sampler2D tex; +layout(set = 0, binding = 1, rgba32ui) readonly uniform uimage2D img; + +void main() { + + ivec2 pos = ivec2(gl_FragCoord.x, gl_FragCoord.y); + + f_color = imageLoad(img, ivec2(pos)) / (255.0); + + float gamma = 0.5; + f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma)); + + //f_color = out_color; + // f_color = texture(tex, tex_coords); +} \ No newline at end of file diff --git a/resources/shaders/color-passthrough.vertex b/resources/shaders/color-passthrough.vertex new file mode 100644 index 00000000..b4dbeee7 --- /dev/null +++ b/resources/shaders/color-passthrough.vertex @@ -0,0 +1,13 @@ +#version 450 +layout(location = 0) in vec2 position; +layout(location = 1) in vec4 color; + +layout(location = 0) out vec2 tex_coords; +layout(location = 1) out vec4 out_color; + +void main() { + out_color = color; + + gl_Position = vec4(position, 0.0, 1.0); + tex_coords = position; +} diff --git a/resources/shaders/simple_texture.fragment b/resources/shaders/simple_texture.fragment index cbb68575..07fcc053 100644 --- a/resources/shaders/simple_texture.fragment +++ b/resources/shaders/simple_texture.fragment @@ -16,5 +16,6 @@ void main() { float gamma = 0.5; f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma)); + //f_color = out_color; // f_color = texture(tex, tex_coords); } \ No newline at end of file diff --git a/resources/shaders/simple_texture.vertex b/resources/shaders/simple_texture.vertex index 21ee14a0..ebac0b4f 100644 --- a/resources/shaders/simple_texture.vertex +++ b/resources/shaders/simple_texture.vertex @@ -6,6 +6,8 @@ layout(location = 0) out vec2 tex_coords; layout(location = 1) out vec4 out_color; void main() { + out_color = color; + gl_Position = vec4(position, 0.0, 1.0); tex_coords = position; } diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index 6d8561c4..19043c8a 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -301,7 +301,7 @@ impl<'a> VkProcessor<'a> { println!("Allocating Buffers..."); - let color = [0.,0.,0.,0.]; + let color = [1.,0.,0.,0.]; let vertex_buffer = { diff --git a/src/vkprocessor/shader_kernels.rs b/src/vkprocessor/shader_kernels.rs index b4f44624..4bfe81e4 100644 --- a/src/vkprocessor/shader_kernels.rs +++ b/src/vkprocessor/shader_kernels.rs @@ -244,7 +244,7 @@ impl ShaderKernels { third_constant: 0.0, }) // The content of the vertex buffer describes a list of triangles. - .triangle_list_with_adjacency() + .triangle_fan() // Use a resizable viewport set to draw over the entire window .viewports_dynamic_scissors_irrelevant(1) // See `vertex_shader`. diff --git a/src/workpiece.rs b/src/workpiece.rs deleted file mode 100644 index b9984c3d..00000000 --- a/src/workpiece.rs +++ /dev/null @@ -1,114 +0,0 @@ -use sfml::graphics::{Texture, Sprite, IntRect, Drawable, RenderTarget, RenderStates}; -use sfml::system::Vector2u; -use sfml::graphics::Transformable; - -//pub struct Thing<'a> { -// -// loader: WorkpieceLoader, -// workpiece: Workpiece<'a> -// -//} -// -//impl<'a> Thing<'a> { -// -// pub fn new(pixels: Vec) -> Thing<'a> { -// -// let mut workpieceloader = WorkpieceLoader::new(String::from("resources/images/funky-bird.jpg")); -// workpieceloader.load_first_stage(pixels); -// -// let mut workpiece = Workpiece::new(); -// workpiece.load_first_stage(&mut workpieceloader.first_stage_texture); -// -// Thing { -// loader: workpieceloader, -// workpiece: workpiece -// } -// } -//} - -/* - - - first_thing = Thing1::new(); - second_thing = Thing1::new(); - - let mut container_thing = Thing2::new(); - - container_thing.field = &mut first_thing; - container_thing.field = &mut second_thing; - - first_thing.field = 10; - - - - - -*/ - -#[derive(Clone)] -pub struct WorkpieceLoader { - pub swatch_texture: Texture, - pub first_stage_texture: Texture, - pub xy: Vector2u, - pub vec: Vec, -} - -impl WorkpieceLoader { - - pub fn new(filepath: String) -> WorkpieceLoader { - - let texture = Texture::from_file(filepath.as_str()).expect("Couldn't load image"); - let xy = texture.size(); - - WorkpieceLoader { - swatch_texture: texture, - first_stage_texture: Texture::new(xy.x, xy.y).unwrap(), - xy: xy, - vec: vec![] - } - } - - pub fn load_first_stage(&mut self, pixels: Vec) { - self.vec.clear(); - let mut t = Texture::new(self.xy.x, self.xy.y).expect("Couldn't load image"); - t.update_from_pixels(pixels.as_slice(), self.xy.x, self.xy.y, 0, 0); - self.vec.push(t); - - } - - pub fn get_first(&mut self) -> &Texture { - &self.first_stage_texture - } -} - -pub struct Workpiece<'a> { - pub render_sprite: Sprite<'a> -} - -impl<'a> Workpiece<'a> { - - pub fn new() -> Workpiece<'a> { - - Workpiece { - render_sprite: Sprite::new() - } - } - - pub fn load_first_stage(&mut self, texture: &'a mut Texture) { - - - self.render_sprite.set_texture(texture, false); - self.render_sprite.set_position((0., 0.)); - - } -} - -impl<'s> Drawable for Workpiece<'s> { - fn draw<'a: 'shader, 'texture, 'shader, 'shader_texture>( - &'a self, - render_target: &mut RenderTarget, - _: RenderStates<'texture, 'shader, 'shader_texture>, - ) { - - } -} \ No newline at end of file