MeshletsPerObjectRenderSrg.azsli 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #pragma once
  9. #include <scenesrg_all.srgi>
  10. /*
  11. // Utilize the following PerDraw srg for instancing - currently not used yet.
  12. ShaderResourceGroup MeshletsInstanceRenderSrg : SRG_PerDraw
  13. {
  14. //! used object Id for instancing and matrix retrieval
  15. uint m_objectId;
  16. //! Returns the matrix for transforming points from Object Space to World Space.
  17. float4x4 GetWorldMatrix()
  18. {
  19. return SceneSrg::GetObjectToWorldMatrix(m_objectId);
  20. }
  21. //! Returns the inverse-transpose of the world matrix.
  22. //! Commonly used to transform normals while supporting non-uniform scale.
  23. float3x3 GetWorldMatrixInverseTranspose()
  24. {
  25. return SceneSrg::GetObjectToWorldInverseTransposeMatrix(m_objectId);
  26. }
  27. }
  28. */
  29. ShaderResourceGroup MeshletsObjectRenderSrg : SRG_PerObject
  30. {
  31. //--------------------------------------------------
  32. // This part should be moved outside the PerObject srg and used in the PerDraw
  33. // srg that represents the instance frequency.
  34. // object Id is used as an index for instancing and matrix retrieval in the
  35. // SceneSrg matrices arrays.
  36. uint m_objectId;
  37. //! Returns the matrix for transforming points from Object Space to World Space.
  38. float4x4 GetWorldMatrix()
  39. {
  40. return SceneSrg::GetObjectToWorldMatrix(m_objectId);
  41. }
  42. //! Returns the inverse-transpose of the world matrix.
  43. //! Commonly used to transform normals while supporting non-uniform scale.
  44. float3x3 GetWorldMatrixInverseTranspose()
  45. {
  46. return SceneSrg::GetObjectToWorldInverseTransposeMatrix(m_objectId);
  47. }
  48. //---------------------------------------------------
  49. // Vertex streams - currently we use Buffer<float> instead of the exact required
  50. // data type (float3 for example) because of alignment problem in Atom buffer
  51. // creation from a common pool.
  52. // [To Do] - change when supported to prevent offset calculation overhead.
  53. // Buffer<float3> m_positions;
  54. // Buffer<float3> m_normals;
  55. // Buffer<float4> m_tangents;
  56. // Buffer<float3> m_bitangents;
  57. Buffer<float> m_positions;
  58. Buffer<float> m_normals;
  59. Buffer<float4> m_tangents;
  60. Buffer<float> m_bitangents;
  61. Buffer<float2> m_uvs;
  62. float3 GetPosition(uint vertexIndex)
  63. {
  64. uint index = vertexIndex * 3;
  65. return float3(m_positions[index], m_positions[index+1], m_positions[index+2]);
  66. }
  67. float3 GetNormal(uint vertexIndex)
  68. {
  69. uint index = vertexIndex * 3;
  70. return float3(m_normals[index], m_normals[index+1], m_normals[index+2]);
  71. }
  72. float3 GetBiTangent(uint vertexIndex)
  73. {
  74. uint index = vertexIndex * 3;
  75. return float3(m_bitangents[index], m_bitangents[index+1], m_bitangents[index+2]);
  76. }
  77. // The last element of the tangents indicates face direction / winding
  78. float4 GetTangent(uint vertexIndex)
  79. {
  80. return m_tangents[vertexIndex];
  81. }
  82. float2 GetUV(uint vertexIndex)
  83. {
  84. return m_uvs[vertexIndex];
  85. }
  86. }