Post Processing Effects + Screen Tiling (#583)

* scene setup

* post processing script

* vignette effect

* small change

* chromatic abberation added

* bloom added

* lens distortion added

* collapse param stuff

* Color grading

* screen tiling added
This commit is contained in:
Rapandrasmus
2023-11-23 22:31:23 +01:00
committed by GitHub
parent 9c37ec4216
commit 012b354db8
11 changed files with 2177 additions and 29 deletions

View File

@ -663,7 +663,7 @@ namespace HeavenStudio
//temp for testing
function = delegate {
var e = eventCaller.currentEntity;
Common.SkillStarManager.instance.DoStarIn(e.beat, e.length);
Common.SkillStarManager.instance.DoStarIn(e.beat, e.length);
}
},
new GameAction("toggle inputs", "Toggle Inputs", 0.5f, true,
@ -774,7 +774,10 @@ namespace HeavenStudio
new Param("colorB", Color.white, "End Color"),
new Param("valA", new EntityTypes.Float(0, 1, 1), "Start Opacity"),
new Param("valB", new EntityTypes.Float(0, 1, 0), "End Opacity"),
new Param("ease", Util.EasingFunction.Ease.Linear, "Ease")
new Param("ease", Util.EasingFunction.Ease.Linear, "Ease", "", new()
{
new((x, y) => (Util.EasingFunction.Ease)x != Util.EasingFunction.Ease.Instant, new string[] { "colorA", "valA" })
})
}
),
new GameAction("filter", "Filter", 1f, true,
@ -791,7 +794,10 @@ namespace HeavenStudio
new Param("start", new EntityTypes.Float(0, 1, 1), "Start Intensity"),
new Param("end", new EntityTypes.Float(0, 1, 1), "End Intensity"),
new Param("ease", Util.EasingFunction.Ease.Linear, "Ease"),
new Param("ease", Util.EasingFunction.Ease.Linear, "Ease", "", new()
{
new((x, y) => (Util.EasingFunction.Ease)x != Util.EasingFunction.Ease.Instant, new string[] { "start" })
}),
}
),
new GameAction("move camera", "Move Camera", 1f, true, new List<Param>()
@ -884,6 +890,162 @@ namespace HeavenStudio
new Param("instantOff", false, "Instant Hide", "Skip the hide animation?"),
}
),
// Post Processing VFX
new GameAction("vignette", "Vignette")
{
resizable = true,
parameters = new()
{
new("intenStart", new EntityTypes.Float(0f, 1f), "Start Intensity"),
new("intenEnd", new EntityTypes.Float(0f, 1f, 1f), "End Intensity"),
new("colorStart", Color.black, "Start Color"),
new("colorEnd", Color.black, "End Color"),
new("smoothStart", new EntityTypes.Float(0.01f, 1f, 0.2f), "Start Smoothness"),
new("smoothEnd", new EntityTypes.Float(0.01f, 1f, 0.2f), "End Smoothness"),
new("roundStart", new EntityTypes.Float(0f, 1f, 1f), "Start Roundness"),
new("roundEnd", new EntityTypes.Float(0f, 1f, 1f), "End Roundness"),
new("rounded", false, "Rounded"),
new("ease", Util.EasingFunction.Ease.Linear, "Ease", "", new()
{
new((x, y) => (Util.EasingFunction.Ease)x != Util.EasingFunction.Ease.Instant, new string[] { "intenStart", "colorStart", "smoothStart", "roundStart" })
}),
}
},
new GameAction("cabb", "Chromatic Abberation")
{
resizable = true,
parameters = new()
{
new("intenStart", new EntityTypes.Float(0f, 1f), "Start Intensity"),
new("intenEnd", new EntityTypes.Float(0f, 1f, 1f), "End Intensity"),
new("ease", Util.EasingFunction.Ease.Linear, "Ease", "", new()
{
new((x, y) => (Util.EasingFunction.Ease)x != Util.EasingFunction.Ease.Instant, new string[] { "intenStart" })
}),
}
},
new GameAction("bloom", "Bloom")
{
resizable = true,
parameters = new()
{
new("intenStart", new EntityTypes.Float(0f, 100f, 0f), "Start Intensity"),
new("intenEnd", new EntityTypes.Float(0f, 100f, 1f), "End Intensity"),
new("colorStart", Color.white, "Start Tint"),
new("colorEnd", Color.white, "End Tint"),
new("thresholdStart", new EntityTypes.Float(0f, 100f, 1f), "Start Threshold"),
new("thresholdEnd", new EntityTypes.Float(0f, 100f, 1f), "End Threshold"),
new("softKneeStart", new EntityTypes.Float(0f, 1f, 0.5f), "Start Soft Knee"),
new("softKneeEnd", new EntityTypes.Float(0f, 1f, 0.5f), "End Soft Knee"),
new("anaStart", new EntityTypes.Float(-1f, 1f, 0f), "Start Anamorphic Ratio"),
new("anaEnd", new EntityTypes.Float(-1f, 1f, 0f), "End Anamorphic Ratio"),
new("ease", Util.EasingFunction.Ease.Linear, "Ease", "", new()
{
new((x, y) => (Util.EasingFunction.Ease)x != Util.EasingFunction.Ease.Instant, new string[] { "intenStart", "colorStart", "thresholdStart", "softKneeStart", "anaStart" })
}),
}
},
new GameAction("lensD", "Lens Distortion")
{
resizable = true,
parameters = new()
{
new("intenStart", new EntityTypes.Float(-100f, 100f, 0f), "Start Intensity"),
new("intenEnd", new EntityTypes.Float(-100f, 100f, 1f), "End Intensity"),
new("xStart", new EntityTypes.Float(0f, 1f, 1f), "Start X Multiplier"),
new("yStart", new EntityTypes.Float(0f, 1f, 1f), "Start Y Multiplier"),
new("xEnd", new EntityTypes.Float(0f, 1f, 1f), "End X Multiplier"),
new("yEnd", new EntityTypes.Float(0f, 1f, 1f), "End Y Multiplier"),
new("ease", Util.EasingFunction.Ease.Linear, "Ease", "", new()
{
new((x, y) => (Util.EasingFunction.Ease)x != Util.EasingFunction.Ease.Instant, new string[] { "intenStart", "xStart", "yStart" })
}),
}
},
new GameAction("grain", "Grain")
{
resizable = true,
parameters = new()
{
new("intenStart", new EntityTypes.Float(0f, 1f), "Start Intensity"),
new("intenEnd", new EntityTypes.Float(0f, 1f, 1f), "End Intensity"),
new("sizeStart", new EntityTypes.Float(0.3f, 3f, 1f), "Start Size"),
new("sizeEnd", new EntityTypes.Float(0.3f, 3f, 1f), "End Size"),
new("colored", true, "Colored"),
new("ease", Util.EasingFunction.Ease.Linear, "Ease", "", new()
{
new((x, y) => (Util.EasingFunction.Ease)x != Util.EasingFunction.Ease.Instant, new string[] { "intenStart", "sizeStart" })
}),
}
},
new GameAction("colorGrading", "Color Grading")
{
resizable = true,
parameters = new()
{
new("tempStart", new EntityTypes.Float(-100f, 100f), "Start Temperature"),
new("tempEnd", new EntityTypes.Float(-100f, 100f), "End Temperature"),
new("tintStart", new EntityTypes.Float(-100f, 100f), "Start Tint"),
new("tintEnd", new EntityTypes.Float(-100f, 100f), "End Tint"),
new("colorStart", Color.white, "Start Color Filter"),
new("colorEnd", Color.white, "End Color Filter"),
new("hueShiftStart", new EntityTypes.Float(-180f, 180f), "Start Hue Shift"),
new("hueShiftEnd", new EntityTypes.Float(-180f, 180f), "End Hue Shift"),
new("satStart", new EntityTypes.Float(-100f, 100f), "Start Saturation"),
new("satEnd", new EntityTypes.Float(-100f, 100f), "End Saturation"),
new("brightStart", new EntityTypes.Float(-100f, 100f), "Start Brightness"),
new("brightEnd", new EntityTypes.Float(-100f, 100f), "End Brightness"),
new("conStart", new EntityTypes.Float(-100f, 100f), "Start Contrast"),
new("conEnd", new EntityTypes.Float(-100f, 100f), "End Contrast"),
new("ease", Util.EasingFunction.Ease.Linear, "Ease", "", new()
{
new((x, y) => (Util.EasingFunction.Ease)x != Util.EasingFunction.Ease.Instant, new string[] { "tempStart", "tintStart", "colorStart", "hueShiftStart", "satStart", "brightStart", "conStart" })
}),
}
},
new GameAction("screenTiling", "Screen Tiling")
{
resizable = true,
parameters = new()
{
new("xStart", new EntityTypes.Float(1, 100, 1), "Start Horizontal Tiles"),
new("yStart", new EntityTypes.Float(1, 100, 1), "Start Vertical Tiles"),
new("xEnd", new EntityTypes.Float(1, 100, 1), "End Horizontal Tiles"),
new("yEnd", new EntityTypes.Float(1, 100, 1), "End Vertical Tiles"),
new("xScrollStart", new EntityTypes.Float(-100, 100, 0), "Start Horizontal Scroll"),
new("yScrollStart", new EntityTypes.Float(-100, 100, 0), "Start Vertical Scroll"),
new("xScrollEnd", new EntityTypes.Float(-100, 100, 0), "End Horizontal Scroll"),
new("yScrollEnd", new EntityTypes.Float(-100, 100, 0), "End Vertical Scroll"),
new("ease", Util.EasingFunction.Ease.Linear, "Ease", "", new()
{
new((x, y) => (Util.EasingFunction.Ease)x != Util.EasingFunction.Ease.Instant, new string[] { "xStart", "yStart", "xScrollStart", "yScrollStart" })
}),
}
}
}),
};

