Revision 375b3950
Added by Leszek Koltunski about 6 years ago
src/main/res/raw/blit_depth_render_fragment_shader.glsl | ||
---|---|---|
20 | 20 |
precision highp float; |
21 | 21 |
precision highp int; |
22 | 22 |
|
23 |
out vec4 fragColor; |
|
24 |
in vec2 v_TexCoordinate; |
|
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. |
|
25 | 31 |
|
26 | 32 |
uniform vec2 u_Size; |
27 | 33 |
|
28 |
layout (std430,binding=1) buffer linkedlist |
|
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 |
|
|
42 |
vec4 convert(uint rgba) |
|
29 | 43 |
{ |
30 |
uint u_Records[]; |
|
31 |
}; |
|
44 |
return vec4( float((rgba>>24u)&255u),float((rgba>>16u)&255u),float((rgba>>8u)&255u),float(rgba&255u) ) / 255.0; |
|
45 |
} |
|
46 |
|
|
47 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
// https://en.wikipedia.org/wiki/Alpha_compositing (premultiplied) |
|
49 |
|
|
50 |
vec4 blend(vec4 clr,vec4 srf) |
|
51 |
{ |
|
52 |
return clr + (1.0 - clr.a) * vec4(srf.rgb * srf.a , srf.a); |
|
53 |
} |
|
32 | 54 |
|
33 | 55 |
////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 56 |
|
35 | 57 |
void main() |
36 | 58 |
{ |
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); |
|
59 |
uint index = uint(v_Pixel.x + v_Pixel.y * u_Size.x); |
|
60 |
uint curr = u_Records[index]; |
|
61 |
|
|
62 |
if (curr == 0u) discard; |
|
63 |
|
|
64 |
vec4 color= vec4(0.0,0.0,0.0,0.0); |
|
65 |
u_Records[index] = 0u; |
|
40 | 66 |
|
41 |
uint ptr = u_Records[index]; |
|
42 |
uint color = u_Records[ptr]; |
|
43 |
//u_Records[ptr] = 0u; |
|
67 |
while (curr > 0u) |
|
68 |
{ |
|
69 |
color= blend( color, convert(u_Records[curr+2u]) ); // keep walking the linked list |
|
70 |
curr = u_Records[curr]; // and blending the colors in |
|
71 |
} |
|
44 | 72 |
|
45 |
if( color==index ) fragColor = vec4(0.0,1.0,0.0,1.0);
|
|
46 |
else fragColor = vec4(1.0,0.0,0.0,1.0);
|
|
73 |
gl_FragDepth = texture(u_DepthTexture, v_TexCoordinate).r;
|
|
74 |
fragColor = color;
|
|
47 | 75 |
} |
Also available in: Unified diff
OIT: something starts working ('Blur' and 'Multiblur' work, 'Triblur' and 'Transparency' do not)