TextureArray.azsl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 TextureArraySrg : SRG_PerScene
  10. {
  11. Texture2D m_textureArray[8];
  12. Sampler m_sampler
  13. {
  14. MaxAnisotropy = 16;
  15. AddressU = Wrap;
  16. AddressV = Wrap;
  17. AddressW = Wrap;
  18. };
  19. }
  20. ShaderResourceGroup TextureIndexSrg : SRG_PerObject
  21. {
  22. uint m_textureArrayIndex;
  23. }
  24. struct VSInput
  25. {
  26. float3 m_position : POSITION;
  27. float2 m_uv : UV0;
  28. };
  29. struct VSOutput
  30. {
  31. float4 m_position : SV_Position;
  32. float2 m_uv : UV0;
  33. };
  34. VSOutput MainVS(VSInput vsInput)
  35. {
  36. VSOutput OUT;
  37. OUT.m_position = float4(vsInput.m_position, 1.0);
  38. OUT.m_uv = vsInput.m_uv;
  39. return OUT;
  40. }
  41. struct PSOutput
  42. {
  43. float4 m_color : SV_Target0;
  44. };
  45. PSOutput MainPS(VSOutput psInput)
  46. {
  47. PSOutput OUT;
  48. Texture2D texture = TextureArraySrg::m_textureArray[TextureIndexSrg::m_textureArrayIndex];
  49. OUT.m_color = texture.Sample(TextureArraySrg::m_sampler, psInput.m_uv);
  50. return OUT;
  51. }