You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
914 B
Plaintext
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;
|
|
}
|