Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/Radial_Blur_FP.glsles @ 12091

Last change on this file since 12091 was 12091, checked in by wiesep, 5 years ago

Updated programs and adjusted Material to work with GLSL>150

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