summaryrefslogtreecommitdiff
path: root/graphics/asymptote/base/shaders/blend.glsl
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-04-07 03:01:53 +0000
committerNorbert Preining <norbert@preining.info>2022-04-07 03:01:53 +0000
commit4ab0687cfdd546779ccb6d8589a671441bf5865f (patch)
tree77554e11f1829a925194242636c38c7306fa43a8 /graphics/asymptote/base/shaders/blend.glsl
parent333540a9182285f9d72d7d39be3fa730c135d664 (diff)
CTAN sync 202204070301
Diffstat (limited to 'graphics/asymptote/base/shaders/blend.glsl')
-rw-r--r--graphics/asymptote/base/shaders/blend.glsl136
1 files changed, 84 insertions, 52 deletions
diff --git a/graphics/asymptote/base/shaders/blend.glsl b/graphics/asymptote/base/shaders/blend.glsl
index 76dfe94ad3..8a656e06c9 100644
--- a/graphics/asymptote/base/shaders/blend.glsl
+++ b/graphics/asymptote/base/shaders/blend.glsl
@@ -1,34 +1,39 @@
-layout(binding=0, std430) buffer offsetBuffer {
+layout(binding=0, std430) buffer offsetBuffer
+{
uint offset[];
};
-layout(binding=1, std430) buffer maxBuffer {
- uint maxSize;
-};
-
#ifdef GPUINDEXING
+uniform uint elements;
uniform uint offset2;
uniform uint m1;
+uniform uint m2;
uniform uint r;
-layout(binding=2, std430) buffer localSumBuffer {
+layout(binding=2, std430) buffer localSumBuffer
+{
uint localSum[];
};
-layout(binding=3, std430) buffer globalSumBuffer {
+layout(binding=3, std430) buffer globalSumBuffer
+{
uint globalSum[];
};
+#define count offset
#else
-layout(binding=2, std430) buffer countBuffer {
+layout(binding=2, std430) buffer countBuffer
+{
uint count[];
};
#endif
-layout(binding=4, std430) buffer fragmentBuffer {
+layout(binding=4, std430) buffer fragmentBuffer
+{
vec4 fragment[];
};
-layout(binding=5, std430) buffer depthBuffer {
+layout(binding=5, std430) buffer depthBuffer
+{
float depth[];
};
@@ -37,13 +42,25 @@ layout(binding=6, std430) buffer opaqueBuffer {
};
layout(binding=7, std430) buffer opaqueDepthBuffer {
+ uint maxSize;
float opaqueDepth[];
};
+#ifdef GPUCOMPRESS
+layout(binding=1, std430) buffer indexBuffer
+{
+ uint index[];
+};
+#define INDEX(pixel) index[pixel]
+#define COUNT(pixel) index[pixel]
+#else
+#define INDEX(pixel) pixel
+#define COUNT(pixel) count[pixel]
+#endif
+
out vec4 outColor;
uniform uint width;
-uniform uint pixels;
uniform vec4 background;
vec4 blend(vec4 outColor, vec4 color)
@@ -53,29 +70,36 @@ vec4 blend(vec4 outColor, vec4 color)
void main()
{
- uint headIndex=uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x);
-#ifdef GPUINDEXING
- uint size=offset[headIndex];
-#else
- uint size=count[headIndex];
+ uint pixel=uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x);
+ float OpaqueDepth=opaqueDepth[pixel];
+ uint element=INDEX(pixel);
+
+#ifdef GPUCOMPRESS
+ if(element == 0u) {
+ if(OpaqueDepth != 0.0)
+ opaqueDepth[pixel]=0.0;
+ discard;
+ }
#endif
- float OpaqueDepth=opaqueDepth[headIndex];
+
+ uint size=count[element];
+
+#ifndef GPUCOMPRESS
if(size == 0u) {
-#ifdef GPUINDEXING
- offset[pixels+headIndex]=0u;
-#endif
- opaqueDepth[headIndex]=0.0;
+ if(OpaqueDepth != 0.0)
+ opaqueDepth[pixel]=0.0;
discard;
}
+#endif
- outColor=OpaqueDepth != 0.0 ? opaqueColor[headIndex] : background;
+ outColor=OpaqueDepth != 0.0 ? opaqueColor[pixel] : background;
#ifdef GPUINDEXING
- uint p=headIndex < r*(m1+1u) ? headIndex/(m1+1u) : (headIndex-r)/m1;
+ uint p=element < r*(m1+1u) ? element/(m1+1u) : (element-r)/m1;
uint listIndex=localSum[p]+localSum[offset2+p/m2]+globalSum[p/(m2*m2)]+
- offset[pixels+headIndex];
+ offset[elements+element];
#else
- uint listIndex=offset[headIndex]-size;
+ uint listIndex=offset[element]-size;
#endif
uint k=0u;
@@ -83,36 +107,49 @@ void main()
while(k < size && depth[listIndex+k] >= OpaqueDepth)
++k;
+ uint n=size-k;
+
// Sort the fragments with respect to descending depth
- if(size-k <= ARRAYSIZE) {
- if(k < size) {
- uint Index[ARRAYSIZE];
- float Depth[ARRAYSIZE];
- Index[0]=k;
- Depth[0]=depth[listIndex+k];
- ++k;
+ if(n <= ARRAYSIZE) {
+ if(n == 1)
+ outColor=blend(outColor,fragment[listIndex+k]);
+ else if(n > 0) {
+ struct element {
+ uint index;
+ float depth;
+ };
+
+ element E[ARRAYSIZE];
+ E[0]=element(k,depth[listIndex+k]);
uint i=1u;
- while(true) {
- if(OpaqueDepth != 0.0)
- while(k < size && depth[listIndex+k] >= OpaqueDepth)
- ++k;
- if(k == size) break;
+ while(++k < size) {
float d=depth[listIndex+k];
+ if(OpaqueDepth != 0.0) {
+ while(k < size && d >= OpaqueDepth) {
+ ++k;
+ d=depth[listIndex+k];
+ }
+ if(k == size) break;
+ }
uint j=i;
- while(j > 0u && d > Depth[j-1u]) {
- Index[j]=Index[j-1u];
- Depth[j]=Depth[j-1u];
+ while(j > 0u && d > E[j-1u].depth) {
+ E[j]=E[j-1u];
--j;
}
- Index[j]=k++;
- Depth[j]=d;
+ E[j]=element(k,d);
++i;
}
for(uint j=0u; j < i; ++j)
- outColor=blend(outColor,fragment[listIndex+Index[j]]);
+ outColor=blend(outColor,fragment[listIndex+E[j].index]);
}
+
+ if(OpaqueDepth != 0.0)
+ opaqueDepth[pixel]=0.0;
} else {
atomicMax(maxSize,size);
+#ifndef GPUINDEXING
+ count[0]=maxSize;
+#endif
for(uint i=k+1u; i < size; i++) {
vec4 temp=fragment[listIndex+i];
float d=depth[listIndex+i];
@@ -130,19 +167,14 @@ void main()
if(OpaqueDepth == 0.0)
for(uint i=listIndex+k; i < stop; i++)
outColor=blend(outColor,fragment[i]);
- else
+ else {
for(uint i=listIndex+k; i < stop; i++) {
if(depth[i] < OpaqueDepth)
outColor=blend(outColor,fragment[i]);
}
+ opaqueDepth[pixel]=0.0;
+ }
}
-
- opaqueDepth[headIndex]=0.0;
-#ifdef GPUINDEXING
- offset[headIndex]=0u;
- offset[pixels+headIndex]=0u;
-#else
- count[headIndex]=0u;
-#endif
+ COUNT(pixel)=0u;
}