SubsurfaceScatteringPass.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 <PostProcessing/SubsurfaceScatteringPass.h>
  9. #include <Atom/RHI/CommandList.h>
  10. #include <Atom/RHI/Factory.h>
  11. #include <Atom/RHI/FrameScheduler.h>
  12. #include <Atom/RPI.Reflect/Pass/PassTemplate.h>
  13. #include <Atom/RPI.Public/Pass/PassUtils.h>
  14. #include <Atom/RPI.Public/Pass/PassAttachment.h>
  15. #include <Atom/RPI.Public/RPIUtils.h>
  16. #include <Atom/RPI.Public/RenderPipeline.h>
  17. #include <Atom/RPI.Public/View.h>
  18. #include <Atom/RPI.Public/RPISystemInterface.h>
  19. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  20. namespace AZ
  21. {
  22. namespace RPI
  23. {
  24. Ptr<SubsurfaceScatteringPass> SubsurfaceScatteringPass::Create(const PassDescriptor& descriptor)
  25. {
  26. Ptr<SubsurfaceScatteringPass> pass = aznew SubsurfaceScatteringPass(descriptor);
  27. return pass;
  28. }
  29. SubsurfaceScatteringPass::SubsurfaceScatteringPass(const PassDescriptor& descriptor)
  30. : ComputePass(descriptor)
  31. { }
  32. void SubsurfaceScatteringPass::FrameBeginInternal(FramePrepareParams params)
  33. {
  34. RHI::Size targetImageSize;
  35. if (m_isFullscreenPass)
  36. {
  37. PassAttachment* outputAttachment = nullptr;
  38. if (GetOutputCount() > 0)
  39. {
  40. outputAttachment = GetOutputBinding(0).GetAttachment().get();
  41. }
  42. else if (GetInputOutputCount() > 0)
  43. {
  44. outputAttachment = GetInputOutputBinding(0).GetAttachment().get();
  45. }
  46. AZ_Assert(outputAttachment != nullptr, "[ComputePass '%s']: A fullscreen compute pass must have a valid output or input/output.",
  47. GetPathName().GetCStr());
  48. AZ_Assert(outputAttachment->GetAttachmentType() == RHI::AttachmentType::Image,
  49. "[ComputePass '%s']: The output of a fullscreen compute pass must be an image.",
  50. GetPathName().GetCStr());
  51. targetImageSize = outputAttachment->m_descriptor.m_image.m_size;
  52. SetTargetThreadCounts(targetImageSize.m_width, targetImageSize.m_height, targetImageSize.m_depth);
  53. }
  54. // Update shader constant
  55. m_shaderResourceGroup->SetConstant(m_screenSizeInputIndex, AZ::Vector2(static_cast<float>(targetImageSize.m_width), static_cast<float>(targetImageSize.m_height)));
  56. RenderPass::FrameBeginInternal(params);
  57. }
  58. } // namespace RPI
  59. } // namespace AZ