From 4337cb33939e43af1ed479bf87cb9390bcbae8b1 Mon Sep 17 00:00:00 2001 From: yum Date: Thu, 10 Aug 2023 11:10:19 -0700 Subject: Add show/hide animation for ray-marched custom chatbox * Fix mirror behavior for ray-marched chatbox --- GUI/GUI/GUI/PythonWrapper.cpp | 8 +++----- Scripts/libtastt.py | 9 ++++----- Scripts/libunity.py | 6 ++++++ Shaders/ray_march.cginc | 33 +++++++++++++++++++++++++++++++-- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/GUI/GUI/GUI/PythonWrapper.cpp b/GUI/GUI/GUI/PythonWrapper.cpp index 2b6443a..1f6f3dc 100644 --- a/GUI/GUI/GUI/PythonWrapper.cpp +++ b/GUI/GUI/GUI/PythonWrapper.cpp @@ -549,8 +549,6 @@ bool PythonWrapper::GenerateAnimator( tastt_generated_dir_path / "FX0.controller"; std::filesystem::path tastt_fx1_path = tastt_generated_dir_path / "FX1.controller"; - std::filesystem::path tastt_fx2_path = - tastt_generated_dir_path / "FX2.controller"; // This is the final animator. std::filesystem::path tastt_animator_path = tastt_generated_dir_path / unity_animator_generated_name; @@ -772,8 +770,8 @@ bool PythonWrapper::GenerateAnimator( Log(out, "Merging with user animator... "); if (!InvokeWithArgs({ libunity_path, "merge", "--fx0", Quote(config.fx_path), - "--fx1", Quote(tastt_fx1_path), - "--fx_dest", Quote(tastt_fx2_path), }, + "--fx1", Quote(tastt_fx0_path), + "--fx_dest", Quote(tastt_fx1_path), }, "Failed to merge animators", out)) { return false; } @@ -781,7 +779,7 @@ bool PythonWrapper::GenerateAnimator( { Log(out, "Setting noop animations... "); if (!InvokeWithArgs({ libunity_path, "set_noop_anim", - "--fx0", Quote(tastt_fx2_path), + "--fx0", Quote(tastt_fx1_path), "--fx_dest", Quote(tastt_animator_path), "--gen_anim_dir", Quote(tastt_animations_path), "--guid_map", Quote(guid_map_path), }, diff --git a/Scripts/libtastt.py b/Scripts/libtastt.py index 1cec20c..1b5ed77 100644 --- a/Scripts/libtastt.py +++ b/Scripts/libtastt.py @@ -630,8 +630,7 @@ def generateToggle(layer_name: str, layer = anim.addLayer(layer_name) # For simplicity, use the layer name as the parameter name. - if parameter_name is not None: - anim.addParameter(parameter_name, bool) + anim.addParameter(parameter_name, bool) off_state = anim.addAnimatorState(layer, layer_name + "_Off", is_default_state = True) @@ -745,12 +744,12 @@ def generateFX(guid_map, gen_anim_dir): generate_utils.getIndicator1Param() + "_Off.anim", generate_utils.getIndicator1Param() + "_On.anim", anim, guid_map) - generateToggle(generate_utils.getToggleParam(), - None, + generateToggle("TaSTT_Expand", + generate_utils.getToggleParam(), gen_anim_dir, "TaSTT_Emerge_000.anim", "TaSTT_Emerge_100.anim", - anim, guid_map) + anim, guid_map, 0.5) generateScaleLayer(anim, gen_anim_dir, guid_map) return anim diff --git a/Scripts/libunity.py b/Scripts/libunity.py index bbf9498..3fd1011 100644 --- a/Scripts/libunity.py +++ b/Scripts/libunity.py @@ -581,8 +581,14 @@ class UnityAnimator(): unity_type = '3' elif param_type == bool: unity_type = '4' + anim = self.peekNodeOfClass('91') params = anim.mapping['AnimatorController'].mapping['m_AnimatorParameters'] + + for p in params.sequence: + if p.mapping['m_Name'] == param_name: + return + param = params.addChildMapping() param.mapping['m_Name'] = param_name param.mapping['m_Type'] = unity_type diff --git a/Shaders/ray_march.cginc b/Shaders/ray_march.cginc index 95d09ac..850a393 100644 --- a/Shaders/ray_march.cginc +++ b/Shaders/ray_march.cginc @@ -12,6 +12,19 @@ float Ray_March_Emerge; +// Allows us to divide [0,1] into `n_phases` equal-sized slices and remap `r` +// onto the `nth_phase`. +// +// A few examples: +// get_phase_fraction(0.9, 0, 2) = 1.0 +// get_phase_fraction(0.9, 1, 2) = 0.8 +// get_phase_fraction(0.5, 0, 3) = 1.0 +// get_phase_fraction(0.5, 1, 3) = 0.5 +// get_phase_fraction(0.5, 2, 3) = 0.0 +// +// So if `r` is past the slice we're looking at, it returns 1; if it's before +// the slice we're looking at, it returns 0; if it's on the slice we're looking +// at, it gets remapped onto [0,1]. float get_phase_fraction(float r, float nth_phase, float n_phases) { float stride = 1.0 / n_phases; @@ -37,6 +50,10 @@ float stt_map(float3 p, out float3 hsv, out float smoothness, out float alpha, o float p1r = get_phase_fraction(Ray_March_Emerge, 1, 3); float p2r = get_phase_fraction(Ray_March_Emerge, 2, 3); + // Use this to make the box grow out of the bottom left corner instead of the + // middle. + float3 emerge_offset = 0; + float dist = 1000 * 1000 * 1000; { float3 pp = p; @@ -47,6 +64,11 @@ float stt_map(float3 p, out float3 hsv, out float smoothness, out float alpha, o float box_thck = .0002; float3 box_sz = float3(6, .5, 3) * .003; + + emerge_offset.x = lerp(box_sz.x, box_thck, p1r); + emerge_offset.z = lerp(box_sz.z, box_thck, p2r); + pp += emerge_offset; + box_sz.y = lerp(box_thck, box_sz.y, p0r) * p0r; box_sz.x = lerp(box_thck, box_sz.x, p1r) * p0r; box_sz.z = lerp(box_thck, box_sz.z, p2r) * p0r; @@ -62,18 +84,23 @@ float stt_map(float3 p, out float3 hsv, out float smoothness, out float alpha, o pp.x -= 0.02; pp.z -= 0.01; - float3 box_scale = float3(.01, .0001, .005) * 1.6; + float3 box_scale = float3(.01, .0001, .0045) * 1.6; float p3r = get_phase_fraction(Ray_March_Emerge, 3, 4); box_scale.x *= ceil(p3r); box_scale.y *= ceil(p3r); box_scale.z = lerp(0, box_scale.z, p3r); + pp += emerge_offset; + float d = distance_from_box(pp, box_scale); text_uv = (clamp(pp.xz, -1 * box_scale.xz, box_scale.xz) / box_scale.xz); text_uv = (text_uv + 1) / 2; + bool in_mirror = !(unity_CameraProjection[2][0] == 0.0 && unity_CameraProjection[2][1] == 0.0); + text_uv = lerp(text_uv, float2(1.0 - text_uv.x, text_uv.y), in_mirror); + alpha = (d < dist) * 1 + (d >= dist) * alpha; hsv[1] = (d < dist) * 0 + (d >= dist) * hsv[1]; hsv[2] = (d < dist) * 0 + (d >= dist) * hsv[2]; @@ -149,7 +176,9 @@ float4 stt_ray_march(float3 ro, float3 rd, inout v2f v2f_i, inout float depth) color.w = alpha; depth = lerp(-1000, depth, distance_to_closest < MINIMUM_HIT_DISTANCE); - return lerp(0, light(v2f_i, color, metallic, smoothness), distance_to_closest < MINIMUM_HIT_DISTANCE); + fixed4 lit_color = light(v2f_i, color, metallic, smoothness); + fixed4 shaded_color = lerp(lit_color, color, 0.2); + return lerp(0, shaded_color, distance_to_closest < MINIMUM_HIT_DISTANCE); } float4 stt_ray_march(inout v2f v2f_i, inout float depth) -- cgit v1.2.3