feat(effects): 为噪点Glitch增加透明叠加合成模式
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -31,6 +31,7 @@ Material:
|
||||
m_Floats:
|
||||
- _BlockSize: 28.8
|
||||
- _ChromaticShift: 0.04
|
||||
- _CompositeMode: 0
|
||||
- _DisplaceStrength: 0.15
|
||||
- _DropoutSize: 0.058
|
||||
- _FlickerStrength: 0.839
|
||||
|
||||
@@ -8,6 +8,7 @@ Shader "AibisDream/SpriteNoiseGlitch"
|
||||
[Header(Glitch Control)]
|
||||
_GlitchIntensity("Glitch Intensity", Range(0, 1)) = 0
|
||||
_Speed("Animation Speed", Float) = 5.0
|
||||
[Enum(Opaque Background,0,Transparent Overlay,1)] _CompositeMode("Composite Mode", Float) = 0
|
||||
|
||||
[Header(Noise)]
|
||||
_NoiseScale("Noise Scale (lower = bigger pixel dots)", Range(40, 500)) = 80
|
||||
@@ -87,6 +88,7 @@ Shader "AibisDream/SpriteNoiseGlitch"
|
||||
float4 _Color;
|
||||
float _GlitchIntensity;
|
||||
float _Speed;
|
||||
float _CompositeMode;
|
||||
float _NoiseScale;
|
||||
float _NoiseDensity;
|
||||
float _NoiseBrightness;
|
||||
@@ -299,9 +301,11 @@ Shader "AibisDream/SpriteNoiseGlitch"
|
||||
|
||||
half4 result;
|
||||
result.rgb = baseColor;
|
||||
result.a = spriteAlpha;
|
||||
result *= input.color;
|
||||
result.a = spriteAlpha;
|
||||
float overlayEnergy = max(baseColor.r, max(baseColor.g, baseColor.b));
|
||||
float overlayVisible = step(0.0001, _GlitchIntensity);
|
||||
float overlayAlpha = spriteAlpha * saturate(overlayEnergy * 1.35 + intensity * 0.18) * overlayVisible;
|
||||
result.a = lerp(spriteAlpha, overlayAlpha, saturate(_CompositeMode));
|
||||
result.rgb *= input.color.rgb;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -342,6 +346,7 @@ Shader "AibisDream/SpriteNoiseGlitch"
|
||||
float4 _Color;
|
||||
float _GlitchIntensity;
|
||||
float _Speed;
|
||||
float _CompositeMode;
|
||||
float _NoiseScale;
|
||||
float _NoiseDensity;
|
||||
float _NoiseBrightness;
|
||||
@@ -530,9 +535,11 @@ Shader "AibisDream/SpriteNoiseGlitch"
|
||||
|
||||
half4 result;
|
||||
result.rgb = baseColor;
|
||||
result.a = spriteAlpha;
|
||||
result *= input.color;
|
||||
result.a = spriteAlpha;
|
||||
float overlayEnergy = max(baseColor.r, max(baseColor.g, baseColor.b));
|
||||
float overlayVisible = step(0.0001, _GlitchIntensity);
|
||||
float overlayAlpha = spriteAlpha * saturate(overlayEnergy * 1.35 + intensity * 0.18) * overlayVisible;
|
||||
result.a = lerp(spriteAlpha, overlayAlpha, saturate(_CompositeMode));
|
||||
result.rgb *= input.color.rgb;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -5,11 +5,13 @@ using System.Collections;
|
||||
public class SpriteNoiseGlitchController : MonoBehaviour
|
||||
{
|
||||
public enum GlitchStage { None, Light, Medium, Heavy }
|
||||
public enum CompositeMode { OpaqueBackground, TransparentOverlay }
|
||||
|
||||
[Header("Runtime")]
|
||||
[SerializeField] private GlitchStage _currentStage = GlitchStage.None;
|
||||
[SerializeField, Range(0f, 1f)] private float _intensity;
|
||||
[SerializeField] private float _transitionDuration = 0.5f;
|
||||
[SerializeField] private CompositeMode _compositeMode = CompositeMode.OpaqueBackground;
|
||||
|
||||
[Header("Audio (Optional)")]
|
||||
[Tooltip("由 Tools > Generate Glitch Noise Audio 生成")]
|
||||
@@ -41,6 +43,7 @@ public class SpriteNoiseGlitchController : MonoBehaviour
|
||||
private bool _calmFieldRequested;
|
||||
|
||||
private static readonly int PropGlitchIntensity = Shader.PropertyToID("_GlitchIntensity");
|
||||
private static readonly int PropCompositeMode = Shader.PropertyToID("_CompositeMode");
|
||||
private static readonly int PropBaseNoiseDensity = Shader.PropertyToID("_BaseNoiseDensity");
|
||||
private static readonly int PropBaseNoiseScale = Shader.PropertyToID("_BaseNoiseScale");
|
||||
private static readonly int PropBaseNoiseBrightness = Shader.PropertyToID("_BaseNoiseBrightness");
|
||||
@@ -69,6 +72,8 @@ public class SpriteNoiseGlitchController : MonoBehaviour
|
||||
set => SetStage(value);
|
||||
}
|
||||
|
||||
public CompositeMode CurrentCompositeMode => _compositeMode;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_renderer = GetComponent<SpriteRenderer>();
|
||||
@@ -78,10 +83,21 @@ public class SpriteNoiseGlitchController : MonoBehaviour
|
||||
private void OnEnable()
|
||||
{
|
||||
ApplyIntensity();
|
||||
ApplyCompositeMode();
|
||||
ApplyCalmField();
|
||||
ApplyAmbientNoise();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 小游戏阶段使用不透明黑底;记忆阶段使用透明叠加。透明模式下强度为 0 时
|
||||
/// Shader 不写入任何可见像素,避免黑底遮挡记忆图。
|
||||
/// </summary>
|
||||
public void SetCompositeMode(CompositeMode mode)
|
||||
{
|
||||
_compositeMode = mode;
|
||||
ApplyCompositeMode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置常驻细密噪点(与 glitch 强度无关,一直显示)。density 为 0 时关闭。
|
||||
/// </summary>
|
||||
@@ -312,6 +328,16 @@ public class SpriteNoiseGlitchController : MonoBehaviour
|
||||
_renderer.SetPropertyBlock(_mpb);
|
||||
}
|
||||
|
||||
private void ApplyCompositeMode()
|
||||
{
|
||||
EnsureRuntimeObjects();
|
||||
if (_renderer == null) return;
|
||||
|
||||
_renderer.GetPropertyBlock(_mpb);
|
||||
_mpb.SetFloat(PropCompositeMode, (float)_compositeMode);
|
||||
_renderer.SetPropertyBlock(_mpb);
|
||||
}
|
||||
|
||||
private void ApplyCalmField()
|
||||
{
|
||||
EnsureRuntimeObjects();
|
||||
@@ -374,6 +400,7 @@ public class SpriteNoiseGlitchController : MonoBehaviour
|
||||
EnsureRuntimeObjects();
|
||||
|
||||
ApplyIntensity();
|
||||
ApplyCompositeMode();
|
||||
ApplyCalmField();
|
||||
ApplyAmbientNoise();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user