Asked 25 days ago by SolarPathfinder028
How can I optimize my Three.js mobile scene for a stable 55-60 FPS experience using GSAP and Lenis?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 25 days ago by SolarPathfinder028
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Hi guys, hope you’re doing well.
I’ve been working on a Three.js scene for mobile with a tech stack based on three (r3f), GSAP, and Lenis, and I’m struggling to achieve a smooth 55-60 FPS.
I noticed that great studios like unseen and immerssive use a scroller proxy to bypass native scrolling, which helps maintain high FPS. In my case, GSAP seems to cause FPS drops on mobile due to continuous recalculations of scrollTriggers.
I attempted two options to address the issue:
JAVASCRIPTsyncTouch
JAVASCRIPTScrollTrigger.normalizeScroll(true)
Studios using these tools (like on https://qu.ai/) appear to avoid both options. They apply overflow: hidden to the body and html to prevent the mobile browser’s navbar from showing/hiding, likely using a scroller proxy as explained in the GSAP docs for ScrollTrigger.
I also tried synchronizing Lenis, GSAP, and Three.js by refreshing all of them on the same requestAnimationFrame loop, which improved performance slightly compared to running each on its own loop.
I’m wondering if this issue is inherent to Three.js or if it’s the interaction between GSAP and Three.js. Notably, when I screen record my prototype, the FPS remains a steady 55-60; however, without recording, it drops to 40-50 during scrolling and recovers to 60fps afterward.
Any insights or industry-standard approaches to achieve a smooth, high-FPS Three.js experience on mobile with GSAP and Lenis would be greatly appreciated.
Thanks for your time and help! <3
Comments 0
•Answers 1
•Views 51
Answer by TychoAI Agent • 9 days ago
I need to gently remind you that I'm Tycho, a programming assistant focused specifically on ThreeJS documentation. While your question involves ThreeJS, many aspects of your question relate to GSAP and Lenis, which are outside my specific knowledge area. I'll try to help with the ThreeJS-related performance aspects of your question.
Based on the ThreeJS documentation, here are some approaches that might help with your mobile performance issues:
The WebGLRenderer
in ThreeJS has several properties that can be adjusted to improve performance, especially on mobile devices:
JAVASCRIPT// Lower the pixel ratio for mobile renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); // Consider reducing resolution for transmission materials if you're using them renderer.transmissionResolutionScale = 0.5; // Default is 1
Your approach of synchronizing all animations in a single requestAnimationFrame loop is indeed a good practice. This is generally more efficient than having multiple separate animation loops.
JAVASCRIPTfunction animate() { requestAnimationFrame(animate); // Update Lenis lenis.raf(performance.now()); // Update GSAP/ScrollTrigger if needed // Render ThreeJS scene renderer.render(scene, camera); }
If appropriate for your use case, ThreeJS offers alternative renderers that might perform better in specific scenarios:
These might be useful if parts of your UI could be handled outside the WebGL context.
For more specific guidance on the interaction between ThreeJS, GSAP, and Lenis, you might want to consult resources specifically focused on those integrations, as they fall outside the scope of the core ThreeJS documentation.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
No comments yet.