• Advertisement
Sign in to follow this  

Motion Blur Post Effect In XNA

This topic is 2772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone I am having a problem implimenting a shader/sample provided by matt at

http://mynameismjp.wordpress.com/samples-tutorials-tools/motion-blur-sample/

i have managed to get all of into my project and as far as i can tell everything is being passed correctly to the shader (obviosly not...) but it seems to render a strong blur even when the camera is not moving, and i have checked to make sure the camera values are correct (or as far as i can tell)

I know its not the depth buffer as it still happens even if i hardcode the depth returned from the buffer in the shader.

Does anyone have any idea?

I had to inverse the depth returned from the depth texture because mine is inverted, i am using a deffered engine if that helps.

here is a snippit of the shader code (I hope matt doesn't mind me posting it)


float4 MotionBlur(float2 vTexCoord, float2 vPixelVelocity, int iNumSamples)
{
// Clamp to a max velocity. The max we can go without artifacts os
// is 1.4f * iNumSamples...but we can fudge things a little.
float2 maxVelocity = (2.4f * iNumSamples) / g_vSourceDimensions;
vPixelVelocity = clamp(vPixelVelocity, -maxVelocity, maxVelocity);

float2 vFinalSamplePos = vTexCoord + vPixelVelocity;

// For each sample, sum up each sample's color in "vSum" and then divide
// to average the color after all the samples are added.
float4 vSum = 0;
for(int i = 0; i < iNumSamples; i++)
{
// Sample texture in a new spot based on vPixelVelocity vector
// and average it with the other samples
float2 vSampleCoord = vTexCoord + (vPixelVelocity * (i / (float)iNumSamples));

// Lookup the color at this new spot
float4 vSample = tex2D(PointSampler0, vSampleCoord);

// Add it with the other samples
vSum += vSample;
}

// Return the average color of all the samples
return vSum / (float)iNumSamples;
}

float4 DepthMotionBlurPS ( in float2 in_vTexCoord : TEXCOORD0, in float3 in_vFrustumPlaneVS : TEXCOORD1, uniform int iNumSamples) : COLOR0
{
// Reconstruct view-space position from the depth buffer
float fPixelDepthVS = -(tex2D(PointSampler1, in_vTexCoord).x);
float3 vPixelPositionVS = fPixelDepthVS * in_vFrustumPlaneVS;

// Convert to world-space, then determine the the clip-space
// position of the pixel in the previous frame.
float4 vPixelPositionWS = mul(float4(vPixelPositionVS, 1.0f), g_matInvView);
float4 vLastPixelPosCS = mul(vPixelPositionWS, g_matLastViewProj);

// Find the corresponding texture coordinate
float2 vLastTexCoord = vLastPixelPosCS.xy / vLastPixelPosCS.w;
vLastTexCoord = (vLastTexCoord / 2.0f) + 0.5f;
vLastTexCoord.y = 1.0f - vLastTexCoord.y;
vLastTexCoord += 0.5f / g_vDestinationDimensions;

float2 vPixelVelocity = in_vTexCoord - vLastTexCoord;

return MotionBlur(in_vTexCoord, vPixelVelocity, iNumSamples);
}




Here is a small pic of what it does when the camera isn't moving.


Any help would be great :)
Thanks all for reading

Share this post


Link to post
Share on other sites
Advertisement
Ive spent all day on this with pix and sadly i'm no closer. Does anyone know how matt (who made the sample) can be reached? His website says he frequents here :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement