- burst2flame
- Posts: 26
- Joined:
Dependency Properties of Shader Effect won't animate
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>
-
sfernandez
Site Admin
- Posts: 3139
- Joined:
Re: Dependency Properties of Shader Effect won't animate
Hi,
I guess you have followed our Brush Shaders sample in which we are animating a few properties of the custom shader.
I tried with a simpler xaml like the one below and it correctly animates the Time (float) and Color properties:
Do you have anything different in your code/xaml?
I guess you have followed our Brush Shaders sample in which we are animating a few properties of the custom shader.
I tried with a simpler xaml like the one below and it correctly animates the Time (float) and Color properties:
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
xmlns:local="clr-namespace:BrushShaders">
<Grid.Resources>
<Storyboard x:Key="anim">
<DoubleAnimation Duration="1.0:0:0" Storyboard.TargetName="fx" Storyboard.TargetProperty="Time" To="86400"/>
<ColorAnimation Duration="0:0:5" Storyboard.TargetName="fx" Storyboard.TargetProperty="Color" To="Blue" AutoReverse="True" RepeatBehavior="Forever"/>
</Storyboard>
</Grid.Resources>
<Grid.Triggers>
<EventTrigger RoutedEvent="Grid.Loaded">
<BeginStoryboard Storyboard="{StaticResource anim}"/>
</EventTrigger>
</Grid.Triggers>
<Rectangle x:Name="rect" Width="300" Height="100">
<Rectangle.Fill>
<ImageBrush>
<noesis:Brush.Shader>
<local:NoiseBrush x:Name="fx" ScaleX="300" ScaleY="100" Time="0" Seed="100" Color="Red"/>
</noesis:Brush.Shader>
</ImageBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
- burst2flame
- Posts: 26
- Joined:
Re: Dependency Properties of Shader Effect won't animate
The only difference I see from my code to the samples is that I'm making an Effect and not a BrushShader. I tried different effects and it seems like Noesis.Effect properties just aren't animated. Can you confirm that you can animate a custom effect property?
Here's what I've seen in my tests
DropShadowEffect -> Can be animated
VideoEffect.TintEffect(In Video Effects Sample) - Can't be animated
LerpEffect(In my code) - Can't be animated
The DropShadowEffect code is very different in regards to it's properties, does something similar need to be done? Or is it just impossible?
Here's what I've seen in my tests
DropShadowEffect -> Can be animated
VideoEffect.TintEffect(In Video Effects Sample) - Can't be animated
LerpEffect(In my code) - Can't be animated
The DropShadowEffect code is very different in regards to it's properties, does something similar need to be done? Or is it just impossible?
Code: Select all
//------------------------------------------------------------------------------
// <auto-generated />
//
// This file was automatically generated by SWIG (http://www.swig.org).
// Version 3.0.10
//
// Do not make changes to this file unless you know what you are doing--modify
// the SWIG interface file instead.
//------------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
namespace Noesis
{
public class DropShadowEffect : Effect {
internal new static DropShadowEffect CreateProxy(IntPtr cPtr, bool cMemoryOwn) {
return new DropShadowEffect(cPtr, cMemoryOwn);
}
internal DropShadowEffect(IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) {
}
internal static HandleRef getCPtr(DropShadowEffect obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
public DropShadowEffect() {
}
protected override IntPtr CreateCPtr(Type type, out bool registerExtend) {
registerExtend = false;
return NoesisGUI_PINVOKE.new_DropShadowEffect();
}
public static DependencyProperty BlurRadiusProperty {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.DropShadowEffect_BlurRadiusProperty_get();
return (DependencyProperty)Noesis.Extend.GetProxy(cPtr, false);
}
}
public static DependencyProperty ColorProperty {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.DropShadowEffect_ColorProperty_get();
return (DependencyProperty)Noesis.Extend.GetProxy(cPtr, false);
}
}
public static DependencyProperty DirectionProperty {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.DropShadowEffect_DirectionProperty_get();
return (DependencyProperty)Noesis.Extend.GetProxy(cPtr, false);
}
}
public static DependencyProperty OpacityProperty {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.DropShadowEffect_OpacityProperty_get();
return (DependencyProperty)Noesis.Extend.GetProxy(cPtr, false);
}
}
public static DependencyProperty ShadowDepthProperty {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.DropShadowEffect_ShadowDepthProperty_get();
return (DependencyProperty)Noesis.Extend.GetProxy(cPtr, false);
}
}
public float BlurRadius {
set {
NoesisGUI_PINVOKE.DropShadowEffect_BlurRadius_set(swigCPtr, value);
}
get {
float ret = NoesisGUI_PINVOKE.DropShadowEffect_BlurRadius_get(swigCPtr);
return ret;
}
}
public Color Color {
set {
NoesisGUI_PINVOKE.DropShadowEffect_Color_set(swigCPtr, ref value);
}
get {
IntPtr ret = NoesisGUI_PINVOKE.DropShadowEffect_Color_get(swigCPtr);
if (ret != IntPtr.Zero) {
return Marshal.PtrToStructure<Color>(ret);
}
else {
return new Color();
}
}
}
public float Direction {
set {
NoesisGUI_PINVOKE.DropShadowEffect_Direction_set(swigCPtr, value);
}
get {
float ret = NoesisGUI_PINVOKE.DropShadowEffect_Direction_get(swigCPtr);
return ret;
}
}
public float Opacity {
set {
NoesisGUI_PINVOKE.DropShadowEffect_Opacity_set(swigCPtr, value);
}
get {
float ret = NoesisGUI_PINVOKE.DropShadowEffect_Opacity_get(swigCPtr);
return ret;
}
}
public float ShadowDepth {
set {
NoesisGUI_PINVOKE.DropShadowEffect_ShadowDepth_set(swigCPtr, value);
}
get {
float ret = NoesisGUI_PINVOKE.DropShadowEffect_ShadowDepth_get(swigCPtr);
return ret;
}
}
}
}
-
sfernandez
Site Admin
- Posts: 3139
- Joined:
Re: Dependency Properties of Shader Effect won't animate
Hmmm... VideoEffect sample is also animating the custom effect properties, and I just tried with a simpler xaml (see below) and it works as expected:
Can you try with that xaml and confirm if it is animating correctly in your case?
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
xmlns:local="clr-namespace:VideoEffect">
<Grid.Resources>
<Storyboard x:Key="anim">
<ColorAnimation Duration="0:0:5" Storyboard.TargetName="fx" Storyboard.TargetProperty="Color" To="Cyan" AutoReverse="True" RepeatBehavior="Forever"/>
</Storyboard>
</Grid.Resources>
<Grid.Triggers>
<EventTrigger RoutedEvent="Grid.Loaded">
<BeginStoryboard Storyboard="{StaticResource anim}"/>
</EventTrigger>
</Grid.Triggers>
<Rectangle x:Name="rect" Width="300" Height="100">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Offset="0" Color="Red"/>
<GradientStop Offset="0.5" Color="Yellow"/>
<GradientStop Offset="1" Color="Turquoise"/>
</LinearGradientBrush>
</Rectangle.Fill>
<Rectangle.Effect>
<local:TintEffect x:Name="fx" Color="Orange"/>
</Rectangle.Effect>
</Rectangle>
</Grid>
Who is online
Users browsing this forum: Google [Bot] and 3 guests