Jump to content
Search Community

Forcing GSAP to run with GPU not with CPU

MarcOlmos test
Moderator Tag

Recommended Posts

Quote

  • force3D - GSAP automatically attempts to maximize rendering performance by applying transforms with 3D components like translate3d() instead of translate() during The animation to activate GPU acceleration, and then switches back to the 2D variant at the end (if possible) to conserve GPU memory. That describes  force3D:"auto" behavior (the default). Setting force3D: falsedisables the behavior. Setting force3D: true will force all transform-related tweens to use the 3D component and NOT switch back to 2D at the end of the tween.

https://greensock.com/docs/v3/GSAP/gsap.config() Hope it helps and happy tweening! 

Link to comment
Share on other sites

Firstly, thank you for answering me.

 

I am using force3D: true on gsap.config() for Angular.

 

I am also applying "rotationY" property to try to force GPU rendering.

 

import { Component, OnInit } from '@angular/core';
import { gsap } from 'gsap';

gsap.config({
  force3D: true
})

@Component({
  selector: 'app-tabs',
  templateUrl: './tabs.component.html',
  styleUrls: ['./tabs.component.scss']
})
export class TabsComponent implements OnInit {
  ngOnInit(): void {
  }

  activateSwitchOnClick(
    partSelected: string,
    otherPart: string
  ) {
    const tl6 = gsap.timeline();
    tl6.to(`.${partSelected}`, {
      duration: 0.5,
      width: 'calc(80% - 10px)',
      backgroundColor: '#FFFFFF',
      pointerEvents: 'none',
      rotationY: 500
    }).to(`.${otherPart}`, {
      duration: 0.5,
      width: 'calc(20% - 10px)',
      backgroundColor: '#0C71C3'
    }, '-=0.5')
      .to(`.${partSelected} .extra-info`, {
        duration: 0.5,
        width: '40%'
      }, '-=0.5')
      .to(`.${otherPart} .extra-info`, {
        duration: 0.5,
        width: '0px'
      }, '-=1')
      .to(`.${otherPart} .extra-info .info-text`, {
        duration: 0.5,
        opacity: 0
      }, '-=1.5')
      .fromTo(`.${partSelected} .extra-info .i1`, {opacity: 0, y: 10}, {opacity: 1, y: 0, duration: 0.3}, '-=0')
      .fromTo(`.${partSelected} .extra-info .i2`, {opacity: 0, y: 10}, {opacity: 1, y: 0, duration: 0.3}, '-=0')
      .fromTo(`.${partSelected} .extra-info .i3`, {opacity: 0, y: 10}, {opacity: 1, y: 0, duration: 0.3}, '-=0')
      .to(`.${otherPart}`, {
        duration: '-=2',
        pointerEvents: 'all'
      })
  }

}

 

But I can´t see any change on the GPU.
 

image.png.bb3a1a2c3369d243fe3e0d15d6d05774.png

Thanks.

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or Stackblitz that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

Hi,

 

A few things to notice. I'm not super experienced with Chrome Task Manager (I used it mostly to kill a tab that gets stuck) so IDK how reliable it is.

 

GSAP is actually doing what is supposed to do, if you inspect the DOM elements being animated, you'll see that there are 3D transforms applied to them and you'll see the transform matrix being updated as the animation progresses. That creates a new GPU Layer which improves performance.

 

Finally if you check the performance tab in dev tools you will see the CPU being used after the click event is triggered:

m7tq486.png

 

In the image you can see the pointer event (click) then below that a bunch of colored lines, those indicate all the JS methods being called. Below that you'll see green lines, those are the moments when the GPU chips in because GSAP is using 3D transforms to create the animation.

 

As you can see the GPU is actually kicking in when is required but, most likely, since your animations are quite simple the processing time required is really small (as shown in the image) so maybe the Chrome task manager doesn't register, perhaps due to the refresh rate it has.

 

Happy Tweening!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...