TexturedIcon.azsl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 InstanceSrg : SRG_PerDraw
  10. {
  11. float2 m_viewportSize;
  12. Texture2D m_texture;
  13. Sampler m_sampler
  14. {
  15. MaxAnisotropy = 16;
  16. AddressU = Clamp;
  17. AddressV = Clamp;
  18. AddressW = Clamp;
  19. };
  20. };
  21. struct VSInput
  22. {
  23. float3 m_position : POSITION;
  24. float4 m_color : COLOR0;
  25. float2 m_uv : TEXCOORD0;
  26. };
  27. struct VSOutput
  28. {
  29. float4 m_position : SV_Position;
  30. float4 m_color : COLOR0;
  31. float2 m_uv : TEXCOORD0;
  32. };
  33. VSOutput MainVS(VSInput IN)
  34. {
  35. // Convert from screen space to clip space
  36. float2 posXY = float2(IN.m_position.xy) / InstanceSrg::m_viewportSize * 2.0f - float2(1.0f, 1.0f);
  37. posXY.y *= -1.0f;
  38. float4 posPS = float4(posXY, IN.m_position.z, 1.0f);
  39. VSOutput OUT;
  40. OUT.m_position = posPS;
  41. OUT.m_color = IN.m_color;
  42. OUT.m_uv = IN.m_uv;
  43. return OUT;
  44. };
  45. struct PSOutput
  46. {
  47. float4 m_color : SV_Target0;
  48. };
  49. PSOutput MainPS(VSOutput IN)
  50. {
  51. PSOutput OUT;
  52. float4 tex;
  53. tex = InstanceSrg::m_texture.Sample(InstanceSrg::m_sampler, IN.m_uv);
  54. float opacity = IN.m_color.a * tex.a;
  55. // We use pre-multiplied alpha here since it is more flexible. For example, it enables alpha-blended rendering to
  56. // a render target and then alpha blending that render target into another render target
  57. OUT.m_color.rgb = IN.m_color.rgb * tex.rgb * opacity;
  58. OUT.m_color.a = opacity;
  59. return OUT;
  60. };