// Vertex Shader Output Structure struct vertexOutput { float4 position : POSITION; float2 tc0 : TEXCOORD0; // Centre float2 tco1 : TEXCOORD1; // Left Top float2 tco2 : TEXCOORD2; // Right Bottom float2 tco3 : TEXCOORD3; // Right Top float2 tco4 : TEXCOORD4; // Left Bottom }; float2 QuadScreenSize = {1280, 720}; // Vertex Shader // Simply passes the position and texture coords through vertexOutput motionBlurVP( float4 position : POSITION, float2 texCoord : TEXCOORD0 ) { vertexOutput OUT = (vertexOutput)0; OUT.position = position; float2 texelSize = 1.0 / QuadScreenSize; OUT.tc0 = texCoord; OUT.tco1 = float2(-texelSize.x, texelSize.y); OUT.tco2 = float2( texelSize.x,-texelSize.y); OUT.tco3 = float2( texelSize.x, texelSize.y); OUT.tco4 = float2(-texelSize.x,-texelSize.y); return OUT; } // Pixel Shader half4 motionBlurFP( vertexOutput IN, uniform sampler2D screenTexture, uniform sampler2D edgeTexture) : COLOR0 { half w = 1.h - tex2D(edgeTexture, IN.tc0).r; half w0 = tex2D(edgeTexture, IN.tc0 + (IN.tco1)).r; half w1 = tex2D(edgeTexture, IN.tc0 + (IN.tco2)).r; half w2 = tex2D(edgeTexture, IN.tc0 + (IN.tco3)).r; half w3 = tex2D(edgeTexture, IN.tc0 + (IN.tco4)).r; IN.tc0 += w0 * IN.tco1 * -2.h; IN.tc0 += w1 * IN.tco2 * -2.h; IN.tc0 += w2 * IN.tco3 * -2.h; IN.tc0 += w3 * IN.tco4 * -2.h; half4 s0 = tex2D(screenTexture, IN.tc0 + (IN.tco1));// * w0; half4 s1 = tex2D(screenTexture, IN.tc0 + (IN.tco2));// * w1; half4 s2 = tex2D(screenTexture, IN.tc0 + (IN.tco3));// * w2; half4 s3 = tex2D(screenTexture, IN.tc0 + (IN.tco4));// * w3; half4 screenColour = (s0 + s1 + s2 + s3)/4.h;//(w0 + w1 + w2 + w3); //screenColour *= w; return screenColour; } // Technique for combining Bloom and Depth of Field technique motionBlur { pass p0 { VertexProgram = compile vp30 motionBlurVP(); FragmentProgram = compile fp40 motionBlurFP(); DepthTestEnable = false; DepthMask = false; BlendEnable = true; BlendFuncSeparate = int4( Zero , SrcAlpha , Zero , One ) ; } }