so that didn't do what I wanted, essentially a pixelate shader ATM

master
mitchellhansen 5 years ago
parent e597e8ef1b
commit b2b486be84

@ -26,10 +26,6 @@ ivec4 separate(int pix){
uint get_idx(int offset_x, int offset_y){ 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(settings.settings[0], max(0, gl_GlobalInvocationID.x + offset_x)); 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)); uint y = min(settings.settings[1], max(0, gl_GlobalInvocationID.y + offset_y));
return ((y * settings.settings[0]) + x); return ((y * settings.settings[0]) + x);
@ -56,7 +52,7 @@ void main() {
ivec3 m = max(max(max(d0, d1), d2), d3); ivec3 m = max(max(max(d0, d1), d2), d3);
if ((m.x + m.y + m.z) > 1){ if ((m.x + m.y + m.z) > 275){
p.x = 0; p.x = 0;
p.y = 0; p.y = 0;
p.z = 255; p.z = 255;

@ -0,0 +1,79 @@
#version 450
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(set = 0, binding = 0) buffer wData {
int buf[];
} write_buffer;
layout(set = 0, binding = 1) buffer rData {
int buf[];
} read_buffer;
layout(set = 0, binding = 2) 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);
}
void main() {
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)]);
ivec4 avg = p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7;
avg = max(avg, 1) / 8;
int total_of_avg = avg.x + avg.y + avg.z;
ivec4 pixels[8] = ivec4[](p0, p1, p2, p3, p4, p5, p6, p7);
int current_best = 999;
ivec4 current_best_p = p;
for (int i = 0; i < 8; i++){
int v = pixels[i].x + pixels[i].y + pixels[i].z;
if (abs(total_of_avg - v) < current_best) {
current_best = abs(total_of_avg - v);
current_best_p = pixels[i];
}
}
p = current_best_p;
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);
// 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);
}

@ -50,7 +50,7 @@ mod util;
fn main() { fn main() {
// Load up the input image, determine some details // Load up the input image, determine some details
let mut img = image::open("resources/images/test2.png").unwrap(); let mut img = image::open("resources/images/funky-bird.jpg").unwrap();
let xy = img.dimensions(); let xy = img.dimensions();
let data_length = xy.0 * xy.1 * 4; let data_length = xy.0 * xy.1 * 4;
let mut image_buffer = Vec::new(); let mut image_buffer = Vec::new();
@ -70,7 +70,7 @@ fn main() {
let project_root = std::env::current_dir().expect("failed to get root directory"); let project_root = std::env::current_dir().expect("failed to get root directory");
let mut compute_path = project_root.clone(); let mut compute_path = project_root.clone();
compute_path.push(PathBuf::from("resources/shaders/add.compute")); compute_path.push(PathBuf::from("resources/shaders/simple-homogenize.compute"));
let shader = sr::load_compute(compute_path).expect("Failed to compile"); let shader = sr::load_compute(compute_path).expect("Failed to compile");
let vulkano_entry = sr::parse_compute(&shader).expect("failed to parse"); let vulkano_entry = sr::parse_compute(&shader).expect("failed to parse");

Loading…
Cancel
Save