fix(memory): 调频 shader 不可用回退 Volume 并绑定场景引用

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-02 17:56:41 +08:00
co-authored by Cursor
parent bd94302714
commit f3c3994f5c
2 changed files with 27 additions and 17 deletions
+1
View File
@@ -6261,6 +6261,7 @@ MonoBehaviour:
memoryGroup: {fileID: 810486144}
punchTapeSlot: {fileID: 803004212}
fadeMaterial: {fileID: 2100000, guid: e54618b1fa673734dae0038617cf6f9a, type: 2}
memoryTuningShader: {fileID: 4800000, guid: 9f7b2ef66c2842c496327822f79da521, type: 3}
--- !u!4 &763669272
Transform:
m_ObjectHideFlags: 0
@@ -20,20 +20,19 @@ namespace AibisDream.FixSystem
private const float ProjectorMoveDuration = 2f;
private const float MaxClarityDistortion = 1f;
private const float MaxFrequencyBlur = 0.6f;
private const float MobileMaxFrequencyBlur = 0.45f;
private const float MinPixelDensity = 18f;
private const float MobileMinPixelDensity = 24f;
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");
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 MemoryGrayscaleId = Shader.PropertyToID("_MemoryGrayscale");
private static readonly int MemoryContrastId = Shader.PropertyToID("_MemoryContrast");
@@ -76,8 +75,10 @@ namespace AibisDream.FixSystem
[SerializeField] private MemoryPunchTapeSlot punchTapeSlot;
[SerializeField] private Material fadeMaterial;
[SerializeField] private Shader memoryTuningShader;
private Material runtimeMemoryMaterial;
private Material runtimeNoColorMemoryMaterial;
private bool spriteShaderTuningAvailable;
private Tween overlayTween;
public void OpenMemoryView()
@@ -276,14 +277,14 @@ namespace AibisDream.FixSystem
{
frequencySlider.OnTuningChanged -= ApplyFrequencyTuning;
frequencySlider.Init(memoryFrequencyVolume);
frequencySlider.SetVolumeOutputEnabled(!useSpriteShaderTuning);
frequencySlider.SetVolumeOutputEnabled(!spriteShaderTuningAvailable);
frequencySlider.OnTuningChanged += ApplyFrequencyTuning;
}
if (claritySlider != null)
{
claritySlider.OnTuningChanged -= ApplyClarityTuning;
claritySlider.Init(memoryClarityVolume);
claritySlider.SetVolumeOutputEnabled(!useSpriteShaderTuning);
claritySlider.SetVolumeOutputEnabled(!spriteShaderTuningAvailable);
claritySlider.OnTuningChanged += ApplyClarityTuning;
}
@@ -463,33 +464,31 @@ namespace AibisDream.FixSystem
private void ApplyFrequencyTuning(float strength)
{
if (!useSpriteShaderTuning || fadeMaterial == null)
if (!spriteShaderTuningAvailable || fadeMaterial == null)
return;
bool active = strength > 0.001f;
float blurCap = Application.isMobilePlatform ? MobileMaxFrequencyBlur : MaxFrequencyBlur;
float minPixelDensity = Application.isMobilePlatform ? MobileMinPixelDensity : MinPixelDensity;
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(PixelatePixelDensityId, Mathf.Lerp(MaxPixelDensity, minPixelDensity, strength));
SetFloatIfExists(GaussianBlurFadeId, strength * blurCap);
SetFloatIfExists(GaussianBlurOffsetId, Mathf.Lerp(0.05f, 0.35f, strength));
}
private void ApplyClarityTuning(float strength)
{
if (!useSpriteShaderTuning || fadeMaterial == null)
if (!spriteShaderTuningAvailable || fadeMaterial == null)
return;
bool active = strength > 0.001f;
SetFloatIfExists(ClarityTuningId, strength);
SetFloatIfExists(EnableUvDistortId, active ? 1f : 0f);
SetFloatIfExists(UvDistortFadeId, strength * MaxClarityDistortion);
}
private void ResetSpriteTuning()
{
if (!useSpriteShaderTuning || fadeMaterial == null)
if (!spriteShaderTuningAvailable || fadeMaterial == null)
return;
ApplyFrequencyTuning(0f);
@@ -528,6 +527,7 @@ namespace AibisDream.FixSystem
private void PrepareRuntimeMemoryMaterial()
{
spriteShaderTuningAvailable = false;
if (!useSpriteShaderTuning || !HasMemoryGraphic())
return;
@@ -535,12 +535,20 @@ namespace AibisDream.FixSystem
if (baseMaterial == null)
baseMaterial = fadeMaterial;
var shader = baseMaterial != null ? baseMaterial.shader : null;
var shader = memoryTuningShader;
if (shader == null && baseMaterial != null)
shader = baseMaterial.shader;
if (shader == null || shader.name != "AibisDream/MemoryTuningSprite")
shader = Shader.Find("AibisDream/MemoryTuningSprite");
if (shader == null)
{
Debug.LogWarning("[MemoryProcess] 未找到 AibisDream/MemoryTuningSprite,调频将回退到当前材质表现。", this);
Debug.LogWarning("[MemoryProcess] 未找到 AibisDream/MemoryTuningSprite,调频将回退到 Volume 后处理。", this);
return;
}
if (!shader.isSupported)
{
Debug.LogWarning("[MemoryProcess] MemoryTuningSprite 在当前平台不受支持,调频将回退到 Volume 后处理。", this);
return;
}
@@ -560,6 +568,7 @@ namespace AibisDream.FixSystem
SetNoColorMemoryMaterial(runtimeNoColorMemoryMaterial);
}
spriteShaderTuningAvailable = true;
ResetSpriteTuning();
}