RenderImage.azsl 1.7 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 <viewsrg.srgi>
  9. #include <Atom/Features/ColorManagement/TransformColor.azsli>
  10. ShaderResourceGroup RenderImageSrg : SRG_PerDraw
  11. {
  12. Texture2D m_texture;
  13. float2 m_position;
  14. float2 m_size;
  15. int m_colorSpace;
  16. Sampler m_sampler
  17. {
  18. MaxAnisotropy = 16;
  19. AddressU = Wrap;
  20. AddressV = Wrap;
  21. AddressW = Wrap;
  22. };
  23. }
  24. struct VSInput
  25. {
  26. uint m_vertexIndex :SV_VertexID;
  27. uint m_instanceIndex :SV_InstanceID;
  28. };
  29. struct VSOutput
  30. {
  31. float4 m_position : SV_Position;
  32. float2 m_uv : UV0;
  33. };
  34. struct PSOutput
  35. {
  36. float4 m_color : SV_Target0;
  37. float4 m_specular : SV_Target1;
  38. float4 m_scatterDistance : SV_Target2;
  39. };
  40. VSOutput MainVS(VSInput vsInput)
  41. {
  42. VSOutput OUT;
  43. float2 uvs[4] = { {0.0, 0.0}, {1.0, 0.0}, {0.0, -1.0}, {1.0, -1.0} };
  44. float2 vtx[4] = { {0.0, 0.0}, {2.0, 0.0}, {0.0, 2.0}, {2.0, 2.0} };
  45. int index = vsInput.m_vertexIndex%4;
  46. float2 startPosition = RenderImageSrg::m_position;
  47. OUT.m_position = float4(startPosition + vtx[index], 0, 1.0);
  48. OUT.m_uv.xy = uvs[index];
  49. return OUT;
  50. }
  51. PSOutput MainPS(VSOutput psInput)
  52. {
  53. PSOutput OUT;
  54. float3 color = float3(1.0, 1.0, 1.0);
  55. color = RenderImageSrg::m_texture.SampleLevel(RenderImageSrg::m_sampler, psInput.m_uv.xy, 0).rgb;
  56. color = TransformColor(color, (ColorSpaceId)RenderImageSrg::m_colorSpace, ColorSpaceId::ACEScg);
  57. OUT.m_color = float4(color, 1.0);
  58. OUT.m_specular = float4(0,0,0,1);
  59. OUT.m_scatterDistance = float4(0,0,0,0);
  60. return OUT;
  61. }