MSAAResolve.azsl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/SrgSemantics.azsli>
  9. ShaderResourceGroup TextureInstanceSrg : SRG_PerObject
  10. {
  11. Texture2DMS<float4> m_albedoMap;
  12. }
  13. struct VSInput
  14. {
  15. float3 m_position : POSITION;
  16. float2 m_uv : UV0;
  17. };
  18. struct VSOutput
  19. {
  20. float4 m_position : SV_Position;
  21. float2 m_uv : UV0;
  22. };
  23. VSOutput MainVS(VSInput vsInput)
  24. {
  25. VSOutput OUT;
  26. OUT.m_position = float4(vsInput.m_position, 1.0);
  27. OUT.m_uv.x = vsInput.m_uv.x;
  28. OUT.m_uv.y = 1.0 - vsInput.m_uv.y;
  29. return OUT;
  30. }
  31. struct PSOutput
  32. {
  33. float4 m_color : SV_Target0;
  34. };
  35. PSOutput MainPS(VSOutput psInput)
  36. {
  37. PSOutput OUT;
  38. uint width = 0;
  39. uint height = 0;
  40. uint numberOfSamples = 0;
  41. TextureInstanceSrg::m_albedoMap.GetDimensions(width, height, numberOfSamples);
  42. float3 albedo = float3(0, 0, 0);
  43. // Just average the samples equally
  44. for (uint i = 0; i < numberOfSamples; ++i)
  45. {
  46. albedo += TextureInstanceSrg::m_albedoMap.Load(int2(width * psInput.m_uv.x, height * psInput.m_uv.y), i).rgb;
  47. }
  48. OUT.m_color = float4(albedo / numberOfSamples, 1.0);
  49. return OUT;
  50. }