1
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
|
20
|
precision lowp float;
|
21
|
|
22
|
#if __VERSION__ != 100
|
23
|
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
|
#define TEXTURE texture
|
28
|
#define FRAG_COLOR fragColor
|
29
|
#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
|
#define TEXTURE texture2D
|
34
|
#define FRAG_COLOR gl_FragColor
|
35
|
#endif
|
36
|
|
37
|
uniform sampler2D u_Texture; // The input texture.
|
38
|
|
39
|
#if NUM_FRAGMENT>0
|
40
|
uniform int fNumEffects; // total number of fragment effects
|
41
|
uniform int fName[NUM_FRAGMENT]; // their namess.
|
42
|
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
|
#endif // NUM_FRAGMENT>0
|
45
|
|
46
|
layout (std430,binding=0) buffer SSBO // PER-SURFACE count of transparent fragments.
|
47
|
{ // Can be buffered, i.e. if we are for example
|
48
|
int ssbocount[]; // triple-buffered, then surfaceID=N uses 3
|
49
|
}; // consecutive counts (N,N+1,N+2) during 3
|
50
|
// consecutive frames.
|
51
|
uniform int u_currentIndex; // Index into the count[] array we are supposed to be using
|
52
|
// during this very invocation.
|
53
|
|
54
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
55
|
|
56
|
void main()
|
57
|
{
|
58
|
vec4 color = TEXTURE(u_Texture,v_TexCoordinate);
|
59
|
|
60
|
#if NUM_FRAGMENT>0
|
61
|
vec2 diff;
|
62
|
float degree;
|
63
|
int effect=0;
|
64
|
|
65
|
for(int i=0; i<fNumEffects; i++)
|
66
|
{
|
67
|
diff = (v_Position.xy - fUniforms[effect+1].xy)/fUniforms[effect+1].zw;
|
68
|
degree = max(0.0,1.0-dot(diff,diff));
|
69
|
|
70
|
// ENABLED EFFECTS WILL BE INSERTED HERE
|
71
|
|
72
|
effect+=2;
|
73
|
}
|
74
|
#endif
|
75
|
|
76
|
ssbocount[u_currentIndex]= 27 + u_currentIndex;
|
77
|
|
78
|
FRAG_COLOR = vec4(color.rgb * (1.0 + 7.0*v_Normal.z) * 0.125, color.a);
|
79
|
}
|