feat(fix-system): 迁移记忆调频到精灵材质

This commit is contained in:
2026-06-29 22:23:10 +08:00
parent c392c81d31
commit 814b659c39
3 changed files with 271 additions and 56 deletions
@@ -23,10 +23,12 @@ namespace AibisDream.FixSystem
private const float MaxFrequencyBlur = 0.6f;
private const float MinPixelDensity = 18f;
private const float MaxPixelDensity = 96f;
private const string DirectionalDistortionFadeProperty = "_DirectionalDistortionFade";
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 DirectionalDistortionFadeId = Shader.PropertyToID(DirectionalDistortionFadeProperty);
private static readonly int PixelateFadeId = Shader.PropertyToID("_PixelateFade");
private static readonly int PixelatePixelDensityId = Shader.PropertyToID("_PixelatePixelDensity");
private static readonly int EnableGaussianBlurId = Shader.PropertyToID("_EnableGaussianBlur");
@@ -34,8 +36,8 @@ namespace AibisDream.FixSystem
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");
private static readonly int MemoryGrayscaleId = Shader.PropertyToID("_MemoryGrayscale");
private static readonly int MemoryContrastId = Shader.PropertyToID("_MemoryContrast");
[SerializeField] private GameObject memoryView;
[SerializeField] private GameObject projector;
@@ -63,6 +65,7 @@ namespace AibisDream.FixSystem
[SerializeField] private Material fadeMaterial;
private Material runtimeMemoryMaterial;
private Material runtimeNoColorMemoryMaterial;
private readonly List<RenderTexture> runtimeRenderTextures = new();
public void OpenMemoryView()
@@ -175,6 +178,8 @@ namespace AibisDream.FixSystem
{
if (runtimeMemoryMaterial != null)
Destroy(runtimeMemoryMaterial);
if (runtimeNoColorMemoryMaterial != null)
Destroy(runtimeNoColorMemoryMaterial);
foreach (var renderTexture in runtimeRenderTextures)
{
@@ -323,6 +328,9 @@ namespace AibisDream.FixSystem
public void TweenWeight(Volume postProcessingVolume, float targetWeight, float duration)
{
if (postProcessingVolume == null)
return;
// 动态调整权重
DOTween.To(() => postProcessingVolume.weight, x => postProcessingVolume.weight = x, targetWeight, duration);
}
@@ -381,10 +389,10 @@ namespace AibisDream.FixSystem
private void ResetPresentationState()
{
if (fadeMaterial != null)
fadeMaterial.SetFloat("_DirectionalDistortionFade", FadeMaterialStartValue);
SetFloatIfExists(DirectionalDistortionFadeId, FadeMaterialStartValue);
ResetSpriteTuning();
memoryFinishedSpriteRenderer.color = Color.black;
memoryProcessVolume.weight = 0;
SetVolumeWeight(memoryProcessVolume, 0f);
_activePunchTape = null;
playBackground.gameObject.SetActive(false);
@@ -414,8 +422,12 @@ namespace AibisDream.FixSystem
{
if (fadeMaterial == null) yield break;
fadeMaterial.SetFloat("_DirectionalDistortionFade", FadeMaterialStartValue);
Tween tween = fadeMaterial.DOFloat(0, "_DirectionalDistortionFade", 3);
SetFloatIfExists(DirectionalDistortionFadeId, FadeMaterialStartValue);
DG.Tweening.Sequence sequence = DOTween.Sequence();
AppendMaterialFloatTween(sequence, fadeMaterial, 0f, DirectionalDistortionFadeProperty, 3f);
if (runtimeNoColorMemoryMaterial != null && runtimeNoColorMemoryMaterial != fadeMaterial)
AppendMaterialFloatTween(sequence, runtimeNoColorMemoryMaterial, 0f, DirectionalDistortionFadeProperty, 3f);
Tween tween = sequence;
yield return tween.WaitForCompletion();
}
@@ -428,7 +440,7 @@ namespace AibisDream.FixSystem
if (useYarn)
{
if (fadeMaterial != null)
fadeMaterial.SetFloat("_DirectionalDistortionFade", FadeMaterialStartValue);
SetFloatIfExists(DirectionalDistortionFadeId, FadeMaterialStartValue);
var memoryKey = string.Format(MemorySpritePath, memName);
var memoryHandle = ResourceSystem.LoadAsync<Sprite>(memoryKey);
yield return memoryHandle;
@@ -501,14 +513,14 @@ namespace AibisDream.FixSystem
Debug.LogError("Memory not found: " + searchMemoryKey);
}
memoryProcessVolume.weight = 1;
SetVolumeWeight(memoryProcessVolume, 1f);
AudioManager.Instance.PlaySfx("event:/Scriptal/mem_load");
yield return new WaitForSeconds(SearchStartDelay);
AudioManager.Instance.SetSfxParam("event:/Amb/amb_mem_tuning", "is_mem_tuning", 1);
memoryFinishedSpriteRenderer.color = Color.white;
memoryProcessVolume.weight = 0;
SetVolumeWeight(memoryProcessVolume, 0f);
isProcessing = true;
frequencySlider.PrepareForSearch();
claritySlider.PrepareForSearch();
@@ -545,8 +557,6 @@ namespace AibisDream.FixSystem
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()
@@ -560,8 +570,32 @@ namespace AibisDream.FixSystem
private void SetFloatIfExists(int propertyId, float value)
{
if (fadeMaterial.HasProperty(propertyId))
fadeMaterial.SetFloat(propertyId, value);
SetFloatIfExists(fadeMaterial, propertyId, value);
if (runtimeNoColorMemoryMaterial != null && runtimeNoColorMemoryMaterial != fadeMaterial)
SetFloatIfExists(runtimeNoColorMemoryMaterial, propertyId, value);
}
private static void SetVolumeWeight(Volume volume, float weight)
{
if (volume != null)
volume.weight = weight;
}
private static void SetFloatIfExists(Material material, int propertyId, float value)
{
if (material != null && material.HasProperty(propertyId))
material.SetFloat(propertyId, value);
}
private static void AppendMaterialFloatTween(
DG.Tweening.Sequence sequence,
Material material,
float target,
string property,
float duration)
{
if (sequence != null && material != null && material.HasProperty(property))
sequence.Join(material.DOFloat(target, property, duration));
}
private void PrepareRuntimeMemoryMaterial()
@@ -578,13 +612,39 @@ namespace AibisDream.FixSystem
return;
}
runtimeMemoryMaterial = new Material(fadeMaterial)
{
shader = shader,
name = $"{fadeMaterial.name}_RuntimeMemoryTuning"
};
runtimeMemoryMaterial = CreateRuntimeMemoryMaterial(fadeMaterial, shader, "Color", 0f, 1f);
memoryFinishedSpriteRenderer.sharedMaterial = runtimeMemoryMaterial;
fadeMaterial = runtimeMemoryMaterial;
if (memoryFinishedImageNoColor != null && memoryFinishedImageNoColor.sharedMaterial != null)
{
runtimeNoColorMemoryMaterial = CreateRuntimeMemoryMaterial(
memoryFinishedImageNoColor.sharedMaterial,
shader,
"NoColor",
1f,
1.8f);
memoryFinishedImageNoColor.sharedMaterial = runtimeNoColorMemoryMaterial;
}
ResetSpriteTuning();
}
private static Material CreateRuntimeMemoryMaterial(
Material source,
Shader shader,
string suffix,
float grayscale,
float contrast)
{
var material = new Material(source)
{
shader = shader,
name = $"{source.name}_RuntimeMemoryTuning_{suffix}"
};
SetFloatIfExists(material, MemoryGrayscaleId, grayscale);
SetFloatIfExists(material, MemoryContrastId, contrast);
return material;
}