1 |
33f59f22
|
Leszek Koltunski
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2018 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
535a45bc
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
33f59f22
|
Leszek Koltunski
|
// //
|
6 |
535a45bc
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
33f59f22
|
Leszek Koltunski
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
535a45bc
|
Leszek Koltunski
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
33f59f22
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
535a45bc
|
Leszek Koltunski
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
33f59f22
|
Leszek Koltunski
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
precision highp float;
|
21 |
|
|
precision highp int;
|
22 |
|
|
|
23 |
|
|
out vec4 fragColor; // The output color
|
24 |
|
|
in vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment.
|
25 |
|
|
in vec2 v_Pixel; // location of the current fragment, in pixels
|
26 |
|
|
|
27 |
|
|
uniform sampler2D u_DepthTexture;
|
28 |
|
|
|
29 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
30 |
|
|
// per-pixel linked list. Order Independent Transparency.
|
31 |
|
|
|
32 |
344ac0e4
|
Leszek Koltunski
|
uniform uvec2 u_Size;
|
33 |
33f59f22
|
Leszek Koltunski
|
|
34 |
|
|
layout (std430,binding=1) buffer linkedlist // first (u_Size.x*u_Size.y) uints - head pointers,
|
35 |
|
|
{ // one for each pixel in the Output rectangle.
|
36 |
|
|
uint u_Records[]; //
|
37 |
|
|
}; // Next 3*u_numRecords uints - actual linked list, i.e.
|
38 |
|
|
// triplets of (pointer,depth,rgba).
|
39 |
|
|
|
40 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
// Pass3 of the OIT algorithm - traverse the per-pixel LinkedList and cut occluded fragments.
|
42 |
|
|
|
43 |
|
|
void main()
|
44 |
|
|
{
|
45 |
344ac0e4
|
Leszek Koltunski
|
uint prev = uint(v_Pixel.x) + uint(v_Pixel.y) * u_Size.x;
|
46 |
33f59f22
|
Leszek Koltunski
|
uint curr = u_Records[prev];
|
47 |
|
|
|
48 |
|
|
if (curr != 0u)
|
49 |
|
|
{
|
50 |
|
|
const float S= 2147483647.0;
|
51 |
|
|
float depth = texture(u_DepthTexture, v_TexCoordinate).r;
|
52 |
|
|
uint texdepth = uint(S*(1.0-depth)/2.0);
|
53 |
|
|
|
54 |
c207da02
|
Leszek Koltunski
|
while( curr != 0u )
|
55 |
33f59f22
|
Leszek Koltunski
|
{
|
56 |
c207da02
|
Leszek Koltunski
|
if( u_Records[curr+1u] <= texdepth )
|
57 |
|
|
{
|
58 |
|
|
u_Records[prev] = 0u;
|
59 |
|
|
break;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
33f59f22
|
Leszek Koltunski
|
prev = curr;
|
63 |
|
|
curr = u_Records[curr];
|
64 |
|
|
}
|
65 |
|
|
}
|
66 |
|
|
else discard;
|
67 |
|
|
}
|