Three.js - Black skybox display

Having trouble adding a skybox to a simple scene in Three.js!

This is the code I'm using for the skybox:

var skyBox = new THREE.Mesh( new THREE.BoxGeometry( 1500, 1500, 1500 ), shaderMaterial );
sceneCube.add( skyBox );

The shaderMaterial is defined as follows:

shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;

var shaderMaterial = new THREE.ShaderMaterial( {

    fragmentShader: shader.fragmentShader,
    vertexShader: shader.vertexShader,
    uniforms: shader.uniforms,
    depthWrite: false,
    side: THREE.BackSide

} );

I simply want to display some simple images as a Skybox, so I load the images using this code:

var path = "Desert-";
var format = '.png';
var urls = [
    path + 'LEFT' + format, path + 'RIGHT' + format,
    path + 'TOP' + format, path + 'BOT' + format,
    path + 'FRONT' + format, path + 'BACK' + format
];
textureCube = new THREE.CubeTextureLoader().load( urls );

When I run the code, there are no errors in the web-console. I'm using a basic scene from .

I've searched online for solutions but can't seem to find where I'm going wrong.

Thank you for your assistance!

Here is the full code I am using:

<script>

var camera, scene, renderer, cameraCube, sceneCube;
var mesh, shader;

init();
animate();

function init() {

camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.z = 400;
cameraCube = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );

scene = new THREE.Scene();
sceneCube = new THREE.Scene();

var path = "textures/Desert-";
var format = '.png';
var urls = [
    path + 'LEFT' + format, path + 'RIGHT' + format,
    path + 'TOP' + format, path + 'BOTTOM' + format,
    path + 'FRONT' + format, path + 'BACK' + format
];
console.log(urls);
textureCube = new THREE.CubeTextureLoader().load( urls );

// Skybox

shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;

var shaderMaterial = new THREE.ShaderMaterial( {
    fragmentShader: shader.fragmentShader,
    vertexShader: shader.vertexShader,
    uniforms: shader.uniforms,
    depthWrite: false,
    side: THREE.BackSide
} );

var skyBox = new THREE.Mesh( new THREE.BoxGeometry( 1500, 1500, 1500 ), shaderMaterial );
sceneCube.add( skyBox );

var texture = new THREE.TextureLoader().load( urls[3] );

var geometry = new THREE.BoxBufferGeometry( 100, 100, 100 );
var material = new THREE.MeshBasicMaterial( { map: texture } );

mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );

renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

window.addEventListener( 'resize', onWindowResize, false );

}

function onWindowResize() {

camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();

renderer.setSize( window.innerWidth, window.innerHeight );

}

function animate() {

requestAnimationFrame( animate );

mesh.rotation.x += 0.005;
mesh.rotation.y += 0.01;

renderer.render( sceneCube, cameraCube );
renderer.render( scene, camera );

}

Answer №1

In case you are executing various render passes like the following:

renderer.render( sceneCube, cameraCube );
renderer.render( scene, camera );

you should make sure to specify

renderer.autoClear = false;

in order to avoid the second rendering pass from clearing the initial one.

This applies to version three.js r.76 and above.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble utilizing a JavaScript file within TypeScript

I am currently exploring the integration of Three.js into an Angular application. Following the documentation, I imported Three.js using the following line: import * as THREE from 'three'; In addition, I installed the types for Three.js with th ...

Angular filter function encounters an issue if the value being filtered is null

