Project

General

Profile

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

library / src / main / res / raw / oit_collapse_fragment_shader.glsl @ 35a0f4ed

1
//////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2018 Leszek Koltunski                                                          //
3
//                                                                                          //
4
// This file is part of Distorted.                                                          //
5
//                                                                                          //
6
// Distorted is free software: you can redistribute it and/or modify                        //
7
// 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
// Distorted 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                            //
14
// GNU General Public License for more details.                                             //
15
//                                                                                          //
16
// You should have received a copy of the GNU General Public License                        //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
18
//////////////////////////////////////////////////////////////////////////////////////////////
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
uniform uvec2 u_Size;
33

    
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
  uint prev = uint(v_Pixel.x) + uint(v_Pixel.y) * u_Size.x;
46
  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
    while( curr != 0u )
55
      {
56
      if( u_Records[curr+1u] <= texdepth )
57
        {
58
        u_Records[prev] = 0u;
59
        break;
60
        }
61

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