Files
DarkflameServer/dUgcServer/UgcPalette.h
Aaron Kimbrell 7c5d69c1ed feat(ugc): make models like LU Toolbox does, within CPU and memory budgets
Parity with LU Toolbox's Process Model, Bake Lighting and icon renderer, with
its defaults as the settings' defaults:

- Colors from its LU palette (UgcPalette: LU colors, LDD colors mapped to the
  nearest LU one, unknown ones black), transparent bricks at 58.82% opacity, a
  brick transparent only when all of its materials are.
- Color variation: each brick's material gets its HSV value shifted in a 2.224
  gamma by up to 5% (times the color's own amount), from a random number of
  the model, brick and material, so reprocessing gives the same colors in
  every LOD. Icons get none, and the icon renderer's color corrections.
- LODs 0 and 2 with its distance logic, written as NiLODNode/NiRangeLODData
  like its exports and the game's own brick models, shapes divided at 65535
  vertices along the longest side like divide_mesh.
- Ambient occlusion like its AO-only bake: 64 rays per vertex, distance 5,
  after hidden surface removal, transparent bricks neither baked nor
  occluding, glow colors added.
- Icons from its icon scene: 50 mm lens at 53.4/19.5 degrees, sun of 2.5 at
  21/50.3 degrees with soft shadows, grey world light with occlusion; LOD 0's
  hidden surface removal and occlusion are reused for them.
- Optional ground plane for hidden surface removal; stats.json per model and
  the previous version's previews kept for comparing.

Budgets, applied live on config reload: max_cpu_percent (workers account
their thread CPU time and sleep to stay under it, long renders included),
worker_nice, max_memory_mb (jobs are estimated from their brick count and
wait until they fit), max_model_bricks and pause_hours. /status and the
traffic report show CPU, memory and throttling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:31:06 -05:00

52 lines
2.2 KiB
C++

#pragma once
#include <cstdint>
#include <optional>
#include <glm/glm.hpp>
/**
* LU Toolbox's color palette (its materials/__init__.py), which it colors imported models with instead of the brick
* database's Materials.xml: LU's colors in linear RGB, the LDD colors LU doesn't have mapped onto the nearest LU one,
* which colors are transparent, glow and metallic, how much each color varies from brick to brick, and the icon
* renderer's corrections. Also the brick to brick color variation itself (process_model.py apply_color_variation).
* Pure.
*/
namespace UgcPalette {
// A material id's color in linear RGB; nullopt when LU Toolbox doesn't know it (it uses black, 26, then).
// `icon`: with the icon renderer's corrections (white and black are toned down).
std::optional<glm::vec3> Linear(uint32_t id, bool icon = false);
bool IsTransparent(uint32_t id);
bool IsMetallic(uint32_t id);
// The glow color (linear) of a glowing material, nullopt for the others
std::optional<glm::vec3> Glow(uint32_t id);
// How much of the color variation a color gets (CUSTOM_VARIATION: black varies less, orange more); 1 by default
float VariationScale(uint32_t id);
// The color LU Toolbox falls back to for unknown ids
constexpr uint32_t FALLBACK_ID = 26;
// sRGB <-> linear, exactly as LU Toolbox converts (color_conversions.py)
float SrgbToLinear(float srgb);
float LinearToSrgb(float linear);
glm::vec3 SrgbToLinear(const glm::vec3& srgb);
glm::vec3 LinearToSrgb(const glm::vec3& linear);
/**
* LU Toolbox's color variation of one color: its HSV value, taken to a 1/2.224 gamma, shifted by
* `random` (0..1, mapped to -variation/200 .. +variation/200, variation in percent), clamped to 0..1 and taken back.
* Hue and saturation stay. `color` is linear RGB.
*/
glm::vec3 ApplyVariation(const glm::vec3& color, float variationPercent, 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
* for each LOD). `brick` is the brick's index in the LXFML.
*/
float BrickRandom(uint64_t seed, uint32_t brick, uint32_t material);
}