TrianglesConstantBuffer.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. struct InstanceInfo
  10. {
  11. column_major float4x4 m_matrix;
  12. float4 m_colorMultiplier;
  13. };
  14. struct InstanceData
  15. {
  16. InstanceInfo m_instancesInfo[30];
  17. };
  18. ShaderResourceGroup TriangleSrg : SRG_PerObject
  19. {
  20. ConstantBuffer<InstanceData> m_trianglesCB;
  21. }
  22. struct VSInput
  23. {
  24. float3 m_position : POSITION;
  25. float4 m_color : COLOR0;
  26. uint m_instanceIndex : SV_InstanceID;
  27. };
  28. struct VSOutput
  29. {
  30. float4 m_position : SV_Position;
  31. float4 m_color : COLOR0;
  32. };
  33. VSOutput MainVS(const VSInput vsInput)
  34. {
  35. VSOutput OUT;
  36. const InstanceInfo triangleInstanceInfo = TriangleSrg::m_trianglesCB.m_instancesInfo[vsInput.m_instanceIndex];
  37. OUT.m_position = mul(float4(vsInput.m_position, 1.0f),triangleInstanceInfo.m_matrix);
  38. OUT.m_color = vsInput.m_color * triangleInstanceInfo.m_colorMultiplier;
  39. return OUT;
  40. }
  41. struct PSOutput
  42. {
  43. float4 m_color : SV_Target0;
  44. };
  45. PSOutput MainPS(VSOutput vsOutput)
  46. {
  47. PSOutput OUT;
  48. OUT.m_color = vsOutput.m_color;
  49. return OUT;
  50. }