style_palette.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "style_palette.h"
  2. #include <algorithm>
  3. namespace Render::GL::Humanoid {
  4. namespace {
  5. inline auto clamp01(float value) -> float {
  6. return std::clamp(value, 0.0F, 1.0F);
  7. }
  8. } // namespace
  9. auto saturate_color(const QVector3D &value) -> QVector3D {
  10. return {clamp01(value.x()), clamp01(value.y()), clamp01(value.z())};
  11. }
  12. auto blend_with_team(const QVector3D &base, const QVector3D &team,
  13. float team_weight) -> QVector3D {
  14. float const base_weight = 1.0F - clamp01(team_weight);
  15. float const team_contrib = clamp01(team_weight);
  16. auto mix_component = [&](float base_c, float team_c) -> float {
  17. return clamp01(base_c * base_weight + team_c * team_contrib);
  18. };
  19. return {mix_component(base.x(), team.x()), mix_component(base.y(), team.y()),
  20. mix_component(base.z(), team.z())};
  21. }
  22. auto mix_palette_color(const QVector3D &base_color,
  23. const std::optional<QVector3D> &override_color,
  24. const QVector3D &team_tint, float team_weight,
  25. float style_weight) -> QVector3D {
  26. if (!override_color) {
  27. return base_color;
  28. }
  29. QVector3D styled =
  30. blend_with_team(*override_color, team_tint, clamp01(team_weight));
  31. styled = saturate_color(styled);
  32. float const t = clamp01(style_weight);
  33. QVector3D mixed = base_color * (1.0F - t) + styled * t;
  34. return saturate_color(mixed);
  35. }
  36. } // namespace Render::GL::Humanoid