Objects beyond a distance of 1 unit start to vanish when employing ArrayCamera

After implementing an ArrayCamera to wrap my PerspectiveCamera, I noticed that objects located more than 1 unit away from the origin point (0,0,0) appear to vanish in the render.

var camera = new THREE.PerspectiveCamera();
camera.viewport = new THREE.Vector4(0, 0, canvas.width, canvas.height);
camera.position.set(0, 10, 40)
arrayCamera.cameras.push(camera);
scene.add(camera);

Check out this video showcasing the rendering using a PerspectiveCamera

And here's how it looks with the ArrayCamera wrapping the PerspectiveCamera

Answer №1

When utilizing ArrayCamera, it is crucial to handle view frustum culling in a unique manner.

Typically, view frustum culling is employed to eliminate objects from rendering if they fall outside of the camera's view frustum. The frustum is generated from the camera's projection and view matrix. When working with ArrayCamera as demonstrated in your code snippet, both matrices are not correctly configured, leading to erroneous view frustum culling that impacts your scene negatively. To address this dilemma, there are two suggested solutions:

  • Deactivate view frustum culling for your objects by setting Object3D.frustumCulled to false.
  • Create a 3D transformation and projection matrix specifically for your instance of ArrayCamera. This has been implemented in the live example given below:

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);

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

var geometry = new THREE.BoxGeometry();
var material = new THREE.MeshBasicMaterial({
  color: 0x00ff00
});
var cube = new THREE.Mesh(geometry, material);
//cube.frustumCulled = false; // SOLUTION 
scene.add(cube);

camera.position.z = 10;
camera.updateMatrixWorld();
camera.viewport = new THREE.Vector4(0, 0, window.innerWidth, window.innerHeight);

var arraycamera = new THREE.ArrayCamera();
arraycamera.cameras.push(camera);
arraycamera.position.copy( camera.position ); // SOLUTION 
arraycamera.projectionMatrix.copy( camera.projectionMatrix ); // SOLUTION 

var animate = function() {
  requestAnimationFrame(animate);

  if (cube.position.x > 5)
    cube.position.x = -1;
  else cube.position.x += 0.1;

  renderer.render(scene, arraycamera);
};

animate();
body {
  margin: 0;
}

canvas {
  display: block;
}
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2741475d4a4adb6e413341343941">[email protected]</a>/build/three.js"></script>

As evident, I have simply transferred the values from your current camera settings. Especially in VR scenarios (where ArrayCamera finds its primary use), combining projection matrices becomes essential to create a unified frustum covering both eyes.

The fundamental concept revolves around performing view frustum culling just once when employing ArrayCamera (due to multiple renderings within one render pass).

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

Utilize ng-repeat to display a series of images, with the first image being placed within a unique div

