feat: add memory tuning sprite shader
This commit is contained in:
@@ -17,6 +17,23 @@ namespace AibisDream.FixSystem
|
||||
private const float DefaultFadeDuration = 1f;
|
||||
private const float SearchStartDelay = 1f;
|
||||
private const float ProjectorMoveDuration = 2f;
|
||||
private const float MaxClarityDistortion = 0.58f;
|
||||
private const float MaxFrequencyBlur = 0.6f;
|
||||
private const float MinPixelDensity = 18f;
|
||||
private const float MaxPixelDensity = 96f;
|
||||
|
||||
private static readonly int EnablePixelateId = Shader.PropertyToID("_EnablePixelate");
|
||||
private static readonly int FrequencyTuningId = Shader.PropertyToID("_FrequencyTuning");
|
||||
private static readonly int ClarityTuningId = Shader.PropertyToID("_ClarityTuning");
|
||||
private static readonly int PixelateFadeId = Shader.PropertyToID("_PixelateFade");
|
||||
private static readonly int PixelatePixelDensityId = Shader.PropertyToID("_PixelatePixelDensity");
|
||||
private static readonly int EnableGaussianBlurId = Shader.PropertyToID("_EnableGaussianBlur");
|
||||
private static readonly int GaussianBlurFadeId = Shader.PropertyToID("_GaussianBlurFade");
|
||||
private static readonly int GaussianBlurOffsetId = Shader.PropertyToID("_GaussianBlurOffset");
|
||||
private static readonly int EnableUvDistortId = Shader.PropertyToID("_EnableUVDistort");
|
||||
private static readonly int UvDistortFadeId = Shader.PropertyToID("_UVDistortFade");
|
||||
private static readonly int EnableSaturationId = Shader.PropertyToID("_EnableSaturation");
|
||||
private static readonly int SaturationId = Shader.PropertyToID("_Saturation");
|
||||
|
||||
[SerializeField] private BubbleSlotGroup bubbleSlotGroup;
|
||||
public BubbleSlotGroup BubbleSlotGroup => bubbleSlotGroup;
|
||||
@@ -31,6 +48,7 @@ namespace AibisDream.FixSystem
|
||||
[SerializeField] private Volume memoryProcessVolume;
|
||||
[SerializeField] private MemorySlider frequencySlider; // 频率调节滑动条
|
||||
[SerializeField] private MemorySlider claritySlider; // 清晰度调节滑动条
|
||||
[SerializeField] private bool useSpriteShaderTuning = true;
|
||||
|
||||
[SerializeField] private CanvasGroup playBackground;
|
||||
|
||||
@@ -45,6 +63,7 @@ namespace AibisDream.FixSystem
|
||||
[SerializeField] private MemoryPunchTapeSlot punchTapeSlot;
|
||||
|
||||
[SerializeField] private Material fadeMaterial;
|
||||
private Material runtimeMemoryMaterial;
|
||||
|
||||
public void OpenMemoryView()
|
||||
{
|
||||
@@ -147,11 +166,18 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private void Start()
|
||||
{
|
||||
PrepareRuntimeMemoryMaterial();
|
||||
frequencySlider.OnFound += CheckAllFound;
|
||||
claritySlider.OnFound += CheckAllFound;
|
||||
Init();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (runtimeMemoryMaterial != null)
|
||||
Destroy(runtimeMemoryMaterial);
|
||||
}
|
||||
|
||||
private void CheckAllFound()
|
||||
{
|
||||
if (frequencySlider.IsFound && claritySlider.IsFound)
|
||||
@@ -206,9 +232,19 @@ namespace AibisDream.FixSystem
|
||||
}
|
||||
|
||||
if (frequencySlider != null)
|
||||
{
|
||||
frequencySlider.OnTuningChanged -= ApplyFrequencyTuning;
|
||||
frequencySlider.Init(memoryFrequencyVolume);
|
||||
frequencySlider.SetVolumeOutputEnabled(!useSpriteShaderTuning);
|
||||
frequencySlider.OnTuningChanged += ApplyFrequencyTuning;
|
||||
}
|
||||
if (claritySlider != null)
|
||||
{
|
||||
claritySlider.OnTuningChanged -= ApplyClarityTuning;
|
||||
claritySlider.Init(memoryClarityVolume);
|
||||
claritySlider.SetVolumeOutputEnabled(!useSpriteShaderTuning);
|
||||
claritySlider.OnTuningChanged += ApplyClarityTuning;
|
||||
}
|
||||
|
||||
ResetPresentationState();
|
||||
}
|
||||
@@ -239,6 +275,7 @@ namespace AibisDream.FixSystem
|
||||
{
|
||||
if (fadeMaterial != null)
|
||||
fadeMaterial.SetFloat("_DirectionalDistortionFade", FadeMaterialStartValue);
|
||||
ResetSpriteTuning();
|
||||
memoryFinishedSpriteRenderer.color = Color.black;
|
||||
memoryProcessVolume.weight = 0;
|
||||
_activePunchTape = null;
|
||||
@@ -377,10 +414,76 @@ namespace AibisDream.FixSystem
|
||||
claritySlider.SetInteractable(true);
|
||||
}
|
||||
|
||||
private void ApplyFrequencyTuning(float strength)
|
||||
{
|
||||
if (!useSpriteShaderTuning || fadeMaterial == null)
|
||||
return;
|
||||
|
||||
bool active = strength > 0.001f;
|
||||
SetFloatIfExists(FrequencyTuningId, strength);
|
||||
SetFloatIfExists(EnablePixelateId, active ? 1f : 0f);
|
||||
SetFloatIfExists(PixelateFadeId, strength);
|
||||
SetFloatIfExists(PixelatePixelDensityId, Mathf.Lerp(MaxPixelDensity, MinPixelDensity, strength));
|
||||
SetFloatIfExists(EnableGaussianBlurId, active ? 1f : 0f);
|
||||
SetFloatIfExists(GaussianBlurFadeId, strength * MaxFrequencyBlur);
|
||||
SetFloatIfExists(GaussianBlurOffsetId, Mathf.Lerp(0.05f, 0.35f, strength));
|
||||
}
|
||||
|
||||
private void ApplyClarityTuning(float strength)
|
||||
{
|
||||
if (!useSpriteShaderTuning || fadeMaterial == null)
|
||||
return;
|
||||
|
||||
bool active = strength > 0.001f;
|
||||
SetFloatIfExists(ClarityTuningId, strength);
|
||||
SetFloatIfExists(EnableUvDistortId, active ? 1f : 0f);
|
||||
SetFloatIfExists(UvDistortFadeId, strength * MaxClarityDistortion);
|
||||
SetFloatIfExists(EnableSaturationId, active ? 1f : 0f);
|
||||
SetFloatIfExists(SaturationId, Mathf.Lerp(1f, 0.25f, strength));
|
||||
}
|
||||
|
||||
private void ResetSpriteTuning()
|
||||
{
|
||||
if (!useSpriteShaderTuning || fadeMaterial == null)
|
||||
return;
|
||||
|
||||
ApplyFrequencyTuning(0f);
|
||||
ApplyClarityTuning(0f);
|
||||
}
|
||||
|
||||
private void SetFloatIfExists(int propertyId, float value)
|
||||
{
|
||||
if (fadeMaterial.HasProperty(propertyId))
|
||||
fadeMaterial.SetFloat(propertyId, value);
|
||||
}
|
||||
|
||||
private void PrepareRuntimeMemoryMaterial()
|
||||
{
|
||||
if (!useSpriteShaderTuning || memoryFinishedSpriteRenderer == null || fadeMaterial == null)
|
||||
return;
|
||||
|
||||
var shader = fadeMaterial.shader;
|
||||
if (shader == null || shader.name != "AibisDream/MemoryTuningSprite")
|
||||
shader = Shader.Find("AibisDream/MemoryTuningSprite");
|
||||
if (shader == null)
|
||||
{
|
||||
Debug.LogWarning("[MemoryProcess] 未找到 AibisDream/MemoryTuningSprite,调频将回退到当前材质表现。", this);
|
||||
return;
|
||||
}
|
||||
|
||||
runtimeMemoryMaterial = new Material(fadeMaterial)
|
||||
{
|
||||
shader = shader,
|
||||
name = $"{fadeMaterial.name}_RuntimeMemoryTuning"
|
||||
};
|
||||
memoryFinishedSpriteRenderer.sharedMaterial = runtimeMemoryMaterial;
|
||||
fadeMaterial = runtimeMemoryMaterial;
|
||||
}
|
||||
|
||||
|
||||
public bool IsProcessing()
|
||||
{
|
||||
return isProcessing;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user