From 3b734f0d6b9e28c1f2c4ae54e3f46e573e02f4a5 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Fri, 9 Mar 2018 21:36:10 +0100 Subject: Initial Commit --- BuddhaTest/Shaders/BuddhaCompute.glsl | 27 +++++++++++++++++++++++++++ BuddhaTest/Shaders/BuddhaFragment.glsl | 28 ++++++++++++++++++++++++++++ BuddhaTest/Shaders/BuddhaVertex.glsl | 11 +++++++++++ 3 files changed, 66 insertions(+) create mode 100644 BuddhaTest/Shaders/BuddhaCompute.glsl create mode 100644 BuddhaTest/Shaders/BuddhaFragment.glsl create mode 100644 BuddhaTest/Shaders/BuddhaVertex.glsl (limited to 'BuddhaTest/Shaders') diff --git a/BuddhaTest/Shaders/BuddhaCompute.glsl b/BuddhaTest/Shaders/BuddhaCompute.glsl new file mode 100644 index 0000000..49209ae --- /dev/null +++ b/BuddhaTest/Shaders/BuddhaCompute.glsl @@ -0,0 +1,27 @@ +#version 430 + +layout(std430, binding=2) buffer renderedData +{ + uint width; + uint height; + uint counts_SSBO[]; +}; + +uniform uint iterationCount; + +void addToColorAt(uvec2 cell, uvec3 toAdd) +{ + uint firstIndex = 3*(cell.x + cell.y * width); + atomicAdd(counts_SSBO[firstIndex],toAdd.x); + atomicAdd(counts_SSBO[firstIndex+1],toAdd.y); + atomicAdd(counts_SSBO[firstIndex+2],toAdd.z); +} + + +layout (local_size_x = 1, local_size_y = 1) in; +void main() { + if(iterationCount < 1024) + addToColorAt(uvec2(iterationCount%width,iterationCount/width),uvec3(1,0,0)); + else + addToColorAt(uvec2(iterationCount%width,iterationCount/width),uvec3(0,1,0)); +} diff --git a/BuddhaTest/Shaders/BuddhaFragment.glsl b/BuddhaTest/Shaders/BuddhaFragment.glsl new file mode 100644 index 0000000..4978765 --- /dev/null +++ b/BuddhaTest/Shaders/BuddhaFragment.glsl @@ -0,0 +1,28 @@ +#version 430 core + +in vec2 uv; + +out vec3 color; + +layout(std430, binding=2) buffer renderedData +{ + uint width; + uint height; + uint counts_SSBO[]; +}; + +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 firstIndex = 3*(xIndex + yIndex * width); + return uvec3(counts_SSBO[firstIndex],counts_SSBO[firstIndex+1],counts_SSBO[firstIndex+2]); +} + +void main(){ + uvec3 totalCount = getColorAt(uv) + getColorAt(vec2(uv.x, -uv.y)); + uvec3 brightness = getColorAt(vec2(-0.2390625,0)); + + vec3 scaled = vec3(totalCount)/max(length(vec3(brightness)),1.0); + color = scaled; +} diff --git a/BuddhaTest/Shaders/BuddhaVertex.glsl b/BuddhaTest/Shaders/BuddhaVertex.glsl new file mode 100644 index 0000000..686eeb4 --- /dev/null +++ b/BuddhaTest/Shaders/BuddhaVertex.glsl @@ -0,0 +1,11 @@ +#version 430 core + +layout(location = 0) in vec3 vertexPosition_modelspace; + +out vec2 uv; + +void main(){ + gl_Position.xyz = vertexPosition_modelspace; + gl_Position.w = 1.0; + uv = gl_Position.xy; +} \ No newline at end of file -- cgit v1.2.3