ColorMesh.azsl 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <scenesrg.srgi>
  10. ShaderResourceGroupSemantic SRG_PerGroup
  11. {
  12. FrequencyId = 0;
  13. };
  14. struct BaseMaterialInfo
  15. {
  16. float4 m_color;
  17. };
  18. ShaderResourceGroup MaterialGroupSrg : SRG_PerGroup
  19. {
  20. BaseMaterialInfo m_materials[10];
  21. }
  22. rootconstant float4x4 s_objectMatrix;
  23. rootconstant uint s_materialIndex;
  24. struct VSInput
  25. {
  26. float3 m_position : POSITION;
  27. float3 m_normal: NORMAL;
  28. };
  29. struct VSOutput
  30. {
  31. float4 m_position : SV_Position;
  32. float4 m_color: COLOR;
  33. };
  34. VSOutput MainVS(VSInput vsInput)
  35. {
  36. VSOutput OUT;
  37. OUT.m_position = mul(mul(ViewSrg::m_viewProjectionMatrix, s_objectMatrix), float4(vsInput.m_position, 1.0));
  38. float3 normal = mul(s_objectMatrix, float4(vsInput.m_normal, 0.0)).xyz;
  39. float intensity = saturate(dot(normalize(normal), normalize(float3(-1.0, -1.0, -1.0))));
  40. OUT.m_color = saturate(MaterialGroupSrg::m_materials[s_materialIndex].m_color * intensity);
  41. return OUT;
  42. }
  43. struct PSOutput
  44. {
  45. float4 m_diffuse : SV_Target0;
  46. float4 m_specular : SV_Target1;
  47. };
  48. PSOutput MainPS(VSOutput vsOutput)
  49. {
  50. PSOutput OUT;
  51. OUT.m_diffuse = vsOutput.m_color;
  52. OUT.m_specular = vsOutput.m_color;
  53. return OUT;
  54. }