Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Cg/Radial_Blur_FP.cg

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

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

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 dependent on screen resolution
5//------------------------------------------------------
6
7uniform sampler2D 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(float4 Pos : POSITION,
24            float2 texCoord: TEXCOORD0,
25            uniform float sampleDist,
26            uniform float sampleStrength
27           ) : COLOR
28{
29   //Vector from pixel to the center of the screen
30   float2 dir = 0.5 - texCoord;
31
32   //Distance from pixel to the center (distant pixels have stronger effect)
33   //float dist = distance( float2( 0.5, 0.5 ), texCoord );
34   float dist = sqrt( dir.x*dir.x + dir.y*dir.y );
35
36
37   //Now that we have dist, we can normlize vector
38   dir = normalize( dir );
39
40   //Save the color to be used later
41   float4 color = tex2D( tex, texCoord );
42   //Average the pixels going along the vector
43   float4 sum = color;
44   for (int i = 0; i < 10; i++)
45   {
46      float4 res=tex2D( tex, texCoord + dir * samples[i] * sampleDist );
47      sum += res;
48   }
49   sum /= 11;
50
51   //Calculate amount of blur based on
52   //distance and a strength parameter
53   float t = dist * sampleStrength;
54   t = saturate( t );//We need 0 <= t <= 1
55
56   //Blend the original color with the averaged pixels
57   return lerp( color, sum, t );
58}
Note: See TracBrowser for help on using the repository browser.