My challenge lies in displaying product images using ng-repeat, where one image is located in a separate div. Let me share my code and explain what is happening. The API response provides product details and images [{"id_product":"1000","name":"Nikolaus ...

In client.js, learn how to retrieve the value of an input tag (Name) from a login form

Let me explain the situation at hand: I'm currently in the process of developing a chat application using socket.io and NodeJS (Express). Initially, I had a simple prompt that asked for the user's name, easily accessible through const name = pro ...

Utilizing jQuery AJAX to Send an HTML Array to PHP

In my current HTML forms and jQuery AJAX workflow within the Codeigniter Framework, I've encountered a common issue that has yet to be resolved to suit my specific requirements. Here's the situation: HTML - The form includes an array named addre ...

Execute a function and simultaneously input data into MySQL using Node JS

Is there a way to simultaneously insert data from multiple external data sources into a database? I have several APIs/Endpoints that provide the same dataset, and I want to insert them all at once. For instance: Right now, my code loops through each API ...

JavaScript salary calculation function not functioning properly

Once the user inputs the employee's name and the number of hours they worked on the HTML form, the submit button captures this information and stores it in variables for calculating their pay. The script also factors in overtime pay. Despite feeling l ...

Create a variable to store the sum value when iterating through a range using jQuery's

Currently, I am in the process of developing a specialized calculator that requires me to calculate the sum of variables within my jQuery.each loop for a specific range from 0 to 4 (equivalent to 5 years). While I have come across several informative reso ...

Moving the panel to follow the mouse cursor in Firefox Add-on SDK

Is there a way to show a panel on the screen at the exact position of the mouse? I'm finding it difficult to understand how to change the position of the panel in Firefox SDK, as the documentation lacks detailed information. ...

Overriding the w-4xl with sm:text-2xl in Tailwind CSS

Struggling to achieve responsive design on my Pages, especially with changing text size when the screen is small. I've been following all the correct steps and maintaining the right order. However, whenever I set 'sm', it seems to override a ...

the webpage is not displaying the style sheet properly

I have set up a local instance of nodejs and am currently running a web service that references a local index.html file upon startup. This web service is operating on my desktop. After experimenting with CSS, I've encountered an issue where the style ...

Step-by-step guide on utilizing the material-ui AutoComplete feature to filter a table by selecting a key from a list and manually entering

I'm working on developing a filtering system similar to the AWS Dashboard, where users can select a filter key like instance state, which then displays the key in the input field and allows the user to enter a value to search for. I'm attempting ...

How can you limit access to certain routes in Nuxt.js to only clients who possess a valid JWT token?

In Nuxt.js, implementing authentication can be done in the following steps: The client authenticates by sending its credentials in an HTTP request to a specific API route in the Nuxt backend; The Nuxt backend responds with a JWT token for accessing protec ...

Modifying data attribute values with jQuery

Hello there, I have a question regarding the following HTML element: <li class="total_payment" data-basetotal="0.00"> <span> <h5>Total</h5> </span> </li> I am trying to update the data-basetotal value f ...

Issue arises while utilizing the echoed ++$value in javascript within a webpage containing an HTML5 audio player

I've been developing a customized 'soundboard' that generates a unique HTML5 audio player for each mp3 file found in a directory. While the player setup is functioning as expected, I encountered challenges when incorporating a customized tim ...

Learn how to continuously update the current timestamp in PHP using jQuery or JavaScript every second

I am currently developing a PHP cart timer script that utilizes PHP along with jQuery and JavaScript. By using the set-interval function, I am able to continuously retrieve the current time-stamp in PHP. Once the first product is added to the cart, the t ...

What is the process for transferring a JSON data object to the server with JavaScript XMLHttpRequest?

When I attempt to send an XMLHttpRequest to a PHP server, I am encountering difficulties in getting the $_POST or $_REQUEST object to be filled with the data I am sending using JavaScript: var r = new XMLHttpRequest; r.open("POST", "http://url.com", true ...

Increasing a value in Mongo DB with a conditional statement in a Meteor application

This seemingly simple issue has been causing me some trouble. With the code provided below, I am able to increase or decrease the number of likes on my posts by 1. I am looking to achieve the following: If postLikes = 0, then prevent further reduction o ...

How to activate a window that's been minimized in Chrome

I am experiencing an issue with a button that is supposed to open a new window as a popup below the parent page. It works correctly in IE and Firefox, but in Chrome, the popup appears on top of the parent window. Can someone please provide a solution? Fo ...

Transferring Information between a Pair of Controllers

Currently, I am utilizing angular version 1.x and faced with the challenge of sharing data between two controllers. In my mainctrl, I am working with the above model. The radiotmplt.radiohead=='IRU600v3' is utilized in firstctrl. Unfortunately, ...

What are the steps to effectively utilize the static folder in Django for organizing CSS and JavaScript files?

I'm completely new to the Django framework. I managed to create a simple welcome page, but now I'm struggling to include a CSS file in my project. Whenever I try to apply the CSS file, I encounter an error saying "NetworkError: 404 NOT FOUND - / ...

Utilizing jQuery to Bind AJAX Events without a DOM Element

The documentation for jQuery AJAX Events provides examples that all involve using a jQuery DOM Element to declare a binding, like so: $('.log').ajaxSend( hander ); I am interested in capturing jQuery AJAX Events without the need for a DOM Eleme ...