[12115] | 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 | |
---|
| 7 | uniform sampler2D tex: register(s0); |
---|
| 8 | |
---|
| 9 | static const float samples[10] = |
---|
| 10 | { |
---|
| 11 | -0.08, |
---|
| 12 | -0.05, |
---|
| 13 | -0.03, |
---|
| 14 | -0.02, |
---|
| 15 | -0.01, |
---|
| 16 | 0.01, |
---|
| 17 | 0.02, |
---|
| 18 | 0.03, |
---|
| 19 | 0.05, |
---|
| 20 | 0.08 |
---|
| 21 | }; |
---|
| 22 | |
---|
| 23 | float4 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 | } |
---|