Files
Steve Pham 38261d0800 Shorten copyright headers by splitting into 2 lines (#2213)
* Updated all copyright headers to split the longer original copyright line into 2 shorter lines

Signed-off-by: Steve Pham <spham@amazon.com>
2021-07-16 15:25:48 -07:00

28 lines
914 B
Plaintext

/*
* 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 <Atom/RPI/Math.azsli>
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;
}