/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include float4 ReconstructWorldPositionFromDepth(float2 screenCoords, uint sampleIndex) { float depth = PassSrg::m_depth.Load(screenCoords, sampleIndex).r; uint2 dimensions; uint samples; PassSrg::m_depth.GetDimensions(dimensions.x, dimensions.y, samples); float2 UV = saturate(screenCoords / dimensions.xy); float x = UV.x * 2.0f - 1.0f; float y = (1.0f - UV.y) * 2.0f - 1.0f; float4 projectedPos = float4(x, y, depth, 1.0f); float4 positionVS = mul(ViewSrg::m_projectionMatrixInverse, projectedPos); positionVS /= positionVS.w; float4 positionWS = mul(ViewSrg::m_viewMatrixInverse, positionVS); return positionWS; }