StacksShaderInputFunctor.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include <MaterialFunctors/StacksShaderInputFunctor.h>
  13. #include <Atom/RPI.Public/Material/Material.h>
  14. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  15. #include <AzCore/Math/Matrix4x4.h>
  16. namespace AtomSampleViewer
  17. {
  18. void StacksShaderInputFunctor::Reflect(AZ::ReflectContext* context)
  19. {
  20. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  21. {
  22. serializeContext->Class<StacksShaderInputFunctor, AZ::RPI::MaterialFunctor>()
  23. ->Version(1)
  24. ->Field("m_azimuthDegreesIndex", &StacksShaderInputFunctor::m_azimuthDegreesIndex)
  25. ->Field("m_elevationDegreesIndex", &StacksShaderInputFunctor::m_elevationDegreesIndex)
  26. ->Field("m_lightDirectionIndex", &StacksShaderInputFunctor::m_lightDirectionIndex)
  27. ;
  28. }
  29. }
  30. void StacksShaderInputFunctor::Process(RuntimeContext& context)
  31. {
  32. float azimuthDegrees = context.GetMaterialPropertyValue<float>(m_azimuthDegreesIndex);
  33. float elevationDegrees = context.GetMaterialPropertyValue<float>(m_elevationDegreesIndex);
  34. AZ::Vector3 lightDir = AZ::Vector3(1,0,0) * AZ::Matrix4x4::CreateRotationZ(AZ::DegToRad(elevationDegrees)) * AZ::Matrix4x4::CreateRotationY(AZ::DegToRad(azimuthDegrees));
  35. float floats[3];
  36. lightDir.StoreToFloat3(floats);
  37. context.GetShaderResourceGroup()->SetConstantRaw(m_lightDirectionIndex, floats, 3 * sizeof(float));
  38. }
  39. } // namespace AtomSampleViewer