Project

General

Profile

« Previous | Next » 

Revision 47511918

Added by Leszek Koltunski about 6 years ago

Order Independent Transparency: some progress

View differences:

src/main/res/raw/blit_depth_fragment_shader.glsl
18 18
//////////////////////////////////////////////////////////////////////////////////////////////
19 19

  
20 20
precision highp float;
21
precision highp uint;
21
precision highp int;
22 22

  
23 23
#if __VERSION__ != 100
24 24
out vec4 fragColor;           // The output color
......
56 56
// This arranges fragments by decreasing 'depth', so one would think - from back to front, but
57 57
// in main() below the depth is mapped with S*(1-depth)/2, so it is really front to back.
58 58

  
59
void insert( vec2 ij, uint depth, uint rgba )
59
void insert2( vec2 ij, uint depth, uint rgba )
60 60
  {
61
  uint ptr = atomicCounterIncrement(u_Counter)-1u;
61
/*
62
  uint index = uint(ij.x + ij.y * float(u_Size.x));
63
  u_Records[index] = (255u<<24u)+ uint( (int(255*int(ij.y)/u_Size.y))<<16u ) + (255u);
64
  discard;
65
*/
66

  
67
  uint ptr = atomicCounterIncrement(u_Counter);
62 68

  
63 69
  if( ptr<u_numRecords )
64
    {/*
65
    uint color;
66
    vec2 c = vec2(0.0,1.0);
70
    {
71
    ptr = ptr /*uint(ij.x + ij.y * float(u_Size.x))*/ + uint(u_Size.x*u_Size.y);
67 72

  
68
    uint rgb = ((uint(255.0*c.x))<<16u) + uint(255.0*c.y);
73
    u_Records[ptr   ] = (255u<<( (4*int(ij.x) > u_Size.x) ? 24u:16u)) + (255u);
74
    //u_Records[ptr+1u] = depth;
75
    //u_Records[ptr+2u] = rgba;
69 76

  
70
         if(  rgb       ==  0u ) color = (255u<<24u) + (255u<<16u) + 255u;
71
    else if( (rgb&255u) ==  0u ) color = (255u<<24u) + 255u;
72
    else if( (rgb&255u) <= 50u ) color = (255u<<16u) + 255u;
73
    else if( (rgb&255u) == 255u) color = (255u<<16u) + (255u<< 8u) + 255u;
74
    else                         color = (255u<< 8u) + 255u;
75
*/
76
vec4 c= vec4(1.0,1.0,0.0,1.0);
77
uint color = ((uint(255.0*c.r))<<24u) + ((uint(255.0*c.g))<<16u) + ((uint(255.0*c.b))<<8u) + uint(255.0*c.a);
77
    uint index = uint(ij.x + ij.y * float(u_Size.x));
78
    u_Records[index] = ptr;
79
    discard;
80
    }
81
  }
82

  
83
void insert( vec2 ij, uint depth, uint rgba )
84
  {
85
  uint ptr = atomicCounterIncrement(u_Counter);
78 86

  
87
  if( ptr<u_numRecords )
88
    {
79 89
    ptr = 3u*ptr + uint(u_Size.x*u_Size.y);
80 90

  
81 91
    u_Records[ptr   ] = 0u;
......
138 148
  {
139 149
  vec4 frag  = TEXTURE(u_Texture     , v_TexCoordinate);
140 150
  float depth= TEXTURE(u_DepthTexture, v_TexCoordinate).r;
141

  
151
/*
142 152
  if( frag.a > 0.95 )
143 153
    {
144 154
    gl_FragDepth = depth;
145 155
    FRAG_COLOR   = frag;
146 156
    }
147 157
  else if( frag.a > 0.0 )
148
    {
158
    {*/
149 159
    const float S= 2147483647.0; // max signed int. Could probably be max unsigned int but this is enough.
150
    insert(v_Pixel, uint(S*(1.0-depth)/2.0), convert(frag) );
151
    discard;
152
    }
160
    insert2(v_Pixel, uint(S*(1.0-depth)/2.0), convert(frag) );
161
    //}
153 162
  }

Also available in: Unified diff