How to ensure the background texture joins up smoothly around sphere in Three.js?

39 Views Asked by At

Image showing a visible line where the texture meets

Below is the bit of the code which sets the texture and maps it onto a large sphere. I have tried all sorts of wrapping but the background is still not smooth as there is a clear joining where the two parts of the texture meets. How do I fix this? Is there a way to overlap the edges maybe?

var milkyWayTexture = loader.load('https://cdn.pixabay.com/photo/2016/11/21/12/30/milky-way-1845068_1280.jpg');

 milkyWayTexture.minFilter = THREE.LinearFilter; 
        milkyWayTexture.magFilter = THREE.LinearFilter; 

        milkyWayTexture.wrapS = THREE.RepeatWrapping;
        milkyWayTexture.wrapT = THREE.RepeatWrapping;

        // Create a large sphere mesh for the starry background
        var backgroundGeometry = new THREE.SphereGeometry(900, 100, 100);
        backgroundGeometry.scale(-1, 1, 1); // Flip the geometry to invert the texture mapping

        var backgroundMaterial = new THREE.MeshBasicMaterial({
            side: THREE.DoubleSide, // Make the sphere visible from inside as well as outside
            map: milkyWayTexture // Add Milky Way texture
        });

        var backgroundMesh = new THREE.Mesh(backgroundGeometry, backgroundMaterial);
       
        scene.add(backgroundMesh);
1

There are 1 best solutions below

0
Nephelococcygia On

You need to understand the concept of UV mapping. It defines how your texture will be projected on a 3D object.

Usually, on a sphere, if you simplify the concept to its core, it consists of a plane rotate in X and Y, to wrap on a sphere. UV mapping

With the illustration you might have guess the solution:

Alternatively, to set an environment I think it's a better practice to use scene.background (source) with a EquirectangularReflectionMapping texture from an HDR file (can be found here).