From 6f1d247bc8813b6ff3db774c5bc1f7853c91736d Mon Sep 17 00:00:00 2001 From: PS Date: Fri, 9 Apr 2021 15:59:32 -1000 Subject: [PATCH] Made Hues capable of smoothly lerping to white or black --- src/app/ss_blumen_lumen/blumen_lumen.cpp | 25 +++++++---- .../ss_blumen_lumen/blumen_lumen_settings.h | 2 +- src/app/ss_blumen_lumen/phrase_hue_map.h | 45 +++++++------------ 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/src/app/ss_blumen_lumen/blumen_lumen.cpp b/src/app/ss_blumen_lumen/blumen_lumen.cpp index 1a91994..cee7f4e 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen.cpp +++ b/src/app/ss_blumen_lumen/blumen_lumen.cpp @@ -413,14 +413,15 @@ BlumenLumen_CustomInit(app_state* State, context Context) #endif 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.Speed = 1; BLState->StandardPatternHues.AddIn = AddIn_Rotary; 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); return Result; } @@ -581,9 +582,15 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) r32 ColorRelOscSpeed = 1 * ColorSpeed;; r32 ColorOscillation = (SinR32(BaseTime * ColorOscSpeed) + 1) / 2; 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); - BLState->StandardPatternHues.Hue2.Hue = LerpR32(.3f, BLState->StandardPatternHues.Hue0.Hue, BLState->StandardPatternHues.Hue1.Hue); + + r32 H0 = ModR32(ColorOscillation * 360, 360); + 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 if (BLState->PatternMode == BlumenPattern_VoiceCommand) @@ -963,9 +970,9 @@ US_CUSTOM_DEBUG_UI(BlumenLumen_DebugUI) if (BLState->DebugOverrideHue) { phrase_hue PHue = BLState->DebugHue; - PHue.Hue0.Hue = (r64)ui_LabeledRangeSlider(I, MakeString("Hue0"), (r32)PHue.Hue0.Hue, 0, 360); - PHue.Hue1.Hue = (r64)ui_LabeledRangeSlider(I, MakeString("Hue1"), (r32)PHue.Hue1.Hue, 0, 360); - PHue.Hue2.Hue = (r64)ui_LabeledRangeSlider(I, MakeString("Hue2"), (r32)PHue.Hue2.Hue, 0, 360); + PHue.Hue0.HSV.x = (r64)ui_LabeledRangeSlider(I, MakeString("Hue0"), (r32)PHue.Hue0.HSV.x, 0, 360); + PHue.Hue1.HSV.x = (r64)ui_LabeledRangeSlider(I, MakeString("Hue1"), (r32)PHue.Hue1.HSV.x, 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.Speed = ui_LabeledRangeSlider(I, MakeString("Speed"), PHue.Speed, 0, 4); diff --git a/src/app/ss_blumen_lumen/blumen_lumen_settings.h b/src/app/ss_blumen_lumen/blumen_lumen_settings.h index a55ce1b..6f8c46c 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen_settings.h +++ b/src/app/ss_blumen_lumen/blumen_lumen_settings.h @@ -121,7 +121,7 @@ r32 GlobalAnimSpeed = 1.0f; r32 GlobalAnimTransitionSpeed = 0.0f; // 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; diff --git a/src/app/ss_blumen_lumen/phrase_hue_map.h b/src/app/ss_blumen_lumen/phrase_hue_map.h index 3667210..39b36d2 100644 --- a/src/app/ss_blumen_lumen/phrase_hue_map.h +++ b/src/app/ss_blumen_lumen/phrase_hue_map.h @@ -29,8 +29,7 @@ enum p_hue_add_in typedef struct p_hue { - r64 Hue; - p_hue_flag Flags; + v4 HSV; } p_hue; typedef struct phrase_hue_map @@ -66,28 +65,25 @@ LerpPHue(r32 T, p_hue A, p_hue B) { 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 { - 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.Hue > 360) Result.Hue -= 360; - Result.Hue = Clamp(0, Result.Hue, 360); + if (Result.HSV.x < 360) Result.HSV.x += 360; + if (Result.HSV.x > 360) Result.HSV.x -= 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; } @@ -122,18 +118,18 @@ CreateHueFromString(gs_const_string Str) { p_hue Result = {}; if (Str.Str[0] == 'b') { - Result.Flags = Hue_Black; + Result.HSV = v4{0, 0, 1, 1 }; } else if (Str.Str[0] == 'w') { - Result.Flags = Hue_White; + Result.HSV = v4{0, 0, 0, 1 };; } else { - Result.Flags = Hue_Value; parse_float_result Parsed = ValidateAndParseFloat(Str); if (!Parsed.Success) { OutputDebugString("Failed to Parse CSV Float\n"); Parsed.Value = 0.0; } - Result.Hue = Parsed.Value; + Result.HSV = v4{ (r32)Parsed.Value, 1, 1, 1 }; + } return Result; } @@ -141,14 +137,7 @@ CreateHueFromString(gs_const_string Str) internal v4 RGBFromPhraseHue (p_hue H) { - v4 Result = {}; - 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; - } + v4 Result = H.HSV; Result = HSVToRGB(Result); return Result; }