adding another buffer for xy

master
mitchellhansen 6 years ago
parent 4de26c702d
commit 8c22536653

@ -1,16 +1,57 @@
#version 450
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(set = 0, binding = 0) buffer Data {
uint data[];
int data[];
} data;
//layout(set = 0, binding = 1) buffer Settings {
// int settings[];
//} settings;
ivec4 separate(int pix){
ivec4 r = ivec4(
(pix & 0x000000FF),
(pix & 0x0000FF00) >> 8,
(pix & 0x00FF0000) >> 16,
(pix & 0xFF000000) >> 24
);
return r;
}
uint get_idx(int offset_x, int offset_y){
// uint x = min(settings.settings[0], max(0, gl_GlobalInvocationID.x + offset_x));
// uint y = min(settings.settings[1], max(0, gl_GlobalInvocationID.y + offset_y));
// return ((y * settings.settings[0]) + x);
uint x = min(800, max(0, gl_GlobalInvocationID.x + offset_x));
uint y = min(600, max(0, gl_GlobalInvocationID.y + offset_y));
return ((y * 800) + x);
}
void main() {
uint idx = (gl_GlobalInvocationID.y * 720 + gl_GlobalInvocationID.x);
data.data[idx+0] = 255;
data.data[idx+1] = 0;
data.data[idx+2] = 0;
uint idx = get_idx(0,0);
ivec4 p = separate(data.data[get_idx(0,0)]);
ivec4 p0 = separate(data.data[get_idx(2,0)]);
ivec4 p1 = separate(data.data[get_idx(-2,0)]);
ivec4 p2 = separate(data.data[get_idx(0,2)]);
ivec4 p3 = separate(data.data[get_idx(0,-2)]);
ivec3 d0 = abs(p0.xyz - p1.xyz);
ivec3 d1 = abs(p2.xyz - p3.xyz);
p.x = 255;//d0.x + d0.y + d0.z + d1.x + d1.y + d1.z;
data.data[idx] = (data.data[idx] & (~0x000000FF) ) | (p.x);
data.data[idx] = (data.data[idx] & (~0x0000FF00) ) | (p.y << 8);
data.data[idx] = (data.data[idx] & (~0x00FF0000) ) | (p.z << 16);
data.data[idx] = (data.data[idx] & (~0xFF000000) ) | (p.w << 24);
}

@ -33,6 +33,7 @@ use std::fs;
use crate::input::Input;
use crate::slider::Slider;
use crate::timer::Timer;
use na::DimAdd;
mod slider;
mod timer;
@ -171,28 +172,42 @@ fn main() {
});
// Load up the input image, determine some details
let mut img = image::open("resources/images/funky-bird.jpg").unwrap();
let mut img = image::open("resources/images/background.jpg").unwrap();
let xy = img.dimensions();
let data_length = xy.0*xy.1*3;
let data_length = xy.0*xy.1*4;
let mut image_buffer = Vec::new();
for i in img.raw_pixels().iter() {
if (image_buffer.len() + 1) % 4 == 0 {
image_buffer.push(255);
}
image_buffer.push(*i);
}
image_buffer.push(255);
println!("Buffer length {}", data_length);
println!("Buffer length {}", img.raw_pixels().len());
println!("Buffer length {}", image_buffer.len());
println!("Size {:?}", xy);
let mut image_buffer = Vec::new();
{
// Pull out the image data and place it in a sync'd CPU<->GPU buffer
// Raw pixels is a u8 rgb buffer (x*y*3)
let data_buffer = {
let mut buff = img.raw_pixels();
let mut buff = buff.iter();
//let mut buff = img.raw_pixels();
let mut buff = image_buffer.iter();
let data_iter = (0 .. data_length).map(|n| *(buff.next().unwrap()));
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), data_iter).unwrap()
};
let settings_buffer = {
CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), vec![xy.0, xy.1]).unwrap()
};
// Create the data descriptor set for our previously created shader pipeline
let set = Arc::new(PersistentDescriptorSet::start(pipeline.clone(), 0)
.add_buffer(data_buffer.clone()).unwrap()
.add_buffer(settings_buffer.clone()).unwrap()
.build().unwrap()
);
@ -207,30 +222,30 @@ fn main() {
.then_signal_fence_and_flush().unwrap();
// I think this is redundant and returns immediately
// future.wait(None).unwrap();
// future.wait(None).unwrap();
// The buffer is sync'd so we can just read straight from the handle
let data_buffer_content = data_buffer.read().unwrap();
for y in 0 .. xy.1 {
for x in 0 .. xy.0 {
let r = data_buffer_content[((xy.0 * y + x) * 4 + 0) as usize] as u8;
let g = data_buffer_content[((xy.0 * y + x) * 4 + 1) as usize] as u8;
let b = data_buffer_content[((xy.0 * y + x) * 4 + 2) as usize] as u8;
let a = data_buffer_content[((xy.0 * y + x) * 4 + 3) as usize] as u8;
let r = data_buffer_content[((xy.0 * y + x) * 3 + 0) as usize] as u8;
let g = data_buffer_content[((xy.0 * y + x) * 3 + 1) as usize] as u8;
let b = data_buffer_content[((xy.0 * y + x) * 3 + 2) as usize] as u8;
image_buffer.push(r);
image_buffer.push(g);
image_buffer.push(b);
image_buffer.push(255);
img.put_pixel(x, y, image::Rgba([r, g, b, 255]))
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 0) as usize).unwrap() = r;
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 1) as usize).unwrap() = g;
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 2) as usize).unwrap() = b;
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 3) as usize).unwrap() = a;
img.put_pixel(x, y, image::Rgba([r, g, b, a]))
}
}
}
img.save("output.png");
img.save("output9.png");
println!("Starting");
@ -241,6 +256,7 @@ fn main() {
&Default::default(),
);
let mut timer = Timer::new();
let mut input = Input::new();
@ -311,8 +327,8 @@ fn main() {
accumulator_time -= step_size;
}
let x = window.mouse_position().x as f32 / window.size().x as f32;
let y = window.mouse_position().y as f32 / window.size().y as f32;
let x = 0.;//window.mouse_position().x as f32 / window.size().x as f32;
let y = 0.;//window.mouse_position().y as f32 / window.size().y as f32;
effects[current].update(elapsed_time*1.0, x, y);
window.clear(&Color::BLACK);

Loading…
Cancel
Save