85 lines
1.8 KiB
GLSL
85 lines
1.8 KiB
GLSL
#version 460
|
|
|
|
#extension GL_GOOGLE_include_directive : require
|
|
#extension GL_EXT_nonuniform_qualifier : require
|
|
|
|
#define COMPOSITE_PASS
|
|
|
|
#include "structures.layout"
|
|
|
|
layout (location = 0) out vec4 FragColor;
|
|
|
|
void BubbleSort(inout uvec2 array[OIT_LAYERS], int n)
|
|
{
|
|
for(int i = (n - 2); i >= 0; --i)
|
|
{
|
|
for(int j = 0; j <= i; ++j)
|
|
{
|
|
if(uintBitsToFloat(array[j].g) >= uintBitsToFloat(array[j+1].g))
|
|
{
|
|
uvec2 temp = array[j+1];
|
|
array[j+1] = array[j];
|
|
array[j] = temp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
float UnPreMultSRGBToLinear(float col)
|
|
{
|
|
return (col < 0.04045f) ? (col / 12.92f) : pow((col + 0.055f) / 1.055f, 2.4f);
|
|
}
|
|
|
|
vec4 UnPreMultSRGBToLinear(vec4 col)
|
|
{
|
|
col.r = UnPreMultSRGBToLinear(col.r);
|
|
col.g = UnPreMultSRGBToLinear(col.g);
|
|
col.b = UnPreMultSRGBToLinear(col.b);
|
|
return col;
|
|
}
|
|
|
|
void DoBlend(inout vec4 color, vec4 base_color)
|
|
{
|
|
color.rgb += (1 - color.a) * base_color.rgb;
|
|
color.a += (1 - color.a) * base_color.a;
|
|
}
|
|
|
|
void DoBlendPacked(inout vec4 color, uint fragment)
|
|
{
|
|
vec4 unpacked_color = unpackUnorm4x8(fragment);
|
|
//unpacked_color = UnPreMultSRGBToLinear(unpacked_color);
|
|
unpacked_color.rgb *= unpacked_color.a;
|
|
DoBlend(color, unpacked_color);
|
|
}
|
|
|
|
void main()
|
|
{
|
|
ivec2 coord = ivec2(gl_FragCoord.xy);
|
|
int store_mask = 0;
|
|
int view_size = int(G.res.x) * int(G.res.y);
|
|
int sample_id = 0;
|
|
int list_pos = view_size * OIT_LAYERS * sample_id + coord.y * int(G.res.x) + coord.x;
|
|
uvec2 array[OIT_LAYERS];
|
|
|
|
vec4 color = vec4(0.0);
|
|
|
|
int fragments = int(imageLoad(ImageAux, coord).r);
|
|
fragments = min(OIT_LAYERS, fragments);
|
|
|
|
for (int i = 0; i < fragments; i++)
|
|
{
|
|
array[i] = imageLoad(ImageABuffer, list_pos + i * view_size).rg;
|
|
}
|
|
|
|
BubbleSort(array, fragments);
|
|
|
|
vec4 color_sum = vec4(0.0);
|
|
|
|
for(int i = 0; i < fragments; i++)
|
|
{
|
|
DoBlendPacked(color_sum, array[i].x);
|
|
}
|
|
|
|
FragColor = color_sum;
|
|
}
|