Triangle.azsl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 TriangleInstanceSrg : SRG_PerDraw
  10. {
  11. column_major float4x4 m_objectMatrix;
  12. }
  13. struct VSInput
  14. {
  15. float3 m_position : POSITION;
  16. float4 m_color : COLOR0;
  17. };
  18. struct VSOutput
  19. {
  20. float4 m_position : SV_Position;
  21. float4 m_color : COLOR0;
  22. };
  23. // Red: normal draw mode (rgb = rgb). The Red corner appears on top
  24. // Green: shift the colors so Green is on top (the top vertex is (1, 0, 0) so the green color should come from .r
  25. // Blue: shift the colors so Blue is on top (the top vertex is (1, 0, 0) so the blue color should come from .r
  26. // White: ignore original colors and draw everything white
  27. option enum class DrawMode { Red, Green, Blue, White} o_drawMode;
  28. VSOutput MainVS(VSInput vsInput)
  29. {
  30. VSOutput OUT;
  31. OUT.m_position = mul(float4(vsInput.m_position, 1.0), TriangleInstanceSrg::m_objectMatrix);
  32. OUT.m_color = vsInput.m_color;
  33. return OUT;
  34. }
  35. struct PSOutput
  36. {
  37. float4 m_color : SV_Target0;
  38. };
  39. PSOutput MainPS(VSOutput vsOutput)
  40. {
  41. PSOutput OUT;
  42. switch (o_drawMode)
  43. {
  44. case DrawMode::Red:
  45. OUT.m_color = vsOutput.m_color.rgba;
  46. break;
  47. case DrawMode::Green:
  48. OUT.m_color = vsOutput.m_color.brga;
  49. break;
  50. case DrawMode::Blue:
  51. OUT.m_color = vsOutput.m_color.gbra;
  52. break;
  53. case DrawMode::White:
  54. OUT.m_color = float4(1, 1, 1, vsOutput.m_color.a);
  55. break;
  56. }
  57. // Simple tonemapping:
  58. OUT.m_color.rgb = pow(OUT.m_color.rgb, 1.0/2.2);
  59. return OUT;
  60. }