I've been struggling to add a background to my THREE scene, but I can't seem to get it right. Despite following the suggestions mentioned here and here, I still haven't had any luck.
Here are the lines of code I inserted into my rather complex script:
// Load the background texture
var loader = new THREE.TextureLoader();
var texture = loader.load( 'textures/stars_texture2956.jpg' );
var backgroundMesh = new THREE.Mesh(
new THREE.PlaneGeometry(2, 2, 0),
new THREE.MeshBasicMaterial({
map: texture
}));
backgroundMesh.material.depthTest = false;
backgroundMesh.material.depthWrite = false;
// Create your background scene
backgroundScene = new THREE.Scene();
backgroundCamera = new THREE.Camera();
backgroundScene.add(backgroundCamera );
backgroundScene.add(backgroundMesh );
and the render
function is as follows:
function render() {
renderer.render(backgroundScene, backgroundCamera);
renderer.render(scene, camera );
}
Despite all this, I still do not see the background (it remains white), although everything else functions as expected. Is there a solution to this issue?