Project

General

Profile

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

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

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 mediump 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
//////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
void main()                    		
49
  {  
50
  vec4 color = TEXTURE(u_Texture,v_TexCoordinate);
51

    
52
#if NUM_FRAGMENT>0
53
  vec2 diff;
54
  float degree;
55
  int effect=0;
56

    
57
  for(int i=0; i<fNumEffects; i++)
58
    {
59
    diff   = (v_Position.xy - fUniforms[effect+1].xy)/fUniforms[effect+1].zw;
60
    degree = max(0.0,1.0-dot(diff,diff));
61

    
62
    // ENABLED EFFECTS WILL BE INSERTED HERE
63

    
64
    effect+=2;
65
    }
66
#endif
67

    
68
  FRAG_COLOR = vec4(color.rgb * (1.0 + 7.0*v_Normal.z) * 0.125, color.a);
69
  }
(6-6/9)