Project

General

Profile

« Previous | Next » 

Revision e029600f

Added by Leszek Koltunski about 6 years ago

still debugging the OIT

View differences:

src/main/res/raw/blit_depth_render_fragment_shader.glsl
20 20
precision highp float;
21 21
precision highp int;
22 22

  
23
#if __VERSION__ != 100
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
#define TEXTURE texture
28
#define FRAG_COLOR fragColor
29
#else
30
varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment.
31
varying vec2 v_Pixel;         // location of the current fragment, in pixels
32
#define TEXTURE texture2D
33
#define FRAG_COLOR gl_FragColor
34
#endif
23
out vec4 fragColor;
24
in vec2 v_TexCoordinate;
35 25

  
36
uniform sampler2D u_DepthTexture;
26
uniform vec2 u_Size;
37 27

  
38
//////////////////////////////////////////////////////////////////////////////////////////////
39
// per-pixel linked list. Order Independent Transparency.
40

  
41
uniform ivec2 u_Size;
42

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

  
49
//////////////////////////////////////////////////////////////////////////////////////////////
50

  
51
vec4 convert(uint rgba)
28
layout (std430,binding=1) buffer linkedlist
52 29
  {
53
  return vec4( float((rgba>>24u)&255u),float((rgba>>16u)&255u),float((rgba>>8u)&255u),float(rgba&255u) ) / 255.0;
54
  }
55

  
56
//////////////////////////////////////////////////////////////////////////////////////////////
57
// https://en.wikipedia.org/wiki/Alpha_compositing (premultiplied)
58

  
59
vec4 blend(vec4 clr,vec4 srf)
60
  {
61
  return clr + (1.0 - clr.a) * vec4(srf.rgb * srf.a , srf.a);
62
  }
30
  uint u_Records[];
31
  };
63 32

  
64 33
//////////////////////////////////////////////////////////////////////////////////////////////
65 34

  
66 35
void main()                    		
67 36
  {
68
  uint index = uint(v_Pixel.x + v_Pixel.y * float(u_Size.x));
69
  uint ptr = u_Records[index];
37
  uint pixelX = uint(v_TexCoordinate.x * u_Size.x);
38
  uint pixelY = uint(v_TexCoordinate.y * u_Size.y);
39
  uint index  = pixelX + pixelY * uint(u_Size.x);
70 40

  
71
  if( ptr == 0u ) discard;
72
  else
73
    {
74
    u_Records[index] = 0u;
75
    vec4 color = convert(u_Records[ptr]);
76

  
77
         if( (2*int(v_Pixel.x) > u_Size.x) && color.r==1.0 ) FRAG_COLOR = color;
78
    else if( (2*int(v_Pixel.x) <=u_Size.x) && color.g==1.0 ) FRAG_COLOR = color;
79
    else FRAG_COLOR = vec4(0.0,0.0,1.0,1.0);
80
    //FRAG_COLOR = convert(u_Records[index]);
81
    //u_Records[index] = 0u;
82
    }
83

  
84
  /*
85
  uint index = uint(v_Pixel.x + v_Pixel.y * float(u_Size.x));
86
  uint curr = u_Records[index];
87

  
88
  if (curr == 0u) discard;
89

  
90
  vec4 color= vec4(0.0,0.0,0.0,0.0);
91
  u_Records[index] = 0u;
92

  
93
  while (curr > 0u)                                      // keep walking the linked list
94
    {                                                    // and blending the colors in
95
    curr = u_Records[curr];                              //
96
    //color= blend( color, convert(u_Records[curr+2u]) );  //
97

  
98
    color = convert(u_Records[curr+2u]);
99

  
100
    if( color.a == 0.0 ) color = vec4(0.0,1.0,0.0,1.0);
101
    }
102

  
103

  
104
  if( curr>0u )
105
    {
106
    curr = u_Records[curr];
107
    color= convert(u_Records[curr+2u]);
108
    }
109

  
110
  gl_FragDepth = TEXTURE(u_DepthTexture, v_TexCoordinate).r;
111
  FRAG_COLOR = color;
41
  uint ptr = u_Records[index];
112 42

  
113
//else
114
//  FRAG_COLOR = vec4(1.0,0.0,0.0,1.0);
115
*/
43
       if( u_Records[ptr]==2u ) fragColor = vec4(1.0,0.0,0.0,1.0);
44
  else if( u_Records[ptr]==1u ) fragColor = vec4(0.0,1.0,0.0,1.0);
45
  else                          fragColor = vec4(0.0,0.0,1.0,1.0);
116 46
  }

Also available in: Unified diff