feat(ugc): live accurate color variation (-6 to 6 per channel, opaque bricks only)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-30 22:49:47 -05:00
parent 030efdaa0f
commit 73600acb4e
9 changed files with 50 additions and 4 deletions

View File

@@ -208,6 +208,16 @@ namespace UgcPalette {
return color * (newValue / value);
}
int32_t LiveVariationStep(float random) {
return std::clamp(static_cast<int32_t>(std::floor(random * 13.0f)), 0, 12) - 6;
}
glm::vec3 ApplyLiveVariation(const glm::vec3& linear, float random) {
const auto step = static_cast<float>(LiveVariationStep(random));
const auto srgb = glm::round(LinearToSrgb(linear) * 255.0f);
return SrgbToLinear(glm::clamp(srgb + step, 0.0f, 255.0f) / 255.0f);
}
float BrickRandom(uint64_t seed, uint32_t brick, uint32_t material) {
const auto bits = SplitMix(SplitMix(seed ^ (static_cast<uint64_t>(brick) << 32)) ^ material);
return static_cast<float>(bits >> 40) / static_cast<float>(1ull << 24);

View File

@@ -41,6 +41,12 @@ namespace UgcPalette {
*/
glm::vec3 ApplyVariation(const glm::vec3& color, float variationPercent, float random);
// The live accurate color variation of one color (linear): a whole number from -6 to 6 picked by `random` (0..1)
// added to each of its 0-255 sRGB channels, clamped to 0..255
glm::vec3 ApplyLiveVariation(const glm::vec3& linear, float random);
// That number: -6 to 6 inclusive, each equally likely
int32_t LiveVariationStep(float random);
/**
* The random number (0..1) of one brick's material: the same for the same seed, brick and material every time,
* so making a model again gives the same colors, and the same in every LOD (LU Toolbox restarts its random sequence