EditorModeBlur.azsl 1.7 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 <EditorModeCommon.azsli>
  9. //! Applies a box blur of the specified kernel width in the specified direction.
  10. float3 Blur(const float2 uv, const float2 uvDir, const float kernelHalfWidth)
  11. {
  12. const float2 unormalizedUv = float2(uv.x * PassSrg::m_maskDimensions.x, uv.y * PassSrg::m_maskDimensions.y);
  13. float3 outColor = float3(0., 0., 0.);
  14. for(float i = -kernelHalfWidth; i <= kernelHalfWidth; i+=1.)
  15. {
  16. outColor += PassSrg::m_framebuffer.Sample(PassSrg::PointSampler, (unormalizedUv + (float2(i,i) * uvDir)) * PassSrg::m_maskDimensions.zw).rgb;
  17. }
  18. return outColor / (kernelHalfWidth * 2.0 + 1.0);
  19. }
  20. PSOutput MainPS(VSOutput IN)
  21. {
  22. PSOutput OUT;
  23. const float3 inColor = PassSrg::m_framebuffer.Sample(PassSrg::LinearSampler, IN.m_texCoord).rgb;
  24. const float mask = PassSrg::m_entityMask.Sample(PassSrg::PointSampler, IN.m_texCoord).r;
  25. // Blur effect
  26. float2 blurDirection = (PassSrg::m_direction == 0) ? float2(1.0, 0.0) : float2(0.0, 1.0);
  27. float3 finalEffect = Blur(IN.m_texCoord, blurDirection, PassSrg::m_kernelHalfWidth);
  28. // Apply the depth transition to the blend amount
  29. const float zDepth = PassSrg::m_depth.Sample(PassSrg::PointSampler, IN.m_texCoord).r;
  30. const float t = PassSrg::CalculateTransitionBlendAmountFromDepth(zDepth, mask);
  31. // Apply the visual effect to non-mask entities, leaving mask entities untouched
  32. OUT.m_color = PassSrg::CalculateFinalBlendAmountAndOutputColor(inColor, finalEffect, t);
  33. return OUT;
  34. }