//**************************************************************************/ // Copyright 2014 Autodesk, Inc. // All rights reserved. // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. //**************************************************************************/ #include "Common.ogsfh" // Specify a default blur amount (number of samples in each direction, or the "radius" of the box // filter) if none is specified. Use to determine the number of samples per pixel, including the // center sample. // NOTE: This can have a maximum value of 12 to work within SM2. #ifndef BLUR_AMOUNT #define BLUR_AMOUNT 10 #endif // The source buffer and sampler. uniform texture2D gSourceTex; uniform sampler2D gSourceSamp = sampler_state { texture = ; }; uniform vec4 gUVTransform : RelativeViewportDimensions; GLSLShader PS_BlurHoriz { void main() { vec2 direction = vec2(1.0f, 0.0f); // TODO int numSamples = BLUR_AMOUNT * 2 + 1; vec2 texelSize = 1.0 / gScreenSize; // Compute the per-sample offset, based on the texel size and blur direction. Then compute the // location of the starting sample, using the number of taps. vec2 offset = direction * texelSize; vec2 UV = VSUV * gUVTransform.zw + gUVTransform.xy - offset * (numSamples - 1) * 0.5f; // Sum each of the samples (box filter). vec4 sum = vec4(0, 0, 0, 0); for (int i = 0; i < numSamples; i++) { // Add the value from the source texture. sum += texture2D(gSourceSamp, clamp(UV, 0.0f, 1.0f)); // Increment the texture coordinates by the offset. UV += offset; } // Return the average color and alpha. colorOut = sum / numSamples; } } GLSLShader PS_BlurVert { void main() { vec2 direction = vec2(0.0f, 1.0f); int numSamples = BLUR_AMOUNT * 2 + 1; vec2 texelSize = 1.0 / gScreenSize; // Compute the per-sample offset, based on the texel size and blur direction. Then compute the // location of the starting sample, using the number of taps. vec2 offset = direction * texelSize; vec2 UV = VSUV * gUVTransform.zw + gUVTransform.xy - offset * (numSamples - 1) * 0.5f; // Sum each of the samples (box filter). vec4 sum = vec4(0, 0, 0, 0); for (int i = 0; i < numSamples; i++) { // Add the value from the source texture. sum += texture2D(gSourceSamp, clamp(UV, 0.0f, 1.0f)); // Increment the texture coordinates by the offset. UV += offset; } // Return the average color and alpha. colorOut = sum / numSamples; } } // Horizontal blur technique. technique BlurHoriz { pass p0 { VertexShader (in VS_INPUT_ScreenQuad, out VS_TO_PS_ScreenQuad) = VS_ScreenQuad; PixelShader (in VS_TO_PS_ScreenQuad, out pixelOut) = PS_BlurHoriz; } } // Vertical blur technique. technique BlurVert { pass p0 { VertexShader (in VS_INPUT_ScreenQuad, out VS_TO_PS_ScreenQuad) = VS_ScreenQuad; PixelShader (in VS_TO_PS_ScreenQuad, out pixelOut) = PS_BlurVert; } }