StacksShaderInputFunctor.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 <MaterialFunctors/StacksShaderInputFunctor.h>
  9. #include <Atom/RPI.Public/Material/Material.h>
  10. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  11. #include <AzCore/Math/Matrix4x4.h>
  12. namespace AtomSampleViewer
  13. {
  14. void StacksShaderInputFunctor::Reflect(AZ::ReflectContext* context)
  15. {
  16. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  17. {
  18. serializeContext->Class<StacksShaderInputFunctor, AZ::RPI::MaterialFunctor>()
  19. ->Version(1)
  20. ->Field("m_azimuthDegreesIndex", &StacksShaderInputFunctor::m_azimuthDegreesIndex)
  21. ->Field("m_elevationDegreesIndex", &StacksShaderInputFunctor::m_elevationDegreesIndex)
  22. ->Field("m_lightDirectionIndex", &StacksShaderInputFunctor::m_lightDirectionIndex)
  23. ;
  24. }
  25. }
  26. void StacksShaderInputFunctor::Process(RuntimeContext& context)
  27. {
  28. float azimuthDegrees = context.GetMaterialPropertyValue<float>(m_azimuthDegreesIndex);
  29. float elevationDegrees = context.GetMaterialPropertyValue<float>(m_elevationDegreesIndex);
  30. AZ::Vector3 lightDir = AZ::Vector3(1,0,0) * AZ::Matrix4x4::CreateRotationZ(AZ::DegToRad(elevationDegrees)) * AZ::Matrix4x4::CreateRotationY(AZ::DegToRad(azimuthDegrees));
  31. float floats[3];
  32. lightDir.StoreToFloat3(floats);
  33. context.GetShaderResourceGroup()->SetConstantRaw(m_lightDirectionIndex, floats, 3 * sizeof(float));
  34. }
  35. } // namespace AtomSampleViewer