HairShortCutResolveDepth.azsl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Modifications 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. //
  9. // Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining a copy
  12. // of this software and associated documentation files (the "Software"), to deal
  13. // in the Software without restriction, including without limitation the rights
  14. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. // copies of the Software, and to permit persons to whom the Software is
  16. // furnished to do so, subject to the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be included in
  19. // all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. // THE SOFTWARE.
  28. //
  29. #include <Atom/Features/SrgSemantics.azsli>
  30. //!------------------------------ SRG Structure --------------------------------
  31. //! Per pass SRG that holds the dynamic shared read-write buffer shared
  32. //! across all dispatches and draw calls. It is used for all the dynamic buffers
  33. //! that can change between passes due to the application of skinning, simulation
  34. //! and physics affect.
  35. //! Once the compute pases are done, it is read by the rendering shaders.
  36. ShaderResourceGroup PassSrg : SRG_PerPass_WithFallback
  37. {
  38. // Originally: [[vk::binding(0, 0)]] Texture2DArray<uint> FragmentDepthsTexture : register(t0, space0);
  39. Texture2DArray<uint> m_fragmentDepthsTexture;
  40. }
  41. //------------------------------------------------------------------------------
  42. #include <HairFullScreenUtils.azsli> // provides the Vertex Shader
  43. //!=============================================================================
  44. //! Resolve Depth - Second Pass of ShortCut
  45. //! Full-screen pass that writes the farthest of the stored K near depths so it
  46. //! could be used for depth culling during the following geometry shading pass.
  47. //!=============================================================================
  48. float HairShortCutResolveDepthPS(VSOutput input) : SV_Depth
  49. {
  50. // Blend the layers of fragments from back to front
  51. int2 vScreenAddress = int2(input.m_position.xy);
  52. // Write farthest depth value for culling in the next pass.
  53. // It may be the initial value of 1.0 if there were not enough fragments to write all depths, but then culling not important.
  54. const int farthestDepthIndex = 2;
  55. uint uDepth = PassSrg::m_fragmentDepthsTexture[uint3(vScreenAddress, farthestDepthIndex)];
  56. // The following line is writing the depth into the actual depth buffer
  57. return asfloat(uDepth);
  58. }