Temporal Reprojection

Started by
0 comments, last by Andimus 9 years ago

Hi

So I'm trying recreate the method of temporal reprojection from Killzone: Shadowfall; see this article for details, in DirectX 11.

In the vertical shader I calculate the current vertex position as normal along with its previous position using the previous matrices. The previous position is passed to the pixel shader with texcoord semantic as suggested by Nehab here. In the pixel shader i calculate its colour and along with a motion vector in a rwbuffer. Using the information I reconstruct the frame in a compute shader.

however I'm a little lost about how to calculate the the motion vector in the pixel shader. The motion vector is in the direction the pixel is moving in screen space, which the the current position will be in, but what about the previous position? I seem to be just getting garbage. I am I missing something or just misunderstanding the problem?

Any help would be appreciated

Andrew

Advertisement

Sorry the post was a bit vague, I'll try and clear up my problem now.

So I am trying to find a pixels previous position in screen space in DirectX 11. The vertex shader is looking like this.

PixelInputType Main(VertexInputType input)
{
PixelInputType output;

// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(float4(input.position.xyz, 1.0f), worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);

output.prevPosition = mul(float4(input.position.xyz, 1.0f), prevWorld);
output.prevPosition = mul(output.prevPosition, prevView);
output.prevPosition = mul(output.prevPosition, prevProj);

// Store the texture coordinates for the pixel shader.
output.tex = input.tex;

return output;
}

Here we are calculating the vertex's current and previous position. The current position is being passed to the pixel shader as a sv_position and the previous positon as a texture coordinate. The pixel shader is looking like this.

float4 Main(PixelInputType input) : SV_TARGET
{
float4 prevPosition = input.prevPosition;

prevPosition.xyz /= prevPosition.w;
prevPosition.xy *= float2(0.5, -0.5);
prevPosition.xy += 0.5f;
prevPosition.xy *= resolution;

float2 motion = input.position.xy - prevPosition.xy;
....//other stuff
}

I'm dividing the previous position by w to get the homogeneous coordinates, adjusting the coordinates then multiplying by the resolution. I thought this would get me the screen space coordinates of the pixel so I can calculate a motion vector. But I'm not getting any sensible values.

Does anyone have any suggestions?

This topic is closed to new replies.

Advertisement