From a0afe4bf8c011222b85c481ae209b09f75189858 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Sat, 10 Mar 2018 13:55:50 +0100 Subject: Reduce buffer size by a factor of 2 (image is symmetric) --- BuddhaTest/Shaders/BuddhaCompute.glsl | 2 +- BuddhaTest/Shaders/BuddhaFragment.glsl | 2 +- BuddhaTest/include/Helpers.h | 2 +- BuddhaTest/src/BuddhaTest.cpp | 2 +- BuddhaTest/src/Helpers.cpp | 17 ++++++++--------- 5 files changed, 12 insertions(+), 13 deletions(-) (limited to 'BuddhaTest') diff --git a/BuddhaTest/Shaders/BuddhaCompute.glsl b/BuddhaTest/Shaders/BuddhaCompute.glsl index d42f506..ddbaf93 100644 --- a/BuddhaTest/Shaders/BuddhaCompute.glsl +++ b/BuddhaTest/Shaders/BuddhaCompute.glsl @@ -23,7 +23,7 @@ void addToColorOfCell(uvec2 cell, uvec3 toAdd) uvec2 getCell(vec2 complex) { - vec2 uv = clamp(vec2((complex.x+2.5)/3.5, 0.5*(complex.y + 1.0)),vec2(0.0),vec2(1.0)); + vec2 uv = clamp(vec2((complex.x+2.5)/3.5, (abs(complex.y))),vec2(0.0),vec2(1.0)); return uvec2(width * uv.x, height * uv.y); } diff --git a/BuddhaTest/Shaders/BuddhaFragment.glsl b/BuddhaTest/Shaders/BuddhaFragment.glsl index 4978765..cb09628 100644 --- a/BuddhaTest/Shaders/BuddhaFragment.glsl +++ b/BuddhaTest/Shaders/BuddhaFragment.glsl @@ -14,7 +14,7 @@ layout(std430, binding=2) buffer renderedData uvec3 getColorAt(vec2 fragCoord) { uint xIndex = uint(max(0.0,(fragCoord.x+1.0)*0.5*width)); - uint yIndex = uint(max(0.0,(fragCoord.y+1.0)*0.5*height)); + uint yIndex = uint(max(0.0,abs(fragCoord.y)*height)); uint firstIndex = 3*(xIndex + yIndex * width); return uvec3(counts_SSBO[firstIndex],counts_SSBO[firstIndex+1],counts_SSBO[firstIndex+2]); } diff --git a/BuddhaTest/include/Helpers.h b/BuddhaTest/include/Helpers.h index 8c897d5..a4bf15d 100644 --- a/BuddhaTest/include/Helpers.h +++ b/BuddhaTest/include/Helpers.h @@ -9,7 +9,7 @@ namespace Helpers GLuint LoadShaders(const char * vertex_file_path, const char * fragment_file_path); GLuint LoadComputeShader(const char * compute_file_path, unsigned int localSizeX, unsigned int localSizeY, unsigned int localSizeZ); - void WriteOutputPNG(const std::vector& data, unsigned int width, unsigned int height); + void WriteOutputPNG(const std::vector& data, unsigned int width, unsigned int bufferHeight); /** Wraps around a C file descriptor. Libpng could be taught to use C++ streams, but I'm too lazy and rather wrap this ugly thing up, so it gets cleaned... */ class ScopedCFileDescriptor diff --git a/BuddhaTest/src/BuddhaTest.cpp b/BuddhaTest/src/BuddhaTest.cpp index 09a3cf1..f23fc5d 100644 --- a/BuddhaTest/src/BuddhaTest.cpp +++ b/BuddhaTest/src/BuddhaTest.cpp @@ -12,7 +12,7 @@ void error_callback(int error, const char* description) int main() { unsigned int bufferWidth = 1600; - unsigned int bufferHeight = 900; + unsigned int bufferHeight = 450; unsigned int windowWidth = 1600; unsigned int windowHeight = 900; diff --git a/BuddhaTest/src/Helpers.cpp b/BuddhaTest/src/Helpers.cpp index abe09fd..881d01f 100644 --- a/BuddhaTest/src/Helpers.cpp +++ b/BuddhaTest/src/Helpers.cpp @@ -154,11 +154,11 @@ namespace Helpers return ProgramID; } - void WriteOutputPNG(const std::vector& data, unsigned int width, unsigned int height) + void WriteOutputPNG(const std::vector& data, unsigned int width, unsigned int bufferHeight) { - std::vector pngData(3*width*height); - std::vector rows{height}; - for(int i = 0; i < height ; ++i) + std::vector pngData(3*width*2*bufferHeight); + std::vector rows{2*bufferHeight}; + for(int i = 0; i < 2*bufferHeight ; ++i) { rows[i] = pngData.data()+3*width*i; } @@ -170,14 +170,13 @@ namespace Helpers } for(unsigned int i = 0; i < data.size();++i) { - pngData[i] = (255*data[i] + (maxValue/2))/maxValue; + pngData[data.size() + i] = (255*data[i] + (maxValue/2))/maxValue; } - for(int i = 0; i < height/2;++i) + for(int i = 0; i < bufferHeight;++i) { for(int j = 0; j < width*3;++j) { - png_byte average = (rows[i][j] + rows[height-i-1][j])/2; - rows[i][j] = rows[height-i-1][j] = average; + rows[i][j] =rows[2*bufferHeight-i-1][j]; } } @@ -204,7 +203,7 @@ namespace Helpers return; } png_init_io(png_ptr, fd.Get()); - png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + png_set_IHDR(png_ptr, info_ptr, width, 2*bufferHeight, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_write_info(png_ptr, info_ptr); //header written. -- cgit v1.2.3