<p>I'm trying to perform forward pixel projection based on previous frame depth. Using UV, I'm reading prevDepth for given pixel and based on that I'm recreating worldPos in camera space (where (0, 0, 0) is camera position). Then I offset this position using previous frame camera position to find prevWorldPos in camera space.</p>
<p>Then I'm doing standard matrix multiplication to get ndc and then prev frame uv. So, it works quite nice without any additional history buffer or using pixel neighbours, at least for camera rotation.</p>
<p><strong>When it comes to camera translation, value of prevUV is the same as uv and it results in no changes in affected pixels and it destroys the reprojection. And I don't understand why.</strong></p>
<pre><code>float3 worldPosition = GetWorldPosFromUV(uv, prevDepth); // Current frame worldPos in camera space
float3 prevWorldPosition = worldPosition + (currFrameCameraOffset - prevFrameCameraOffset); // Transform to camera space position in previous frame

float4 ndcPrev = mul(float4(prevWorldPosition, 1.0f), viewProjMatrixPrevFrame); 
ndcPrev.xyz /= ndcPrev.w;
float2 prevUV = ndcPrev.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f);

return prevUV;
</code></pre>
<p><a href="https://i.sstatic.net/I0NZc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/I0NZc.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2022-09-20T19:57:31.683Z
Why do you use the previous frame depth buffer with the current frame UV? That doesn't seem to make sense. Wouldn't you use the current frame depth buffer to get the current frame world position?
Nathan Reed
CC BY-SA 4.0
2022-09-20T20:48:47.880Z
@NathanReed Sorry, I didn't make it clear. I'm using kind of "special" buffer which is tracking depth of special objects not available in normal depth buffer. I'm working on optimization to calculate pixels only when something changes, because that objects are really expensive to render. So if I skip calculation for that pixels, I lack "special" depth buffer for current frame and I have to use previous frame depth.
DirectX_Programmer
<matrix><depth-map>
Previous frame reprojection fails for camera translation
DirectX_Programmer
# Previous frame reprojection fails for camera translation

(Asked by: username_0 on 2022-09-20)

I'm trying to perform forward pixel projection based on previous frame depth. Using UV, I'm reading prevDepth for given pixel and based on that I'm recreating worldPos in camera space (where (0, 0, 0) is camera position). Then I offset this position using previous frame camera position to find prevWorldPos in camera space.

Then I'm doing standard matrix multiplication to get ndc and then prev frame uv. So, it works quite nice without any additional history buffer or using pixel neighbours, at least for camera rotation.

**When it comes to camera translation, value of prevUV is the same as uv and it results in no changes in affected pixels and it destroys the reprojection. And I don't understand why.**

```
float3 worldPosition = GetWorldPosFromUV(uv, prevDepth); // Current frame worldPos in camera space
float3 prevWorldPosition = worldPosition + (currFrameCameraOffset - prevFrameCameraOffset); // Transform to camera space position in previous frame

float4 ndcPrev = mul(float4(prevWorldPosition, 1.0f), viewProjMatrixPrevFrame); 
ndcPrev.xyz /= ndcPrev.w;
float2 prevUV = ndcPrev.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f);

return prevUV;

```

[![enter image description here](https://i.sstatic.net/I0NZc.png)](https://i.sstatic.net/I0NZc.png)

**Tags:** matrix, depth-map

> **Comments:**
> **username_1**: Why do you use the previous frame depth buffer with the current frame UV? That doesn't seem to make sense. Wouldn't you use the current frame depth buffer to get the current frame world position?  
> **username_0**: @username_1 Sorry, I didn't make it clear. I'm using kind of "special" buffer which is tracking depth of special objects not available in normal depth buffer. I'm working on optimization to calculate pixels only when something changes, because that objects are really expensive to render. So if I skip calculation for that pixels, I lack "special" depth buffer for current frame and I have to use previous frame depth.  

---

## 0 answers

