AsyncComputeLuminanceMap.azsl 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. float CalcLuminance(float3 color)
  10. {
  11. return dot(color, float3(0.299f, 0.587f, 0.114f));
  12. }
  13. ShaderResourceGroup TextureInstanceSrg : SRG_PerObject
  14. {
  15. Texture2D m_texture;
  16. Sampler m_sampler
  17. {
  18. MaxAnisotropy = 16;
  19. AddressU = Wrap;
  20. AddressV = Wrap;
  21. AddressW = Wrap;
  22. };
  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 IN)
  46. {
  47. PSOutput OUT;
  48. float3 color = TextureInstanceSrg::m_texture.Sample(TextureInstanceSrg::m_sampler, IN.m_uv).rgb;
  49. float luminance = log(max(CalcLuminance(color), 0.00001f));
  50. OUT.m_color = float4(luminance, 1.0f, 1.0f, 1.0f);
  51. return OUT;
  52. };