Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/pool/programs/Radial_Blur_FP.cg @ 12373

Last change on this file since 12373 was 7708, checked in by dafrick, 14 years ago

Merging cleanup branch. You will need to update your data repository as well as your local copy of the code.

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1//------------------------------------------------------
2//Radial_Blur_FP.cg
3//  Implements radial blur to be used with the compositor
4//  It's very dependant on screen resolution
5//------------------------------------------------------
6
7uniform sampler tex: register(s0);
8
9static const float samples[10] =
10{
11-0.08,
12-0.05,
13-0.03,
14-0.02,
15-0.01,
160.01,
170.02,
180.03,
190.05,
200.08
21};
22
23float4 main(float2 texCoord: TEXCOORD0,
24            uniform float sampleDist,
25            uniform float sampleStrength
26           ) : COLOR
27{
28   //Vector from pixel to the center of the screen
29   float2 dir = 0.5 - texCoord;
30
31   //Distance from pixel to the center (distant pixels have stronger effect)
32   //float dist = distance( float2( 0.5, 0.5 ), texCoord );
33   float dist = sqrt( dir.x*dir.x + dir.y*dir.y );
34
35
36   //Now that we have dist, we can normlize vector
37   dir = normalize( dir );
38
39   //Save the color to be used later
40   float4 color = tex2D( tex, texCoord );
41
42   //Average the pixels going along the vector
43   float4 sum = color;
44   for (int i = 0; i < 10; i++)
45   {
46      sum += tex2D( tex, texCoord + dir * samples[i] * sampleDist );
47   }
48   sum /= 11;
49
50   //Calculate amount of blur based on
51   //distance and a strength parameter
52   float t = dist * sampleStrength;
53   t = saturate( t );//We need 0 <= t <= 1
54
55   //Blend the original color with the averaged pixels
56   return lerp( color, sum, t );
57}
Note: See TracBrowser for help on using the repository browser.