diff options
Diffstat (limited to 'BuddhaTest/Shaders')
-rw-r--r-- | BuddhaTest/Shaders/BuddhaCompute.glsl | 66 | ||||
-rw-r--r-- | BuddhaTest/Shaders/BuddhaFragment.glsl | 12 |
2 files changed, 71 insertions, 7 deletions
diff --git a/BuddhaTest/Shaders/BuddhaCompute.glsl b/BuddhaTest/Shaders/BuddhaCompute.glsl index 1903505..ebfdb29 100644 --- a/BuddhaTest/Shaders/BuddhaCompute.glsl +++ b/BuddhaTest/Shaders/BuddhaCompute.glsl @@ -7,6 +7,12 @@ layout(std430, binding=2) restrict buffer renderedDataRed restrict uint counts_SSBO[]; }; +layout(std430, binding=3) restrict buffer brightnessData +{ + restrict uint brightness; +}; + +/** Data stored in the state buffer. */ struct individualData { uint phase; @@ -28,12 +34,38 @@ uniform uvec4 orbitLength; uniform uint iterationsPerDispatch; uniform uint totalIterations; +/** Data stored in shared memory. Used to reduce register pressure. Read at beginning from buffer (if needed), written back at end. */ +struct workerState +{ + uint brightness; +}; + +/** Storage in shared memory. Used to reduce register pressure. */ +shared workerState[gl_WorkGroupSize.x*gl_WorkGroupSize.y*gl_WorkGroupSize.z] localStore; + +void uintMaxIP(inout uint modified, const uint constant) +{ + modified = modified < constant ? constant : modified; +} + +void uintMaxIP(inout uvec3 modified, const uvec3 constant) +{ + for(int i = 0; i < 3 ; ++i) + uintMaxIP(modified[i],constant[i]); +} + void addToColorOfCell(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); + uvec3 b; + b.x = atomicAdd(counts_SSBO[firstIndex],toAdd.x); + b.y = atomicAdd(counts_SSBO[firstIndex+1],toAdd.y); + b.z = atomicAdd(counts_SSBO[firstIndex+2],toAdd.z); + for(int i = 0; i < 3;++i) + { + if(localStore[gl_LocalInvocationIndex].brightness < b[i]) + localStore[gl_LocalInvocationIndex].brightness = b[i]; + } } uvec2 getCell(vec2 complex) @@ -225,6 +257,8 @@ vec2 getCurrentOrbitOffset(const uint orbitNumber, const uint totalWorkers, cons } void main() { + localStore[gl_LocalInvocationIndex].brightness = 0; + //we need to know how many total work groups are running this iteration const uvec3 totalWorkersPerDimension = gl_WorkGroupSize * gl_NumWorkGroups; const uint totalWorkers = totalWorkersPerDimension.x*totalWorkersPerDimension.y*totalWorkersPerDimension.z; @@ -288,5 +322,31 @@ void main() { } } } + stateArray[uniqueWorkerID] = state; + + + //use divide et impera to get the real maximum brightness of this local group + barrier(); + if(bool(localStore.length() & 1) && gl_LocalInvocationIndex == 0) + { + uintMaxIP(localStore[0].brightness, localStore[localStore.length()-1].brightness); + } + for(int step = localStore.length()/2;step >= 1;step = step/2) + { + barrier(); + if(gl_LocalInvocationIndex < step) + { + uintMaxIP(localStore[gl_LocalInvocationIndex].brightness,localStore[gl_LocalInvocationIndex+step].brightness); + if(bool(step & 1) && gl_LocalInvocationIndex == 0) + { + uintMaxIP(localStore[0].brightness, localStore[step-1].brightness); + } + } + } + barrier(); + if(gl_LocalInvocationIndex == 0) + { + atomicMax(brightness, localStore[0].brightness); + } } diff --git a/BuddhaTest/Shaders/BuddhaFragment.glsl b/BuddhaTest/Shaders/BuddhaFragment.glsl index a6f47c1..ad184e6 100644 --- a/BuddhaTest/Shaders/BuddhaFragment.glsl +++ b/BuddhaTest/Shaders/BuddhaFragment.glsl @@ -6,11 +6,17 @@ out vec3 color; layout(std430, binding=2) restrict readonly buffer renderedDataRed { - restrict readonly uint counts_SSBO[]; + restrict readonly uint counts_SSBO[]; +}; +layout(std430, binding=3) restrict readonly buffer brightnessData +{ + restrict readonly uint brightness; }; uniform uint width; uniform uint height; +uniform float gamma; +uniform float colorScale; uvec3 getColorAt(vec2 fragCoord) { @@ -22,8 +28,6 @@ uvec3 getColorAt(vec2 fragCoord) void main(){ uvec3 totalCount = getColorAt(uv); - uvec3 brightness = getColorAt(vec2(-0.245,0)); - - vec3 scaled = vec3(totalCount)/max(length(vec3(brightness)),1.0); + vec3 scaled = pow(min(vec3(1.0),colorScale*vec3(totalCount)/max(float(brightness),1.0)),vec3(gamma)); color = scaled; } |