Project

General

Profile

« Previous | Next » 

Revision 33f59f22

Added by Leszek Koltunski almost 6 years ago

OIT: move towards 4 passes ( clear - build - collapse - render )

View differences:

src/main/res/raw/oit_render_fragment_shader.glsl
24 24
in vec2 v_TexCoordinate;      // Interpolated texture coordinate per fragment.
25 25
in vec2 v_Pixel;              // location of the current fragment, in pixels
26 26

  
27
uniform sampler2D u_Texture;
28
uniform sampler2D u_DepthTexture;
29

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

  
......
54 51
  }
55 52

  
56 53
//////////////////////////////////////////////////////////////////////////////////////////////
57
// Pass3 of the OIT algorithm - traverse the per-pixel LinkedList and build the final color.
54
// Pass4 of the OIT algorithm - keep traversing the linked list, build the final color and blend it.
58 55

  
59 56
void main()                    		
60 57
  {
61
  float texdepth = texture(u_DepthTexture, v_TexCoordinate).r;
62
  vec4  color    = texture(u_Texture     , v_TexCoordinate);
63
  uint  index    = uint(v_Pixel.x + v_Pixel.y * u_Size.x);
64
  uint  curr     = u_Records[index];
58
  uint prev = uint(v_Pixel.x + v_Pixel.y * u_Size.x);
59
  uint curr = u_Records[prev];
65 60

  
66 61
  if (curr != 0u)
67 62
    {
68 63
    const float S= 2147483647.0;
69
    uint depth = u_Records[curr+1u];
70
    uint texdepthuint = uint(S*(1.0-texdepth)/2.0);
71
    texdepth = 1.0 -2.0*float(depth)/S;
64
    gl_FragDepth = 1.0 - 2.0*float(u_Records[curr+1u])/S;
65
    vec4 color   = convert(u_Records[curr+2u]);
72 66

  
73
    if( depth >= texdepthuint )
67
    while (curr != 0u)
74 68
      {
75
      vec4 clr= convert(u_Records[curr+2u]);
76 69
      curr = u_Records[curr];
77

  
78
      while (curr > 0u)
79
        {
80
        depth= u_Records[curr+1u];                       // keep walking the linked list
81
        if( depth < texdepthuint ) break;                // until we reach scene depth
82
        clr= blend( clr, convert(u_Records[curr+2u]) );  // and blending the colors in
83
        curr = u_Records[curr];
84
        }
85

  
86
      color = blend( clr, color);
70
      color = blend( color , convert(u_Records[curr+2u]) );
87 71
      }
88
    }
89 72

  
90
  gl_FragDepth = texdepth;
91
  fragColor    = color;
73
    fragColor = color;
74
    }
75
  else discard;
92 76
  }

Also available in: Unified diff