aboutsummaryrefslogtreecommitdiff
path: root/engine/src/core-data/Common/MatDefs/Blur/RadialBlur15.frag
blob: cc403501ba9cc93792629cf6908f4e85a9a08a56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#import "Common/ShaderLib/MultiSample.glsllib"

uniform COLORTEXTURE m_Texture;
uniform float m_SampleDist;
uniform float m_SampleStrength;
uniform float m_Samples[10];

in vec2 texCoord;
out vec4 outFragColor;

void main(void)
{
   // some sample positions
   //float samples[10] =   float[](-0.08,-0.05,-0.03,-0.02,-0.01,0.01,0.02,0.03,0.05,0.08);

    // 0.5,0.5 is the center of the screen
    // so substracting texCoord from it will result in
    // a vector pointing to the middle of the screen
    vec2 dir = 0.5 - texCoord;

    // calculate the distance to the center of the screen
    float dist = sqrt(dir.x*dir.x + dir.y*dir.y);

    // normalize the direction (reuse the distance)
    dir = dir/dist;

    // this is the original colour of this fragment
    // using only this would result in a nonblurred version
    vec4 colorRes = getColor(m_Texture,texCoord);

    vec4 sum = colorRes;

    // take 10 additional blur samples in the direction towards
    // the center of the screen
    for (int i = 0; i < 10; i++){
      sum += getColor( m_Texture, texCoord + dir * m_Samples[i] * m_SampleDist );
    }

    // we have taken eleven samples
    sum *= 1.0/11.0;

    // weighten the blur effect with the distance to the
    // center of the screen ( further out is blurred more)
    float t = dist * m_SampleStrength;
    t = clamp( t ,0.0,1.0); //0 &lt;= t &lt;= 1

    //Blend the original color with the averaged pixels
    outFragColor =mix( colorRes, sum, t );
     
}