Dependency Properties of Shader Effect won't animate
Posted: 10 Sep 2024, 02:48
I have made a Custom Shader Effect with two dependency properties, that work well when normally set. But when I make an animation with them. The setters are never called. I read something about animations not calling the setters. How can I make it so the properties will animate properly?
I know that the targeting of the animation works. I switched to use a dropshadow effect and I can animate the BlurRadius fine. What do I need to do, to make it so my effect properties will animate properly?
LerpEffect.cs
Xaml
I know that the targeting of the animation works. I switched to use a dropshadow effect and I can animate the BlurRadius fine. What do I need to do, to make it so my effect properties will animate properly?
LerpEffect.cs
Code: Select all
using System;
using System.Runtime.InteropServices;
using Noesis;
namespace Quantum_Survivor
{
public class LerpEffect : ShaderEffect
{
private static NoesisShader Shader;
public LerpEffect()
{
#if !UNITY_EDITOR
if (Shader == null)
#endif
Shader = CreateShader();
SetShader(Shader);
SetConstantBuffer(_constants);
}
public Color Color
{
get { return (Color)GetValue(ColorProperty); }
set { SetValue(ColorProperty, value); }
}
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(
"Color", typeof(Color), typeof(LerpEffect),
new PropertyMetadata(Colors.White, OnColorChanged));
private static void OnColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
LerpEffect this_ = (LerpEffect)d;
this_._constants.color = (Color)e.NewValue;
this_.InvalidateConstantBuffer();
}
public float Blend
{
get { return (float)GetValue(BlendProperty); }
set { SetValue(BlendProperty, value); }
}
public static readonly DependencyProperty BlendProperty = DependencyProperty.Register(
"Blend", typeof(float), typeof(LerpEffect),
new PropertyMetadata(0.5f, OnBlendChanged));
private static void OnBlendChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
LerpEffect this_ = (LerpEffect)d;
this_._constants.blend = (float)e.NewValue;
this_.InvalidateConstantBuffer();
}
[StructLayout(LayoutKind.Sequential)]
private class Constants
{
public Color color = Colors.White;
public float blend = 0.5f;
}
private Constants _constants = new Constants();
}
}
Code: Select all
<Storyboard x:Key="Anim.Release">
<DoubleAnimation Storyboard.TargetName="LerpEffect" Storyboard.TargetProperty="Blend" To="1" Duration="0:0:0.2" DecelerationRatio="1"/>
<ColorAnimation Storyboard.TargetName="LerpEffect" Storyboard.TargetProperty="Color" To="Black" Duration="0:0:0.2" DecelerationRatio="1"/>
</Storyboard>