From e476cb2e4e19d765a5dfcb37d3c68fdc07bcdb29 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Thu, 18 Jul 2019 23:43:55 -0700 Subject: [PATCH] It was the gamma being wrong. Interesting how much different this is working than SFML+OpenCL --- resources/shaders/simple-edge.compute | 72 +++++++++++------------ resources/shaders/simple_texture.fragment | 23 ++------ src/main.rs | 2 +- src/vkprocessor.rs | 18 +----- 4 files changed, 46 insertions(+), 69 deletions(-) diff --git a/resources/shaders/simple-edge.compute b/resources/shaders/simple-edge.compute index e2c7d2d8..47ddc43d 100644 --- a/resources/shaders/simple-edge.compute +++ b/resources/shaders/simple-edge.compute @@ -33,48 +33,48 @@ uint get_idx(int offset_x, int offset_y){ void main() { - uint idx = get_idx(0,0); + uint idx = get_idx(0,0); + + ivec4 p = separate(read_buffer.buf[get_idx(0 , 0)]); + ivec4 p0 = separate(read_buffer.buf[get_idx(0 , 1)]); + ivec4 p1 = separate(read_buffer.buf[get_idx(0 ,-1)]); + ivec4 p2 = separate(read_buffer.buf[get_idx(1 , 1)]); + ivec4 p3 = separate(read_buffer.buf[get_idx(-1,-1)]); + ivec4 p4 = separate(read_buffer.buf[get_idx(1 , 0)]); + ivec4 p5 = separate(read_buffer.buf[get_idx(-1, 0)]); + ivec4 p6 = separate(read_buffer.buf[get_idx(1 ,-1)]); + ivec4 p7 = separate(read_buffer.buf[get_idx(-1, 1)]); + + ivec3 d0 = abs(p0.xyz - p1.xyz); + ivec3 d1 = abs(p2.xyz - p3.xyz); + ivec3 d2 = abs(p4.xyz - p5.xyz); + ivec3 d3 = abs(p6.xyz - p7.xyz); + + ivec3 m = max(max(max(d0, d1), d2), d3); + + if ((m.x + m.y + m.z) > 975){ + p.x = 0; + p.y = 0; + p.z = 255; + } + else { + + //p.w = 125; + } + + write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x000000FF) ) | (p.x); + write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8); + write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16); + write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24); - ivec4 p = separate(read_buffer.buf[get_idx(0 , 0)]); -// ivec4 p0 = separate(read_buffer.buf[get_idx(0 , 1)]); -// ivec4 p1 = separate(read_buffer.buf[get_idx(0 ,-1)]); -// ivec4 p2 = separate(read_buffer.buf[get_idx(1 , 1)]); -// ivec4 p3 = separate(read_buffer.buf[get_idx(-1,-1)]); -// ivec4 p4 = separate(read_buffer.buf[get_idx(1 , 0)]); -// ivec4 p5 = separate(read_buffer.buf[get_idx(-1, 0)]); -// ivec4 p6 = separate(read_buffer.buf[get_idx(1 ,-1)]); -// ivec4 p7 = separate(read_buffer.buf[get_idx(-1, 1)]); - -// ivec3 d0 = abs(p0.xyz - p1.xyz); -// ivec3 d1 = abs(p2.xyz - p3.xyz); -// ivec3 d2 = abs(p4.xyz - p5.xyz); -// ivec3 d3 = abs(p6.xyz - p7.xyz); - -// ivec3 m = max(max(max(d0, d1), d2), d3); - -// if ((m.x + m.y + m.z) > 275){ -// p.x = 0; -// p.y = 0; -// p.z = 255; -// } - -// //p.z = max(p.z - (d0.x + d0.y + d0.z + d1.x + d1.y + d1.z)/5, 0); +} -// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x000000FF) ) | (p.x); -// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8); -// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16); -// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24); -// p.x = 70; -// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x000000FF) ) | (p.x); -// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8); -// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16); -// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24); +// Just gonna keep this around // read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x000000FF) ) | (p.x); // read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8); // read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16); -// read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24); -} \ No newline at end of file +// read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24); \ No newline at end of file diff --git a/resources/shaders/simple_texture.fragment b/resources/shaders/simple_texture.fragment index befc7b76..69b562ef 100644 --- a/resources/shaders/simple_texture.fragment +++ b/resources/shaders/simple_texture.fragment @@ -2,26 +2,15 @@ layout(location = 0) in vec2 tex_coords; layout(location = 0) out vec4 f_color; layout(set = 0, binding = 0) uniform sampler2D tex; -layout(set = 0, binding = 1, rgba8ui) readonly uniform uimage2D img; +layout(set = 0, binding = 1, rgba32ui) readonly uniform uimage2D img; void main() { - vec2 onePixel = vec2(1.0, 1.0) / (720.0, 756.0); - vec2 pos = tex_coords * onePixel; - ivec2 ipos = ivec2(pos); - vec4 colorSum = imageLoad(img, ipos); - f_color = colorSum; - - - // f_color = texture(tex, tex_coords); - // ivec2 t = ivec2(tex_coords.x, tex_coords.y ); - ivec2 size = ivec2(gl_FragCoord.x, gl_FragCoord.y); - //ivec2 size = ivec2(0, 0); - f_color = imageLoad(img, size) / (200); -// f_color.w = 0; -// f_color.r = 75; -// f_color.g = 30; -// f_color.b =; + f_color = imageLoad(img, size) / (255.0); + // f_color.a += 100; + // f_color = texture(tex, tex_coords); + float gamma = 0.5; + f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma)); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index de2f7bf2..81a95d86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,7 @@ fn main() { processor.compile_kernel(String::from("simple-edge.compute")); processor.compile_shaders(String::from("simple_texture"), &surface); - processor.load_buffers(String::from("funky-bird.jpg")); + processor.load_buffers(String::from("background.jpg")); let mut timer = Timer::new(); diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index 8bbbfbe1..b200bafd 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -487,18 +487,10 @@ impl<'a> VkProcessor<'a> { self.vertex_buffer = Some(vertex_buffer); let (texture, tex_future) = { - let image = image::load_from_memory_with_format(include_bytes!("../resources/images/funky-bird.jpg"), - ImageFormat::JPEG).unwrap().to_rgba(); - - println!("{}", image.len()); - println!("{}", self.image_buffer.len()); - - let dimensions = image.dimensions(); - let image_data = image.into_raw().clone(); ImmutableImage::from_iter( - image_data.iter().cloned(), - Dimensions::Dim2d { width: dimensions.0, height: dimensions.1 }, + self.image_buffer.iter().cloned(), + Dimensions::Dim2d { width: self.xy.0, height: self.xy.1 }, Format::R8G8B8A8Srgb, self.queue.clone() // self.image_buffer.iter().cloned(), @@ -508,10 +500,6 @@ impl<'a> VkProcessor<'a> { }; let attachment_image = { - let image = image::load_from_memory_with_format(include_bytes!("../resources/images/funky-bird.jpg"), - ImageFormat::JPEG).unwrap().to_rgba(); - let dimensions = image.dimensions(); - let image_data = image.into_raw().clone(); let mut usage = ImageUsage::none(); usage.transfer_destination = true; @@ -519,7 +507,7 @@ impl<'a> VkProcessor<'a> { AttachmentImage::with_usage( self.device.clone(), - [dimensions.0, dimensions.1], + [self.xy.0, self.xy.1], Format::R8G8B8A8Uint, usage) };