Project

General

Profile

Download (4.47 KB) Statistics
| Branch: | Revision:

library / src / main / res / raw / main_fragment_shader.glsl @ 2faad666

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
                                        // 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
uniform int u_currentIndex;             // Index into the count[] array we are supposed to be using
57
                                        // during this very invocation.
58

    
59
//////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
void main()                    		
62
  {  
63
  vec4 color = TEXTURE(u_Texture,v_TexCoordinate);
64

    
65
#if NUM_FRAGMENT>0
66
  vec2 diff;
67
  float degree;
68
  int effect=0;
69

    
70
  for(int i=0; i<fNumEffects; i++)
71
    {
72
    diff   = (v_Position.xy - fUniforms[effect+1].xy)/fUniforms[effect+1].zw;
73
    degree = max(0.0,1.0-dot(diff,diff));
74

    
75
    // ENABLED EFFECTS WILL BE INSERTED HERE
76

    
77
    effect+=2;
78
    }
79
#endif
80

    
81
  if( color.a < 1.0 && color.a > 0.0 ) atomicAdd(ssbocount[u_currentIndex],1);
82

    
83
  FRAG_COLOR = vec4(color.rgb * (1.0 + 7.0*v_Normal.z) * 0.125, color.a);
84
  }
(5-5/8)