Texture.azsl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. bool m_useStaticSampler;
  12. column_major float4x4 m_objectMatrix;
  13. column_major float3x3 m_uvMatrix;
  14. Texture2D m_albedoMap;
  15. Sampler m_sampler
  16. {
  17. MaxAnisotropy = 16;
  18. AddressU = Wrap;
  19. AddressV = Wrap;
  20. AddressW = Wrap;
  21. };
  22. Sampler m_dynamicSampler;
  23. float m_padding; // align on 8 byte, 124 -> 128
  24. }
  25. struct VSInput
  26. {
  27. float3 m_position : POSITION;
  28. float2 m_uv : UV0;
  29. };
  30. struct VSOutput
  31. {
  32. float4 m_position : SV_Position;
  33. float2 m_uv : UV0;
  34. };
  35. VSOutput MainVS(VSInput vsInput)
  36. {
  37. VSOutput OUT;
  38. OUT.m_position = mul(float4(vsInput.m_position, 1.0), TextureInstanceSrg::m_objectMatrix);
  39. OUT.m_uv = mul(float3(vsInput.m_uv, 1.0), TextureInstanceSrg::m_uvMatrix).xy;
  40. return OUT;
  41. }
  42. struct PSOutput
  43. {
  44. float4 m_color : SV_Target0;
  45. };
  46. PSOutput MainPS(VSOutput psInput)
  47. {
  48. PSOutput OUT;
  49. float3 albedo;
  50. if (TextureInstanceSrg::m_useStaticSampler)
  51. {
  52. albedo = TextureInstanceSrg::m_albedoMap.Sample(TextureInstanceSrg::m_sampler, psInput.m_uv).rgb;
  53. }
  54. else
  55. {
  56. albedo = TextureInstanceSrg::m_albedoMap.Sample(TextureInstanceSrg::m_dynamicSampler, psInput.m_uv).rgb;
  57. }
  58. OUT.m_color = float4(albedo, 1.0);
  59. return OUT;
  60. }