Currently facing an issue while filtering an array. Whenever the filtered field is null, it triggers an error causing the rest of the code to fail. This is how my code looks like: this.order= result.headerText.find((item) => item.textType === 'Orde ...

Navigating back to the previous page while retaining modifications using AngularJS

When I use the products table to conduct an advanced search, view details of a specific item and then click on the cancel button to return to the list, all my research inputs are reset... Is there a way for me to go back to where I was before? Can I retri ...

Add slides in PowerPoint before or after the currently selected slide to enhance your presentation flow

I'm currently working on a function that pulls data from an API to convert PowerPoint presentations into base64 strings. Once I receive the response object, my goal is to seamlessly insert the slides into the existing presentation, exactly after the s ...

Unable to generate a JSON string from the JavaScript object

I need help converting the object I receive from the server into a JSON file for use in a d3.js chart: data = { "dog ":"5", "cat ":"4", "fish ":"12", } The desired output is: { "name" : "animal", "children" : [ {"name":"dog" ...

Automatically Populate Custom Body Fields in NetSuite Using Line Item Data

As a newcomer to NetSuite scripting, I am working on populating 3 custom body fields within an Item Fulfillment form. The fields I need to populate are Line Item Name, Line Item Class, and Line Item Count (which represents the total count of line items in ...

Reducing div size when clicked - Using JQuery version 1.9

I am looking to make a specific div shrink in size, while keeping all the data visible, each time a user clicks on a certain icon with the class legend-icon. For example, I want the div with the ID #Chart to shrink when clicked. This is the HTML code: &l ...

working with Selenium in the Chrome web browser

Within a file named e2e.js, the following code was written: const webdriver = require('selenium-webdriver'); const driver = new webdriver.Builder().forBrowser('chrome').build(); driver.get('https://www.google.co.il/'); I h ...

Font rendering issue in Chrome extension

I have been diligently following various tutorials on incorporating a webfont into my Chrome extension, but unfortunately, none of them seem to be working for me. Despite all my efforts, the font remains unchanged and still appears as the default ugly font ...

Manipulate a value using JavaScript

While the intention is for the button value to switch between 1 and 0, the echo $_POST["ordina"] consistently returns 1. Despite checking the code multiple times, I am unable to identify the issue. <script> function order() { if (document.ordination ...

Tips for mocking constructors in AngularJS, specifically the Date() constructor

Trying to verify a function which receives millisSinceEpoch and gives back the time if it is today's date, otherwise it gives the date. getLocaleAbbreviatedDatetimeString: function(millisSinceEpoch) { var date = new Date(millisSinceEpoch); if (d ...

How can I disable the automatic generation of index paths from embedded documents in mongoose?

It appears that mongoose is automatically generating indexes for embedded documents. Is there a setting to disable the automatic index creation feature? For instance, the code snippet https://github.com/Automattic/mongoose/blob/master/lib/schema.js#L940 s ...

Determining if an emitted event value has been altered in Angular 4

I am currently working on an Angular 4 project. One of the features I have implemented is a search component, where users can input a string. Upon submission of the value, I send this value from the SearchComponent to the DisplayComponent. The process of ...

Hide the form field upon button click

I currently have a form with 6 input fields all under the same id entry1. Whenever I click the Add Section button, these fields are cloned and added to the form. There is also a button for removing the section above. The issue arises when I click on the R ...

Receiving the outcome of an asynchronous function in JavaScript

async function retrieveKey() { try { var key = await dec.awsDecrypt('dev-frontend') return key; } catch(err) { } } //calling the function const result = retrieveKey() In the code snippet above, there is an asynchronous ...

The .val() and focus() methods are not functioning correctly

I am having an issue with a simple script: when I input a link to an image in the form's INPUT field, it should automatically display a preview of the image: https://example.com/image.jpg However, when I input the same link not by using ctrl+C/ctr ...

Trigger a function in JavaScript by clicking on an element and passing its class

I have written the following code: <?php $extCount = 0; foreach($this->externalReferal as $externalReferal) { $extCount++; ?> <div class='fieldtestPct' > <div class='fieldItemLabel'> < ...

Issue encountered when trying to test a slider element using TestCafe

Could someone please help me with writing a test for a slider element in this situation? <Slider defaultValue={pickupValue.length ? pickupValue : [15, 15]} aria-labelledby="range-slider" ...

Issue with React tabulator ref being null after re-rendering

Utilizing Tabulator within React by employing the react-tabulator module has been a part of my development process. Now, I rely on 'ref' for the table component to execute actions such as downloading data or any other relevant activity. import R ...

What is the best way to pass a parameter dynamically in the get method?

When looking at the network tab, I realized that I sent the query '' Unfortunately, it didn't work as expected. How do I adjust the query to have the order like this: Should the 'q' parameter come after the search? getArtists(q ...