MarcOlmos Posted October 2, 2023 Share Posted October 2, 2023 Hi, I would like to know if it is possible to force all GSAP animations to run with GPU, even if the animations aren't 3D. Thanks. Link to comment Share on other sites More sharing options...
mvaneijgen Posted October 2, 2023 Share Posted October 2, 2023 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 More sharing options...
MarcOlmos Posted October 2, 2023 Author Share Posted October 2, 2023 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. Thanks. Link to comment Share on other sites More sharing options...
GSAP Helper Posted October 2, 2023 Share Posted October 2, 2023 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: React (please read this article!) Next Svelte Sveltekit Vue Nuxt 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 More sharing options...
MarcOlmos Posted October 2, 2023 Author Share Posted October 2, 2023 I have cloned the example: https://stackblitz.com/edit/stackblitz-starters-vg5rkj?file=src%2Fglobal_styles.css,src%2Fmain.ts,src%2Findex.html Link to comment Share on other sites More sharing options...
Rodrigo Posted October 2, 2023 Share Posted October 2, 2023 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: 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now