0

I have C# + WPF application. I created animations that move element from one point to another. I have a hotkey that calls a method> The method start animation Animations on my PC works perfectly(I have very powerful PC) but if another user with decent PC use my application animations has some lags or freezes. It looks like it has low sample rate

So, the problem is animations works bad on other PC

I noticed that if I run my application and task manager I see that GPU load is consuming, when I run a method with animation begin GPU load is increasing and can be up to 15% everytime when I click on hotkey with a animation method.

Current Result: animation works bad, some lags

Expected Result: animation works fine and smoothly

How to make animation work good on all machines?

My PC:

Others PC

 public class HotKeys
{

DoubleAnimation animShowCard = new DoubleAnimation(100, TimeSpan.FromMilliseconds(250));
DoubleAnimation animShowCardOffset = new DoubleAnimation(0, TimeSpan.FromMilliseconds(150));


 public HotKeys(MainWindow _window)
    {
        SineEase sineEase = new SineEase();
        sineEase.EasingMode = EasingMode.EaseOut;
        animShowCard.EasingFunction = sineEase;
        animShowCardOffset.EasingFunction = sineEase;

         animShowCard.Completed += (s, e) =>
        {
          window.cardQuestionBorder.RenderTransform = new TranslateTransform(100, 0);
          window.cardQuestionBorder.RenderTransform.BeginAnimation(TranslateTransform.XProperty, animShowCardOffset);            

        };
    }

     //call a method with animation when D1 hotkey is clicked
         if (e.Key == Key.D1)
         {
            e.Handled = true;  
              ShowCard();
          }

     //method that show animation
      private void ShowCard()
    {
        window.cardQuestionBorder.RenderTransform = new TranslateTransform(-1600, 0);
        window.cardQuestionBorder.RenderTransform.BeginAnimation(TranslateTransform.XProperty, animShowCard);
    }
}

I tried to change SampleRate of animation(60 frames is default value I think) to 25 or less but it go worse even on my PC:

Timeline.SetDesiredFrameRate(animShowCard, 25);

EDIT:

I recorded my application working on other PC, It consumes GPU load up to 45%

Users PC Video

EDIT 2:

I found the root problem. It was shadow effect of a card. I used it in xaml. When I removed this thing animation has been working smooth and very good

<Border.Effect>
                    <DropShadowEffect Color="Black"
                                      Direction="320"
                                      BlurRadius="60"
                                      ShadowDepth="40"
                                      Opacity="0.8" />
                </Border.Effect>

Is there any way to fix it? Can I use another shadow type? How can I use it in code behind?

kenny
  • 91
  • 1
  • 1
  • 4
  • Please format your code with a proper indentation – Sir Rufo Feb 16 '20 at 13:17
  • Can you benchmark your UI with alt+F2 in release and share results on the other machines? You might have something else happening on your UI thread slowing down your animation. Also: what are the hardware (you PC and others) ? – Soleil Feb 16 '20 at 13:32
  • @Soleil I cannot benchmark my application on other machines because I should install IDE and all the libraries that are used in my application. my PC is Nvidia 1050 TI, Ryzen 7 and 32 gb memory. Users' PC is a decent PC that can handle common desktop applications like Adobe Premiere or Skype or Photoshop. User's PC are not too slow. – kenny Feb 16 '20 at 13:39
  • I think the problem is in animation itself. May be I created it in a wrong way? – kenny Feb 16 '20 at 13:39
  • Should I create some stuff in code that supports GPU acelleration? – kenny Feb 16 '20 at 13:41
  • Does not seems to me. Then benchmark (alt+F2) the app on your machine; select the right time range so you're considering the moment of the animation. – Soleil Feb 16 '20 at 14:12
  • @kenny your WPF program is already natively GPU accelelerated (if your GPU is DirectX compatible). – Soleil Feb 16 '20 at 14:13
  • @kenny Could you record GPU load on the user's machine? – TripleAccretion Feb 16 '20 at 15:36
  • @Artem K, how can I do that? Should I install additional software? DO you mean just record video of task manager, the tab with GPU load? – kenny Feb 16 '20 at 17:52
  • @kenny Sure, nothing fancy, TM is enough (for now). We just want to establish where the bottleneck is. Usually choppy animations == CPU is being used somewhere somehow, and we should see that reflected in low GPU utilization. If the opposite is true, you would have to get the machine (on which the bug is reproducible) and do proper profiling. – TripleAccretion Feb 16 '20 at 18:50
  • @kenny with the performance profiler (alt+F2) you'll be able to see CPU, GPU, memory usage in time and see the resources used by your program, esp. how much by the UI thread (and why it may slows down on other machines). https://learn.microsoft.com/en-us/visualstudio/profiling/profiling-feature-tour?view=vs-2019 – Soleil Feb 17 '20 at 12:49
  • @Artem K, I Edited my post and recorded a video how it works on other PC – kenny Feb 20 '20 at 03:14
  • 1
    @kenny Interesting. It seems that the problem is related to excessive GPU usage. I would guess that the cause is the shadow effect on the form (effects are usually resource hogs). [To get a better idea of what's exactly happening, you should try profiling render times in your application](https://stackoverflow.com/q/33468572/10857604). – TripleAccretion Feb 20 '20 at 11:28

1 Answers1

0

The problem was I used shadow effect on border. Border contains many elements like rectangle and text. Effect applies to all elements in border. That's why it reflects on GPU usage. I just applied shadow effect on inner element not on border and animation works good now

kenny
  • 91
  • 1
  • 1
  • 4