Add WorldPosition to postfx material scene textures for world-space position sampling at uv

This commit is contained in:
Wojtek Figat
2022-11-21 23:45:13 +01:00
parent 99c296ff3a
commit c55d38534d
7 changed files with 38 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ float TimeParam;
float4 ViewInfo;
float4 ScreenSize;
float4 TemporalAAJitter;
float4x4 InverseViewProjectionMatrix;
@1META_CB_END
// Shader resources
@@ -62,6 +63,14 @@ MaterialInput GetMaterialInput(PixelInput input)
return result;
}
// Gets world space position at given pixel coordinate with given device depth
float3 GetWorldPos(float2 uv, float deviceDepth)
{
float4 clipPos = float4(uv * float2(2.0, -2.0) + float2(-1.0, 1.0), deviceDepth, 1.0);
float4 wsPos = mul(clipPos, InverseViewProjectionMatrix);
return wsPos.xyz / wsPos.w;
}
// Transforms a vector from tangent space to world space
float3 TransformTangentVectorToWorld(MaterialInput input, float3 tangentVector)
{