Project

General

Profile

Download (3.41 KB) Statistics
| Branch: | Revision:

library / src / main / res / raw / oit_collapse_fragment_shader.glsl @ 3f12341d

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2018 Leszek Koltunski  leszek@koltunski.pl                                          //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// This library is free software; you can redistribute it and/or                                 //
7
// modify it under the terms of the GNU Lesser General Public                                    //
8
// License as published by the Free Software Foundation; either                                  //
9
// version 2.1 of the License, or (at your option) any later version.                            //
10
//                                                                                               //
11
// This library is distributed in the hope that it will be useful,                               //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
14
// Lesser General Public License for more details.                                               //
15
//                                                                                               //
16
// You should have received a copy of the GNU Lesser General Public                              //
17
// License along with this library; if not, write to the Free Software                           //
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

    
21
precision highp float;
22
precision highp int;
23

    
24
out vec4 fragColor;           // The output color
25
in vec2 v_TexCoordinate;      // Interpolated texture coordinate per fragment.
26
in vec2 v_Pixel;              // location of the current fragment, in pixels
27

    
28
uniform sampler2D u_DepthTexture;
29

    
30
//////////////////////////////////////////////////////////////////////////////////////////////
31
// per-pixel linked list. Order Independent Transparency.
32

    
33
uniform uvec2 u_Size;
34

    
35
layout (std430,binding=1) buffer linkedlist  // first (u_Size.x*u_Size.y) uints - head pointers,
36
  {                                          // one for each pixel in the Output rectangle.
37
  uint u_Records[];                          //
38
  };                                         // Next 3*u_numRecords uints - actual linked list, i.e.
39
                                             // triplets of (pointer,depth,rgba).
40

    
41
//////////////////////////////////////////////////////////////////////////////////////////////
42
// Pass3 of the OIT algorithm - traverse the per-pixel LinkedList and cut occluded fragments.
43

    
44
void main()                    		
45
  {
46
  uint prev = uint(v_Pixel.x) + uint(v_Pixel.y) * u_Size.x;
47
  uint curr = u_Records[prev];
48

    
49
  if (curr != 0u)
50
    {
51
    const float S= 2147483647.0;
52
    float depth = texture(u_DepthTexture, v_TexCoordinate).r;
53
    uint texdepth = uint(S*(1.0-depth)/2.0);
54

    
55
    while( curr != 0u )
56
      {
57
      if( u_Records[curr+1u] <= texdepth )
58
        {
59
        u_Records[prev] = 0u;
60
        break;
61
        }
62

    
63
      prev = curr;
64
      curr = u_Records[curr];
65
      }
66
    }
67
  else discard;
68
  }
(11-11/14)