Advertisement
Noneatme

Untitled

Jan 11th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. //
  2. // radial_blur.fx
  3. //
  4.  
  5. //---------------------------------------------------------------------
  6. // Settings
  7. //---------------------------------------------------------------------
  8. texture sSceneTexture;
  9. texture sRadialMaskTexture;
  10. float sLengthScale = 1;
  11. float2 sMaskScale = float2(3,1.5);
  12. float2 sMaskOffset = float2(0,-0.15);
  13. float sVelZoom = 1;
  14. float2 sVelDir = float2(0,0);
  15. float sAmount = 0;
  16.  
  17.  
  18. //---------------------------------------------------------------------
  19. // Include some common stuff
  20. //---------------------------------------------------------------------
  21. #include "mta-helper.fx"
  22.  
  23.  
  24. //---------------------------------------------------------------------
  25. // Sampler for the main texture
  26. //---------------------------------------------------------------------
  27. sampler Sampler0 = sampler_state
  28. {
  29. Texture = (sSceneTexture);
  30. MinFilter = Linear;
  31. MagFilter = Linear;
  32. MipFilter = Linear;
  33. AddressU = Mirror;
  34. AddressV = Mirror;
  35. };
  36.  
  37. //---------------------------------------------------------------------
  38. // Sampler for the radial mask
  39. //---------------------------------------------------------------------
  40. sampler SamplerMask = sampler_state
  41. {
  42. Texture = (sRadialMaskTexture);
  43. MinFilter = Linear;
  44. MagFilter = Linear;
  45. MipFilter = Linear;
  46. AddressU = Clamp;
  47. AddressV = Clamp;
  48. };
  49.  
  50.  
  51. //---------------------------------------------------------------------
  52. // Structure of data sent to the vertex shader
  53. //---------------------------------------------------------------------
  54. struct VSInput
  55. {
  56. float3 Position : POSITION;
  57. float4 Diffuse : COLOR0;
  58. float2 TexCoord0 : TEXCOORD0;
  59. };
  60.  
  61.  
  62. //---------------------------------------------------------------------
  63. // Structure of data sent to the pixel shader ( from the vertex shader )
  64. //---------------------------------------------------------------------
  65. struct PSInput
  66. {
  67. float4 Pos: POSITION;
  68. float2 texCoord0: TEXCOORD0;
  69. float2 texCoord1: TEXCOORD1;
  70. };
  71.  
  72.  
  73. //------------------------------------------------------------------------------------------
  74. // VertexShaderFunction
  75. // 1. Read from VS structure
  76. // 2. Process
  77. // 3. Write to PS structure
  78. //------------------------------------------------------------------------------------------
  79. PSInput VertexShaderFunction(VSInput VS)
  80. {
  81. PSInput PS = (PSInput)0;
  82.  
  83. PS.Pos = mul(float4(VS.Position, 1), gWorldViewProjection);
  84.  
  85. PS.texCoord0 = VS.TexCoord0;
  86. PS.texCoord1.x = ( VS.TexCoord0.x - 0.5 ) * sMaskScale.x + 0.5;
  87. PS.texCoord1.y = ( VS.TexCoord0.y - 0.5 ) * sMaskScale.y + 0.5;
  88.  
  89. PS.texCoord1 += sMaskOffset;
  90.  
  91. return PS;
  92. }
  93.  
  94. //------------------------------------------------------------------------------------------
  95. // PixelShaderFunction
  96. // 1. Read from PS structure
  97. // 2. Process
  98. // 3. Return pixel color
  99. //------------------------------------------------------------------------------------------
  100. float4 PixelShaderFunction(
  101. float2 texCoord0: TEXCOORD0,
  102. float2 texCoord1: TEXCOORD1,
  103. uniform int numsteps
  104. ) : COLOR
  105. {
  106.  
  107. // Vector from pixel to the center of the screen
  108. float2 dir = 0.5 - texCoord0;
  109.  
  110. float mixAmount = sAmount;
  111. float lengthAmount = lerp(0.5, 1, sAmount) * sLengthScale;
  112.  
  113. if ( sVelZoom < 0 )
  114. {
  115. dir *= sVelZoom * lengthAmount * 2;
  116. dir += sVelDir * lengthAmount * 2;
  117. }
  118. else
  119. {
  120. dir += dir * sVelZoom * lengthAmount;
  121. dir += sVelDir * lengthAmount * 2;
  122. dir += sVelDir * lengthAmount * 2 * sVelZoom;
  123. }
  124.  
  125. // Average the pixels going along the vector
  126. float4 sum = 0;
  127. float weightTotal = 0;
  128. for (int i = 0; i < numsteps; i++)
  129. {
  130. float u = i / (float)numsteps;
  131. float weight = 1 - u;
  132. float s = 0.01 + i * 0.005;
  133. s += i*(i*0.2)*0.001;
  134. sum += tex2D( Sampler0, texCoord0 + dir * s * 1.2 * lengthAmount) * weight;
  135. weightTotal += weight;
  136. }
  137. sum /= weightTotal;
  138.  
  139.  
  140. float4 mask = tex2D( SamplerMask, texCoord1 );
  141. float t = mask.a;
  142.  
  143. t *= mixAmount;
  144. t = min(0.7,t);
  145. float4 finalColor = sum;
  146. finalColor.b *= 0.85;
  147. finalColor.a = t;
  148.  
  149. return finalColor;
  150. }
  151.  
  152.  
  153. //-----------------------------------------------------------------------------
  154. // Techniques
  155. //-----------------------------------------------------------------------------
  156. technique tec10
  157. {
  158. pass P0
  159. {
  160. VertexShader = compile vs_2_0 VertexShaderFunction();
  161. PixelShader = compile ps_2_0 PixelShaderFunction(10);
  162. }
  163. }
  164.  
  165. technique tec6
  166. {
  167. pass P0
  168. {
  169. VertexShader = compile vs_2_0 VertexShaderFunction();
  170. PixelShader = compile ps_2_0 PixelShaderFunction(6);
  171. }
  172. }
  173.  
  174. technique fallback
  175. {
  176. pass P0
  177. {
  178. }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement