DepthToLinearDepth.azsl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Atom/Features/PBR/Lights/LightStructures.azsli>
  9. #include <Atom/Features/Decals/DecalStructures.azsli>
  10. #include <viewsrg_all.srgi>
  11. #include <Atom/Features/PostProcessing/FullscreenVertex.azsli>
  12. ShaderResourceGroup PassSrg : SRG_PerPass
  13. {
  14. // D32_FLOAT_S8X24_UINT (Format:15) depthStencil texture
  15. Texture2D<float2> m_depthStencil;
  16. Sampler PointSampler
  17. {
  18. MinFilter = Point;
  19. MagFilter = Point;
  20. MipFilter = Point;
  21. AddressU = Clamp;
  22. AddressV = Clamp;
  23. AddressW = Clamp;
  24. };
  25. }
  26. struct PSOutput
  27. {
  28. float m_linearDepth : SV_Target0;
  29. };
  30. PSOutput MainPS(VSOutput IN)
  31. {
  32. PSOutput OUT;
  33. float zDepth = PassSrg::m_depthStencil.Sample(PassSrg::PointSampler, IN.m_texCoord).r;
  34. float linearDepth =
  35. abs(((ViewSrg::GetFarZTimesNearZ()) / (ViewSrg::GetFarZMinusNearZ() * zDepth - ViewSrg::GetFarZ())));
  36. OUT.m_linearDepth = linearDepth;
  37. return OUT;
  38. }