1 |
d333eb6b
|
Leszek Koltunski
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 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 |
6a06a912
|
Leszek Koltunski
|
|
20 |
8cefe6a3
|
Leszek Koltunski
|
precision lowp float;
|
21 |
94f6d472
|
Leszek Koltunski
|
|
22 |
|
|
#if __VERSION__ != 100
|
23 |
f2367b75
|
Leszek Koltunski
|
in vec3 v_Position; // Interpolated position for this fragment.
|
24 |
|
|
in vec3 v_Normal; // Interpolated normal for this fragment.
|
25 |
|
|
in vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment.
|
26 |
|
|
out vec4 fragColor; // The output color
|
27 |
1cbf4103
|
leszek
|
#define TEXTURE texture
|
28 |
|
|
#define FRAG_COLOR fragColor
|
29 |
94f6d472
|
Leszek Koltunski
|
#else
|
30 |
|
|
varying vec3 v_Position; // Interpolated position for this fragment.
|
31 |
|
|
varying vec3 v_Normal; // Interpolated normal for this fragment.
|
32 |
|
|
varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment.
|
33 |
1cbf4103
|
leszek
|
#define TEXTURE texture2D
|
34 |
|
|
#define FRAG_COLOR gl_FragColor
|
35 |
94f6d472
|
Leszek Koltunski
|
#endif
|
36 |
|
|
|
37 |
|
|
uniform sampler2D u_Texture; // The input texture.
|
38 |
6a06a912
|
Leszek Koltunski
|
|
39 |
|
|
#if NUM_FRAGMENT>0
|
40 |
ad33f883
|
Leszek Koltunski
|
uniform int fNumEffects; // total number of fragment effects
|
41 |
15aa7d94
|
Leszek Koltunski
|
uniform int fName[NUM_FRAGMENT]; // their namess.
|
42 |
2fce34f4
|
Leszek Koltunski
|
uniform vec4 fUniforms[2*NUM_FRAGMENT]; // i-th effect is 2 consecutive vec4's: [2*i], [2*i+1]. First vec4 is the Interpolated values,
|
43 |
|
|
// next describes the Region, i.e. area over which the effect is active.
|
44 |
03cb451d
|
Leszek Koltunski
|
#endif // NUM_FRAGMENT>0
|
45 |
6a06a912
|
Leszek Koltunski
|
|
46 |
27cd6b98
|
Leszek Koltunski
|
layout (std430,binding=0) buffer SSBO // PER-SURFACE count of transparent fragments.
|
47 |
12f45260
|
Leszek Koltunski
|
{ // Can be buffered, i.e. if we are for example
|
48 |
2ab60f72
|
Leszek Koltunski
|
int ssbocount[]; // triple-buffered, then surfaceID=N uses 3
|
49 |
12f45260
|
Leszek Koltunski
|
}; // consecutive counts (N,N+1,N+2) during 3
|
50 |
|
|
// consecutive frames.
|
51 |
df4d7edc
|
Leszek Koltunski
|
// Cannot be an 'uint' because the Java application that's
|
52 |
|
|
// reading this does not have unsigned types so it's reading
|
53 |
|
|
// this into a signed int... Doesn't matter as things keep on
|
54 |
|
|
// working even when this overflows into negative territory :)
|
55 |
|
|
|
56 |
12f45260
|
Leszek Koltunski
|
uniform int u_currentIndex; // Index into the count[] array we are supposed to be using
|
57 |
|
|
// during this very invocation.
|
58 |
|
|
|
59 |
6a06a912
|
Leszek Koltunski
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
60 |
|
|
|
61 |
|
|
void main()
|
62 |
|
|
{
|
63 |
7cd24173
|
leszek
|
vec4 color = TEXTURE(u_Texture,v_TexCoordinate);
|
64 |
4018b3b7
|
Leszek Koltunski
|
|
65 |
|
|
#if NUM_FRAGMENT>0
|
66 |
6a06a912
|
Leszek Koltunski
|
vec2 diff;
|
67 |
7cd24173
|
leszek
|
float degree;
|
68 |
|
|
int effect=0;
|
69 |
03cb451d
|
Leszek Koltunski
|
|
70 |
6a06a912
|
Leszek Koltunski
|
for(int i=0; i<fNumEffects; i++)
|
71 |
|
|
{
|
72 |
7cd24173
|
leszek
|
diff = (v_Position.xy - fUniforms[effect+1].xy)/fUniforms[effect+1].zw;
|
73 |
|
|
degree = max(0.0,1.0-dot(diff,diff));
|
74 |
341c803d
|
Leszek Koltunski
|
|
75 |
7cd24173
|
leszek
|
// ENABLED EFFECTS WILL BE INSERTED HERE
|
76 |
03cb451d
|
Leszek Koltunski
|
|
77 |
7cd24173
|
leszek
|
effect+=2;
|
78 |
6a06a912
|
Leszek Koltunski
|
}
|
79 |
|
|
#endif
|
80 |
ff8ad0a7
|
Leszek Koltunski
|
|
81 |
51a3cbab
|
Leszek Koltunski
|
if( color.a < 1.0 && color.a > 0.0 ) ssbocount[u_currentIndex]++;
|
82 |
12f45260
|
Leszek Koltunski
|
|
83 |
7cd24173
|
leszek
|
FRAG_COLOR = vec4(color.rgb * (1.0 + 7.0*v_Normal.z) * 0.125, color.a);
|
84 |
341c803d
|
Leszek Koltunski
|
}
|