[5312] | 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 | |
---|
| 7 | uniform sampler 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(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 | } |
---|