Inverse Projection Matrix - Custom HLSL Node

Mad.King
Sat, 09 Aug 2025 15:22:59 +0000
Rendering

Is this the correct way to construct an inverse projection matrix? Projections and matrices are an elusive concept to me. I’ve basically just been trying to piece together the correct solution based on info I could find on the subject, so I’m not entirely sure it’s 100% correct.

/////
// inputs: CameraPos (from CameraPositionWS)
/////

float2 uv = GetDefaultSceneTextureUV(Parameters, 0);

float depth = SceneTextureLookup(uv, 1, false).r;

// normalized device coordinates
float4 ndcPos;
ndcPos.x = uv.x * 2.0 - 1.0;
ndcPos.y = (1.0 - uv.y) * 2.0 - 1.0;
ndcPos.z = depth;
ndcPos.w = 1.0;

// translated world space
float4 worldPosTranslated4 = mul(ndcPos, View.ScreenToTranslatedWorld);
float3 worldPosTranslated = worldPosTranslated4.xyz / worldPosTranslated4.w;

// absolute world position
float3 worldPosAbsolute = worldPosTranslated + CameraPos;

6 posts - 2 participants