From 2a4489262bc434241a4742dcc8e2b1465684cfb0 Mon Sep 17 00:00:00 2001 From: wookywok <62037083+wookywok@users.noreply.github.com> Date: Sat, 27 Apr 2024 21:45:33 -0500 Subject: [PATCH] Pixelize VFX! (#895) Finally, the dark days of zooming the camera and viewport are over... --- .../PostProcessingVFX/GameCameraProfile.asset | 38 +++++++++++++++++-- .../Prefabs/GameView/GameTex.renderTexture | 4 +- .../Prefabs/GameView/OverlayTex.renderTexture | 4 +- Assets/Scenes/Editor.unity | 12 +++--- Assets/Scripts/Minigames.cs | 20 ++++++++++ Assets/Scripts/PostProcessingVFX.cs | 38 +++++++++++++++++++ .../Effects/PixelizeQuad/PixelizeQuad.cs | 2 +- 7 files changed, 104 insertions(+), 14 deletions(-) diff --git a/Assets/PostProcessingVFX/GameCameraProfile.asset b/Assets/PostProcessingVFX/GameCameraProfile.asset index cdadab56..366ccfd6 100644 --- a/Assets/PostProcessingVFX/GameCameraProfile.asset +++ b/Assets/PostProcessingVFX/GameCameraProfile.asset @@ -1412,7 +1412,7 @@ MonoBehaviour: overrideState: 0 value: 0 intervalType: - overrideState: 0 + overrideState: 1 value: 0 frequency: overrideState: 0 @@ -1446,6 +1446,37 @@ MonoBehaviour: fastMode: overrideState: 0 value: 0 +--- !u!114 &-2221949593409771698 +MonoBehaviour: + m_ObjectHideFlags: 3 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bcc23458a58ff384c82bd27e09aa0cc6, type: 3} + m_Name: PixelizeQuad + m_EditorClassIdentifier: + active: 1 + enabled: + overrideState: 1 + value: 1 + pixelSize: + overrideState: 1 + value: 0.184 + useAutoScreenRatio: + overrideState: 1 + value: 0 + pixelRatio: + overrideState: 1 + value: 1 + pixelScaleX: + overrideState: 1 + value: 1 + pixelScaleY: + overrideState: 1 + value: 1 --- !u!114 &-1752554079016775041 MonoBehaviour: m_ObjectHideFlags: 3 @@ -1469,7 +1500,7 @@ MonoBehaviour: overrideState: 1 value: {r: 0, g: 0, b: 0, a: 1} center: - overrideState: 0 + overrideState: 1 value: {x: 0.5, y: 0.5} intensity: overrideState: 1 @@ -1540,6 +1571,7 @@ MonoBehaviour: - {fileID: -44530092333175149} - {fileID: -6672723021951195849} - {fileID: 6617679330616591269} + - {fileID: -2221949593409771698} --- !u!114 &190338221448500764 MonoBehaviour: m_ObjectHideFlags: 3 @@ -1589,7 +1621,7 @@ MonoBehaviour: value: 1 intensity: overrideState: 1 - value: 0 + value: 0.5 size: overrideState: 1 value: 1 diff --git a/Assets/Resources/Prefabs/GameView/GameTex.renderTexture b/Assets/Resources/Prefabs/GameView/GameTex.renderTexture index 5ea586ce..62cbb7cd 100644 --- a/Assets/Resources/Prefabs/GameView/GameTex.renderTexture +++ b/Assets/Resources/Prefabs/GameView/GameTex.renderTexture @@ -14,8 +14,8 @@ RenderTexture: m_DownscaleFallback: 0 m_IsAlphaChannelOptional: 0 serializedVersion: 5 - m_Width: 1249 - m_Height: 703 + m_Width: 1920 + m_Height: 1080 m_AntiAliasing: 2 m_MipCount: -1 m_DepthStencilFormat: 92 diff --git a/Assets/Resources/Prefabs/GameView/OverlayTex.renderTexture b/Assets/Resources/Prefabs/GameView/OverlayTex.renderTexture index 90af6dee..8d5f1407 100644 --- a/Assets/Resources/Prefabs/GameView/OverlayTex.renderTexture +++ b/Assets/Resources/Prefabs/GameView/OverlayTex.renderTexture @@ -14,8 +14,8 @@ RenderTexture: m_DownscaleFallback: 0 m_IsAlphaChannelOptional: 0 serializedVersion: 5 - m_Width: 1873 - m_Height: 1054 + m_Width: 2880 + m_Height: 1620 m_AntiAliasing: 1 m_MipCount: -1 m_DepthStencilFormat: 92 diff --git a/Assets/Scenes/Editor.unity b/Assets/Scenes/Editor.unity index 41066792..d90543fa 100644 --- a/Assets/Scenes/Editor.unity +++ b/Assets/Scenes/Editor.unity @@ -13155,7 +13155,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 171581557} m_HandleRect: {fileID: 171581556} m_Direction: 2 - m_Value: 1 + m_Value: 0 m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: @@ -25414,8 +25414,8 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1589389272} m_HandleRect: {fileID: 1589389271} m_Direction: 2 - m_Value: 1 - m_Size: 0.99995804 + m_Value: 0 + m_Size: 0.99392056 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -31580,7 +31580,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0.5} m_AnchorMax: {x: 1, y: 0.5} - m_AnchoredPosition: {x: 0, y: 122.12238} + m_AnchoredPosition: {x: 0, y: 199.0612} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 1} --- !u!222 &1154875945 @@ -41326,8 +41326,8 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1220118245} m_HandleRect: {fileID: 1220118244} m_Direction: 2 - m_Value: 1.0000005 - m_Size: 0.61358607 + m_Value: 1 + m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 733841b6..abf0d8c9 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -1188,6 +1188,26 @@ namespace HeavenStudio } }, + new GameAction("pixelQuad", "Pixelize") + { + resizable = true, + parameters = new() + { + new("pixelSizeStart", new EntityTypes.Float(0.00f, 1f, 0.00f), "Start Pixel Size", "Set the pixel size at the start of the event."), + new("pixelSizeEnd", new EntityTypes.Float(0.00f, 1f, 0.5f), "End Pixel Size", "Set the pixel size at the end of the event."), + new("ratioStart", new EntityTypes.Float(0.2f, 5f, 1f), "Start Pixel Ratio", "Set the pixel ratio at the start of the event."), + new("ratioEnd", new EntityTypes.Float(0.2f, 5f, 1f), "End Pixel Ratio", "Set the pixel ratio at the end of the event."), + new("xScaleStart", new EntityTypes.Float(0.2f, 5f, 1f), "Start X Scale", "Set the X scale of the pixels at the start of the event."), + new("xScaleEnd", new EntityTypes.Float(0.2f, 5f, 1f), "End X Scale", "Set the X scale of the pixels at the end of the event."), + new("yScaleStart", new EntityTypes.Float(0.2f, 5f, 1f), "Start Y Scale", "Set the Y scale of the pixels at the start of the event."), + new("yScaleEnd", new EntityTypes.Float(0.2f, 5f, 1f), "End Y Scale", "Set the Y scale of the pixels at the end of the event."), + new("ease", Util.EasingFunction.Ease.Linear, "Ease", "Set the easing of the action.", new() + { + new((x, y) => (Util.EasingFunction.Ease)x != Util.EasingFunction.Ease.Instant, new string[] { "pixelSizeStart", "ratioStart", "xScaleStart", "yScaleStart" }) + }), + } + }, + new GameAction("retroTv", "Retro TV") { resizable = true, diff --git a/Assets/Scripts/PostProcessingVFX.cs b/Assets/Scripts/PostProcessingVFX.cs index 5d5800b6..98ba1342 100644 --- a/Assets/Scripts/PostProcessingVFX.cs +++ b/Assets/Scripts/PostProcessingVFX.cs @@ -24,12 +24,15 @@ namespace HeavenStudio private List _analogNoises = new(); private List _screenJumps = new(); private List _sobelNeons = new(); + private List _pixelizeQuads = new(); + private void Awake() { _volume = GetComponent(); UpdateRetroTV(); UpdateAnalogNoise(); UpdateSobelNeons(); + UpdatePixelizes(); } @@ -52,6 +55,7 @@ namespace HeavenStudio _analogNoises = EventCaller.GetAllInGameManagerList("vfx", new string[] {"analogNoise"}); _screenJumps = EventCaller.GetAllInGameManagerList("vfx", new string[] {"screenJump"}); _sobelNeons = EventCaller.GetAllInGameManagerList("vfx", new string[] {"sobelNeon"}); + _pixelizeQuads = EventCaller.GetAllInGameManagerList("vfx", new string [] {"pixelQuad"}); UpdateVignette(); UpdateChromaticAbberations(); @@ -65,6 +69,7 @@ namespace HeavenStudio UpdateAnalogNoise(); UpdateScreenJumps(); UpdateSobelNeons(); + UpdatePixelizes(); } @@ -82,6 +87,7 @@ namespace HeavenStudio UpdateAnalogNoise(); UpdateScreenJumps(); UpdateSobelNeons(); + UpdatePixelizes(); } @@ -399,6 +405,38 @@ namespace HeavenStudio } + private void UpdatePixelizes() + { + if (!_volume.profile.TryGetSettings(out var pq)) return; + pq.enabled.Override(false); + foreach (var e in _pixelizeQuads) + { + float normalized = Conductor.instance.GetPositionFromBeat(e.beat, e.length); + if (normalized < 0) break; + + float clampNormal = Mathf.Clamp01(normalized); + var func = Util.EasingFunction.GetEasingFunction((Util.EasingFunction.Ease)e["ease"]); + + float newPixelSize = func(e["pixelSizeStart"], e["pixelSizeEnd"], clampNormal); + pq.enabled.Override(newPixelSize != 0); + if (!pq.enabled) continue; + pq.pixelSize.Override(newPixelSize); + + float newPixelRatio = func(e["ratioStart"], e["ratioEnd"], clampNormal); + if (!pq.enabled) continue; + pq.pixelRatio.Override(newPixelRatio); + + float newPixelXScale = func(e["xScaleStart"], e["xScaleEnd"], clampNormal); + if (!pq.enabled) continue; + pq.pixelScaleX.Override(newPixelXScale); + + float newPixelYScale = func(e["yScaleStart"], e["yScaleEnd"], clampNormal); + if (!pq.enabled) continue; + pq.pixelScaleY.Override(newPixelYScale); + + } + } + private Color ColorEase(Color start, Color end, float time, Util.EasingFunction.Function func) { float newR = func(start.r, end.r, time); diff --git a/Assets/X-PostProcessing/Effects/PixelizeQuad/PixelizeQuad.cs b/Assets/X-PostProcessing/Effects/PixelizeQuad/PixelizeQuad.cs index b0da22d6..621c032b 100644 --- a/Assets/X-PostProcessing/Effects/PixelizeQuad/PixelizeQuad.cs +++ b/Assets/X-PostProcessing/Effects/PixelizeQuad/PixelizeQuad.cs @@ -21,7 +21,7 @@ namespace XPostProcessing public class PixelizeQuad : PostProcessEffectSettings { - [Range(0.01f, 1.0f)] + [Range(0.00f, 1.0f)] public FloatParameter pixelSize = new FloatParameter { value = 0.5f }; public BoolParameter useAutoScreenRatio = new BoolParameter { value = true };