Made Hues capable of smoothly lerping to white or black

This commit is contained in:
PS 2021-04-09 15:59:32 -10:00
parent cbd6433a30
commit 6f1d247bc8
3 changed files with 34 additions and 38 deletions

View File

@ -413,14 +413,15 @@ BlumenLumen_CustomInit(app_state* State, context Context)
#endif #endif
State->AnimationSystem.TimelineShouldAdvance = true; State->AnimationSystem.TimelineShouldAdvance = true;
BLState->StandardPatternHues.Hue0.Flags = Hue_Value;
BLState->StandardPatternHues.Hue1.Flags = Hue_Value;
BLState->StandardPatternHues.Hue2.Flags = Hue_Value;
BLState->StandardPatternHues.Granularity = 1; BLState->StandardPatternHues.Granularity = 1;
BLState->StandardPatternHues.Speed = 1; BLState->StandardPatternHues.Speed = 1;
BLState->StandardPatternHues.AddIn = AddIn_Rotary; BLState->StandardPatternHues.AddIn = AddIn_Rotary;
BLState->StandardPatternHues.Pattern = HuePattern_Wavy; BLState->StandardPatternHues.Pattern = HuePattern_Wavy;
BLState->DebugHue.Hue0.HSV = v4{0, 1, 1, 1};
BLState->DebugHue.Hue1.HSV = v4{0, 1, 1, 1};
BLState->DebugHue.Hue2.HSV = v4{0, 1, 1, 1};
BlumenLumen_AppendBootupLog(State, BLState, Context); BlumenLumen_AppendBootupLog(State, BLState, Context);
return Result; return Result;
} }
@ -581,9 +582,15 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
r32 ColorRelOscSpeed = 1 * ColorSpeed;; r32 ColorRelOscSpeed = 1 * ColorSpeed;;
r32 ColorOscillation = (SinR32(BaseTime * ColorOscSpeed) + 1) / 2; r32 ColorOscillation = (SinR32(BaseTime * ColorOscSpeed) + 1) / 2;
r32 ColorRelationship = 30 + (((1 + SinR32(BaseTime * ColorRelOscSpeed)) / 2) * 300); r32 ColorRelationship = 30 + (((1 + SinR32(BaseTime * ColorRelOscSpeed)) / 2) * 300);
BLState->StandardPatternHues.Hue0.Hue = ModR32(ColorOscillation * 360, 360);
BLState->StandardPatternHues.Hue1.Hue = ModR32(BaseTime + ColorRelationship, 360); r32 H0 = ModR32(ColorOscillation * 360, 360);
BLState->StandardPatternHues.Hue2.Hue = LerpR32(.3f, BLState->StandardPatternHues.Hue0.Hue, BLState->StandardPatternHues.Hue1.Hue); r32 H1 = ModR32(BaseTime + ColorRelationship, 360);
// TODO(PS): use our new HSV lerp
r32 H2 = LerpR32(.3f, H0, H1);
BLState->StandardPatternHues.Hue0.HSV = v4{ H0, 1, 1, 1 };
BLState->StandardPatternHues.Hue1.HSV = v4{ H1, 1, 1, 1 };
BLState->StandardPatternHues.Hue2.HSV = v4{ H2, 1, 1, 1 };
// Transition back to standard mode after some time // Transition back to standard mode after some time
if (BLState->PatternMode == BlumenPattern_VoiceCommand) if (BLState->PatternMode == BlumenPattern_VoiceCommand)
@ -963,9 +970,9 @@ US_CUSTOM_DEBUG_UI(BlumenLumen_DebugUI)
if (BLState->DebugOverrideHue) if (BLState->DebugOverrideHue)
{ {
phrase_hue PHue = BLState->DebugHue; phrase_hue PHue = BLState->DebugHue;
PHue.Hue0.Hue = (r64)ui_LabeledRangeSlider(I, MakeString("Hue0"), (r32)PHue.Hue0.Hue, 0, 360); PHue.Hue0.HSV.x = (r64)ui_LabeledRangeSlider(I, MakeString("Hue0"), (r32)PHue.Hue0.HSV.x, 0, 360);
PHue.Hue1.Hue = (r64)ui_LabeledRangeSlider(I, MakeString("Hue1"), (r32)PHue.Hue1.Hue, 0, 360); PHue.Hue1.HSV.x = (r64)ui_LabeledRangeSlider(I, MakeString("Hue1"), (r32)PHue.Hue1.HSV.x, 0, 360);
PHue.Hue2.Hue = (r64)ui_LabeledRangeSlider(I, MakeString("Hue2"), (r32)PHue.Hue2.Hue, 0, 360); PHue.Hue2.HSV.x = (r64)ui_LabeledRangeSlider(I, MakeString("Hue2"), (r32)PHue.Hue2.HSV.x, 0, 360);
PHue.Granularity = (u32)ui_LabeledRangeSlider(I, MakeString("Granularity"), (r32)PHue.Granularity, 0, 5); PHue.Granularity = (u32)ui_LabeledRangeSlider(I, MakeString("Granularity"), (r32)PHue.Granularity, 0, 5);
PHue.Speed = ui_LabeledRangeSlider(I, MakeString("Speed"), PHue.Speed, 0, 4); PHue.Speed = ui_LabeledRangeSlider(I, MakeString("Speed"), PHue.Speed, 0, 4);

View File

@ -121,7 +121,7 @@ r32 GlobalAnimSpeed = 1.0f;
r32 GlobalAnimTransitionSpeed = 0.0f; r32 GlobalAnimTransitionSpeed = 0.0f;
// how long it takes to fade from the old voice hue to the new one // how long it takes to fade from the old voice hue to the new one
r32 PhraseHueFadeInDuration = 2.0f; // seconds r32 PhraseHueFadeInDuration = 1.0f; // seconds
r64 PhrasePriorityMessageGroupingTime = 0.0f; r64 PhrasePriorityMessageGroupingTime = 0.0f;

View File

@ -29,8 +29,7 @@ enum p_hue_add_in
typedef struct p_hue typedef struct p_hue
{ {
r64 Hue; v4 HSV;
p_hue_flag Flags;
} p_hue; } p_hue;
typedef struct phrase_hue_map typedef struct phrase_hue_map
@ -66,28 +65,25 @@ LerpPHue(r32 T, p_hue A, p_hue B)
{ {
p_hue Result = {}; p_hue Result = {};
if (Abs(A.Hue - B.Hue) < 180.0f) if (Abs(A.HSV.x - B.HSV.x) < 180.0f)
{ {
Result.Hue = LerpR64(T, A.Hue, B.Hue); Result.HSV.x = LerpR64(T, A.HSV.x, B.HSV.x);
} }
else if (B.Hue > A.Hue) else if (B.HSV.x > A.HSV.x)
{ {
Result.Hue = LerpR64(T, A.Hue, B.Hue - 360.0f); Result.HSV.x = LerpR64(T, A.HSV.x, B.HSV.x - 360.0f);
} }
else else
{ {
Result.Hue = LerpR64(T, A.Hue - 360.0f, B.Hue); Result.HSV.x = LerpR64(T, A.HSV.x - 360.0f, B.HSV.x);
} }
if (Result.Hue < 360) Result.Hue += 360; if (Result.HSV.x < 360) Result.HSV.x += 360;
if (Result.Hue > 360) Result.Hue -= 360; if (Result.HSV.x > 360) Result.HSV.x -= 360;
Result.Hue = Clamp(0, Result.Hue, 360); Result.HSV.x = Clamp(0, Result.HSV.x, 360);
Result.HSV.y = LerpR32(T, A.HSV.y, B.HSV.y);
Result.HSV.z = LerpR32(T, A.HSV.z, B.HSV.z);
Result.HSV.w = LerpR32(T, A.HSV.w, B.HSV.w);
if (T < 0.5f)
{
Result.Flags = A.Flags;
} else {
Result.Flags = B.Flags;
}
return Result; return Result;
} }
@ -122,18 +118,18 @@ CreateHueFromString(gs_const_string Str)
{ {
p_hue Result = {}; p_hue Result = {};
if (Str.Str[0] == 'b') { if (Str.Str[0] == 'b') {
Result.Flags = Hue_Black; Result.HSV = v4{0, 0, 1, 1 };
} else if (Str.Str[0] == 'w') { } else if (Str.Str[0] == 'w') {
Result.Flags = Hue_White; Result.HSV = v4{0, 0, 0, 1 };;
} else { } else {
Result.Flags = Hue_Value;
parse_float_result Parsed = ValidateAndParseFloat(Str); parse_float_result Parsed = ValidateAndParseFloat(Str);
if (!Parsed.Success) if (!Parsed.Success)
{ {
OutputDebugString("Failed to Parse CSV Float\n"); OutputDebugString("Failed to Parse CSV Float\n");
Parsed.Value = 0.0; Parsed.Value = 0.0;
} }
Result.Hue = Parsed.Value; Result.HSV = v4{ (r32)Parsed.Value, 1, 1, 1 };
} }
return Result; return Result;
} }
@ -141,14 +137,7 @@ CreateHueFromString(gs_const_string Str)
internal v4 internal v4
RGBFromPhraseHue (p_hue H) RGBFromPhraseHue (p_hue H)
{ {
v4 Result = {}; v4 Result = H.HSV;
switch (H.Flags)
{
case Hue_Black: { Result = v4{1, 0, 0, 1}; } break;
case Hue_White: { Result = v4{1, 0, 1, 1}; } break;
case Hue_Value: { Result = v4{(r32)H.Hue, 1, 1, 1}; } break;
InvalidDefaultCase;
}
Result = HSVToRGB(Result); Result = HSVToRGB(Result);
return Result; return Result;
} }