View File

@ -0,0 +1,236 @@
using Jukebox;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
namespace HeavenStudio
{
public class PostProcessingVFX : MonoBehaviour
{
private PostProcessVolume _volume;
// events
private List<RiqEntity> _vignettes = new();
private List<RiqEntity> _cabbs = new();
private List<RiqEntity> _blooms = new();
private List<RiqEntity> _lensDs = new();
private List<RiqEntity> _grains = new();
private List<RiqEntity> _colorGradings = new();
private void Awake()
{
_volume = GetComponent<PostProcessVolume>();
}
private void Start()
{
GameManager.instance.onBeatChanged += OnBeatChanged;
}
public void OnBeatChanged(double beat)
{
_vignettes = EventCaller.GetAllInGameManagerList("vfx", new string[] { "vignette" });
_cabbs = EventCaller.GetAllInGameManagerList("vfx", new string[] { "cabb" });
_blooms = EventCaller.GetAllInGameManagerList("vfx", new string[] { "bloom" });
_lensDs = EventCaller.GetAllInGameManagerList("vfx", new string[] { "lensD" });
_grains = EventCaller.GetAllInGameManagerList("vfx", new string[] { "grain" });
_colorGradings = EventCaller.GetAllInGameManagerList("vfx", new string[] { "colorGrading" });
UpdateVignette();
UpdateChromaticAbberations();
UpdateBlooms();
UpdateLensDistortions();
UpdateGrain();
UpdateColorGrading();
}
private void Update()
{
UpdateVignette();
UpdateChromaticAbberations();
UpdateBlooms();
UpdateLensDistortions();
UpdateGrain();
UpdateColorGrading();
}
private void UpdateVignette()
{
if (!_volume.profile.TryGetSettings<Vignette>(out var v)) return;
v.enabled.Override(false);
foreach (var e in _vignettes)
{
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 newIntensity = func(e["intenStart"], e["intenEnd"], clampNormal);
v.enabled.Override(newIntensity != 0);
if (!v.enabled) continue;
v.rounded.Override(e["rounded"]);
Color newColor = ColorEase(e["colorStart"], e["colorEnd"], clampNormal, func);
v.color.Override(newColor);
v.intensity.Override(newIntensity);
float newSmoothness = func(e["smoothStart"], e["smoothEnd"], clampNormal);
v.smoothness.Override(newSmoothness);
float newRoundness = func(e["roundStart"], e["roundEnd"], clampNormal);
v.roundness.Override(newRoundness);
}
}
private void UpdateChromaticAbberations()
{
if (!_volume.profile.TryGetSettings<ChromaticAberration>(out var c)) return;
c.enabled.Override(false);
foreach (var e in _cabbs)
{
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 newIntensity = func(e["intenStart"], e["intenEnd"], clampNormal);
c.enabled.Override(newIntensity != 0);
if (!c.enabled) continue;
c.intensity.Override(newIntensity);
}
}
private void UpdateBlooms()
{
if (!_volume.profile.TryGetSettings<Bloom>(out var b)) return;
b.enabled.Override(false);
foreach (var e in _blooms)
{
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 newIntensity = func(e["intenStart"], e["intenEnd"], clampNormal);
b.enabled.Override(newIntensity != 0);
if (!b.enabled) continue;
b.intensity.Override(newIntensity);
Color newColor = ColorEase(e["colorStart"], e["colorEnd"], clampNormal, func);
b.color.Override(newColor);
float newThreshold = func(e["thresholdStart"], e["thresholdEnd"], clampNormal);
b.threshold.Override(newThreshold);
float newSoftKnee = func(e["softKneeStart"], e["softKneeEnd"], clampNormal);
b.softKnee.Override(newSoftKnee);
float newAna = func(e["anaStart"], e["anaEnd"], clampNormal);
b.anamorphicRatio.Override(newAna);
}
}
private void UpdateLensDistortions()
{
if (!_volume.profile.TryGetSettings<LensDistortion>(out var l)) return;
l.enabled.Override(false);
foreach (var e in _lensDs)
{
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 newIntensity = func(e["intenStart"], e["intenEnd"], clampNormal);
l.enabled.Override(newIntensity != 0);
if (!l.enabled) continue;
l.intensity.Override(newIntensity);
float newX = func(e["xStart"], e["xEnd"], clampNormal);
l.intensityX.Override(newX);
float newY = func(e["yStart"], e["yEnd"], clampNormal);
l.intensityY.Override(newY);
}
}
private void UpdateGrain()
{
if (!_volume.profile.TryGetSettings<Grain>(out var g)) return;
g.enabled.Override(false);
foreach (var e in _grains)
{
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 newIntensity = func(e["intenStart"], e["intenEnd"], clampNormal);
g.enabled.Override(newIntensity != 0);
if (!g.enabled) continue;
g.intensity.Override(newIntensity);
g.colored.Override(e["colored"]);
float newSize = func(e["sizeStart"], e["sizeEnd"], clampNormal);
g.size.Override(newSize);
}
}
private void UpdateColorGrading()
{
if (!_volume.profile.TryGetSettings<ColorGrading>(out var c)) return;
c.enabled.Override(false);
foreach (var e in _colorGradings)
{
c.enabled.Override(true);
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 newTemp = func(e["tempStart"], e["tempEnd"], clampNormal);
c.temperature.Override(newTemp);
float newTint = func(e["tintStart"], e["tintEnd"], clampNormal);
c.tint.Override(newTint);
Color newColor = ColorEase(e["colorStart"], e["colorEnd"], clampNormal, func);
c.colorFilter.Override(newColor);
float newHue = func(e["hueShiftStart"], e["hueShiftEnd"], clampNormal);
c.hueShift.Override(newHue);
float newSat = func(e["satStart"], e["satEnd"], clampNormal);
c.saturation.Override(newSat);
float newBright = func(e["brightStart"], e["brightEnd"], clampNormal);
c.brightness.Override(newBright);
float newCon = func(e["conStart"], e["conEnd"], clampNormal);
c.contrast.Override(newCon);
}
}
private Color ColorEase(Color start, Color end, float time, Util.EasingFunction.Function func)
{
float newR = func(start.r, end.r, time);
float newG = func(start.g, end.g, time);
float newB = func(start.b, end.b, time);
return new Color(newR, newG, newB, 1);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e3cc0a4bae0c56540b9f598f4644539c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Jukebox;
using UnityEngine.UI;
namespace HeavenStudio
{
public class ScreenTiling : MonoBehaviour
{
private RawImage _image;
private RectTransform _rectTransform;
private List<RiqEntity> _events = new();
private void Awake()
{
_image = GetComponent<RawImage>();
_rectTransform = GetComponent<RectTransform>();
}
private void Start()
{
GameManager.instance.onBeatChanged += OnBeatChanged;
}
public void OnBeatChanged(double beat)
{
_events = EventCaller.GetAllInGameManagerList("vfx", new string[] { "screenTiling" });
ResetUVRect();
Update();
}
private void Update()
{
foreach (var e in _events)
{
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 newXTiles = func(e["xStart"], e["xEnd"], clampNormal);
float newYTiles = func(e["yStart"], e["yEnd"], clampNormal);
float newXScroll = func(e["xScrollStart"], e["xScrollEnd"], clampNormal);
float newYScroll = func(e["yScrollStart"], e["yScrollEnd"], clampNormal);
_image.uvRect = new Rect(newXScroll, newYScroll, newXTiles, newYTiles);
_rectTransform.localScale = new Vector3(1 / newXTiles, 1 / newYTiles);
}
}
public void ResetUVRect()
{
_image.uvRect = new Rect(0, 0, 1, 1);
_rectTransform.localScale = Vector3.one;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d556607141c07af40b1b5ee71c28c5a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: