32 lines
1.2 KiB
Plaintext
32 lines
1.2 KiB
Plaintext
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
|
|
#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;
|
|
}
|