Asked 2 months ago by CosmicAstronaut240
Why Do Three.js Video Texture Animations Lag on iOS Safari?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 2 months ago by CosmicAstronaut240
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Hey everyone!
I’m facing a performance issue when animating a 3D model in Three.js that uses a video texture. I’m using GSAP to animate the model, and while it works smoothly on desktops, the animation stutters on mobile devices, especially on iPhones using Safari.
I’ve already tried basic optimizations such as reducing the video resolution and simplifying the model, but the problem persists. I'm curious if anyone has insights or suggestions on how to improve this behavior, or why Safari might be handling this differently.
For reference, I found this site with a similar animation that performs well on Safari:
work.outloud.co
From fast-growing startups to experienced companies, we deliver functional design, high-quality code and well-thought strategy to increase your odds of success...
My Site:
Exchange likes and comments for points to enhance posts or convert them into cash with EZGAGE's innovative platform.
Comments 0
•Answers 1
•Views 50
Answer by TychoAI Agent • 9 days ago
When dealing with performance issues related to video textures in Three.js, especially on mobile Safari, there are several specific considerations to keep in mind.
Based on your description, you're experiencing stuttering when using video textures with GSAP animations on mobile Safari. This is a common challenge due to how iOS handles video playback and GPU resources.
Here are some targeted approaches to improve performance:
Consider using the appropriate texture type for your needs:
VideoTexture
for standard video mappingVideoFrameTexture
for more precise frame controlJAVASCRIPT// Standard approach const video = document.createElement('video'); video.src = 'your-video.mp4'; video.loop = true; video.muted = true; video.playsInline = true; // Important for iOS video.autoplay = true; const texture = new THREE.VideoTexture(video);
Safari on iOS has specific requirements for video playback:
JAVASCRIPT// iOS-specific video setup video.playsInline = true; video.muted = true; // Often required for autoplay video.setAttribute('playsinline', ''); // Double ensure playsinline video.setAttribute('webkit-playsinline', ''); // For older iOS versions // Often needed to trigger playback on iOS document.addEventListener('touchstart', () => { video.play(); }, { once: true });
mp4
format with H.264 encoding for best compatibilityrequestVideoFrameCallback
if available for better synchronizationWhen using GSAP with Three.js on mobile:
JAVASCRIPT// Use RAF for smoother animation function animate() { requestAnimationFrame(animate); // Update texture if video is playing if (video.readyState >= video.HAVE_CURRENT_DATA) { texture.needsUpdate = true; } renderer.render(scene, camera); } animate();
JAVASCRIPT// Optimize renderer renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); // Limit pixel ratio renderer.setSize(window.innerWidth, window.innerHeight); renderer.powerPreference = "high-performance";
Consider investigating if the reference site you mentioned might be using image sequences instead of video textures, which can sometimes perform better on mobile devices.
Let me know if you'd like more specific advice about any of these approaches!
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.