palette.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "palette.h"
  2. #include "geom/math_utils.h"
  3. #include "humanoid_math.h"
  4. #include <cstdint>
  5. #include <qvectornd.h>
  6. namespace Render::GL {
  7. using Render::Geom::clampVec01;
  8. auto makeHumanoidPalette(const QVector3D &team_tint,
  9. uint32_t seed) -> HumanoidPalette {
  10. HumanoidPalette p;
  11. float const variation = (hash_01(seed) - 0.5F) * 0.08F;
  12. p.cloth = clampVec01(team_tint * (1.0F + variation));
  13. p.skin = QVector3D(0.96F, 0.80F, 0.69F);
  14. float const leather_var = (hash_01(seed ^ 0x1234U) - 0.5F) * 0.06F;
  15. float const r = team_tint.x();
  16. float const g = team_tint.y();
  17. float const b = team_tint.z();
  18. float const saturation = 0.6F;
  19. float const brightness = 0.5F;
  20. QVector3D const desaturated(r * saturation + (1.0F - saturation) * brightness,
  21. g * saturation + (1.0F - saturation) * brightness,
  22. b * saturation +
  23. (1.0F - saturation) * brightness);
  24. p.leather = clampVec01(desaturated * (0.7F + leather_var));
  25. p.leatherDark = p.leather * 0.85F;
  26. p.wood = QVector3D(0.16F, 0.10F, 0.05F);
  27. QVector3D const neutral_gray(0.70F, 0.70F, 0.70F);
  28. p.metal = clampVec01(team_tint * 0.25F + neutral_gray * 0.75F);
  29. return p;
  30. }
  31. } // namespace Render::GL