Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/GLSL150/Radial_Blur_FP.glsl @ 12115

Last change on this file since 12115 was 12115, checked in by wiesep, 6 years ago

Changed folder structure, deletet some unused files and cleaned up code

File size: 1.5 KB
Line 
1#version 150
2
3//------------------------------------------------------
4//Radial_Blur_FP.glsl
5//  Implements radial blur to be used with the compositor
6//  It's very dependent on screen resolution
7//------------------------------------------------------
8
9uniform sampler2D tex;
10uniform float sampleDist;
11uniform float sampleStrength;
12
13in vec2 oUv0;
14out vec4 fragColour;
15
16void main()
17{
18        float samples[10];
19       
20        samples[0] = -0.08;
21        samples[1] = -0.05;
22        samples[2] = -0.03;
23        samples[3] = -0.02;
24        samples[4] = -0.01;
25        samples[5] = 0.01;
26        samples[6] = 0.02;
27        samples[7] = 0.03;
28        samples[8] = 0.05;
29        samples[9] = 0.08;
30       
31   //Vector from pixel to the center of the screen
32   vec2 dir = 0.5 - oUv0;
33
34   //Distance from pixel to the center (distant pixels have stronger effect)
35   //float dist = distance( vec2( 0.5, 0.5 ), texCoord );
36   float dist = sqrt( dir.x*dir.x + dir.y*dir.y );
37
38
39   //Now that we have dist, we can normlize vector
40   dir = normalize( dir );
41
42   //Save the color to be used later
43   vec4 color = texture( tex, oUv0 );
44   //Average the pixels going along the vector
45   vec4 sum = color;
46   for (int i = 0; i < 10; i++)
47   {
48      vec4 res=texture( tex, oUv0 + dir * samples[i] * sampleDist );
49      sum += res;
50   }
51   sum /= 11.0;
52
53   //Calculate amount of blur based on
54   //distance and a strength parameter
55   float t = dist * sampleStrength;
56   t = clamp( t, 0.0, 1.0 );//We need 0 <= t <= 1
57
58   //Blend the original color with the averaged pixels
59   fragColour = mix( color, sum, t );
60}
Note: See TracBrowser for help on using the repository browser.