Exploring the world of lighting and shadows with Three.js

I have a question about the initialization and animation process. When making changes to elements like lights and shadows, I've noticed that using large values during initialization can cause a significant drop in frames per second at the start. So, I decided to test how setting values incrementally in each loop of the animation process would impact the performance. It seems like it doesn't make much of a difference as the program loops through all the elements in the scene continuously.

This got me thinking, is this method really better for setting up a scene?

What are your thoughts on this? Have you encountered any complex scenes that behave similarly, or do you know of any instances where values are updated differently during startup? I'm specifically referring to scenarios where we are not just rendering what is visible on the screen but everything in the entire scene.

I'm also interested in how you would approach this situation:

 var cam, light, d, rend; 
var ambLone = 0x444444, ambLoneI = 0.2, ambLtwo = 0x666666, ambLtwoI = 0.5, lC = 0xdfebff, lN = 2.75, lF = 1000, lightPx = 700, lightPy = 500, lightPz = 500, lightSCmin = 1, lightSCmax = 1000, lightSCF = 100, lightSCN = lightSCmin; 

in init(); ->

scenes.add( new THREE.AmbientLight( ambLone, ambLoneI ) ); 
scenes.add( new THREE.AmbientLight( ambLtwo, ambLtwoI ) ); 
light = new THREE.DirectionalLight( lC, lN, lF ); 
light.position.set( lightPx, lightPy, lightPz ); 
light.position.multiplyScalar( 1.3 ); 
light.castShadow = true; 
light.shadow.mapSize.width = 1024; 
light.shadow.mapSize.height = 1024; 
d = 1000; 
light.shadow.camera.left = - d; 
light.shadow.camera.right = d; 
light.shadow.camera.top = d; 
light.shadow.camera.bottom = - d; 
light.shadow.camera.far = lightSCF; 
light.shadow.camera.near = lightSCN; 
var helper = new THREE.CameraHelper( light.shadow.camera ); 
scenes.add( light, helper ); 

in animate(); ->

requestAnimationFrame( animate ); if (lightSCF === lightSCmax) { lightSCF = 1000; light.shadow.mapSize.width = 5120; light.shadow.mapSize.height = 5120; console.log( 'Light is set to: ' + lightSCF + light.shadow.mapSize.width); } else if(lightSCF < lightSCmax){ lightSCF = lightSCF + 1; light.shadow.mapSize.width = light.shadow.mapSize.width + 4.5; light.shadow.mapSize.height = light.shadow.mapSize.width + 4.5; light.shadow.camera.far = lightSCF; light.shadow.camera.updateProjectionMatrix(); console.log( 'Light is now: ' + lightSCF + ' ' + light.shadow.mapSize.width ); } else { console.log( 'whatever... '); } render(); 

Answer №1

It's possible that the issue you're experiencing is related to the unusual values you've set for the shadow.mapSize parameter. The documentation specifies that these values should be powers of 2, so it's worth verifying if your device supports large textures by checking

WebGLRenderer.capabilities.maxTextureSize
.

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

Measuring Load Time Percentage in AngularJS Using $http Requests

I am currently utilizing Angular with my Rails application. I have a sample app and I am interested in displaying the response time required to load a response in Angular. For example, When loading a response of an array containing 100,000 elements, I w ...

The PHP header() function is not properly redirecting the page, instead it is only displaying the HTML

After double checking that no client sided data was being sent beforehand and enabling error reporting, I am still encountering issues. The issue revolves around a basic login script with redirection upon validation. <?php include_once "database- ...

"Exploring the Power of Logarithmic Slider with Vue and Quasar

I'm currently working on a project utilizing Vue 2 and Quasar 1, where I am attempting to develop a logarithmic slider. Initially, I managed to create a basic example using a native input slider in this code pen: https://codepen.io/tonycarpenter/pen/Z ...

Accessing information from a JSON array

I am encountering difficulties in fetching data from a JSON file. Whenever I click the button, it triggers the call function which then retrieves data from the json.jsp file containing an array. However, I am unable to retrieve the data successfully. Below ...

Deciphering JSON data in an Express.js application

In a Node.js/Express.js application, an API call is made to another server which responds with JSON data. However, the received JSON response is not being properly parsed into new variables. What specific modifications should be applied to the code below i ...

Fetch the count of files in a directory using AJAX

I'm attempting to fetch the number of files in a folder and compare it with the maxfiles value. Within dropzone.js, there is a function that looks like this: Dropzone.prototype._updateMaxFilesReachedClass = function() { if ((this.options.maxF ...

Having trouble extracting the date modified from a JSON file

I am able to retrieve section name, URL, web title, and headline from parsing JSON data with this code snippet. However, I seem to be encountering an issue where I cannot extract the last modified date. Here is the JSON structure: { "response":{ ...

Caution: A non-boolean attribute received a value of `false`. What is the correct way to provide a boolean value?

I'm encountering an issue with the code below: react-dom.development.js:67 Warning: Received false for a non-boolean attribute high. If you want to write it to the DOM, pass a string instead: high="false" or high={value.toString()}. Despi ...

Tool to insert content into the initial subdirectory

My goal is to develop a bookmarklet that can add text after the main domain but before any subpath. For example: http://example.com/home/start -> http://example.com/text/home/start I am considering storing the full path, removing the domain, replacing ...

Differences between JSX and creating instances of component classes

Could someone please clarify the distinction between the following two statements? let instance1 = new CustomComponent(); and let instance2 = <CustomComponent /> When checking in the Chrome debugger, I see the following: for instance1 CustomComp ...

php$insert new field into mysql table using form insertcell

How do I insert a column in MySQL? I am struggling with the insertCell form. I have tried but I can't seem to add a MySQL column using my JavaScript code with PHP. I am familiar with Php PDO, but this seems difficult to me. Can someone guide me on ho ...

"Utilize an HTML file open dialog box to gain access to the server's

Is it feasible to implement a file open dialog box that displays files and directories from the server's file system? In my web application, there is a need for users to select a file that resides on the server. Are there any plugins available for th ...

Hold off on running the code until the image from the AJAX request is fully loaded and

Currently, I am facing a challenge with my code that aims to determine the width and height of a div only after it has been loaded with an image from an AJAX request. The dimensions of the div remain 0x0 until the image is successfully placed inside it, c ...

Countdown timer feature and auto-submit function for your website's page

Currently, I am working on an online exam project that requires the page to be automatically submitted after 10 minutes, regardless of whether the user clicks on the submit button or not. Additionally, I want to include a countdown timer to display the r ...

Tips for assessing JSON response data from an AJAX form

I am struggling with how to properly structure a question, but I would like to explain my situation. I am using AJAX to send data and receiving JSON in return. Each value in the JSON response represents a status, and I need to test and react based on these ...

What is the best way to create a button that will trigger a modal window to display a message?

I am looking to create a button that will open a modal window displaying a message. However, when I tried to add a label and viewed the page, the desired window appeared on top of the rest of the content. But unfortunately, clicking the button did not prod ...

The requested function is nowhere to be found within the confines of my Controller module

While working on a personal project, I encountered an issue where a function from another class in a separate Java file is not being found, even though it is defined in the respective class. EventView.js: displayEvent(event){ this.EventTitle = event. ...

Using JavaScript in PHP files to create a box shadow effect while scrolling may not produce the desired result

Issue at hand : My JavaScript is not functioning properly in my .php files CSS not applying while scrolling *CSS Files are named "var.css" #kepala { padding: 10px; top: 0px; left: 0px; right: 0px; position: fixed; background - c ...

Calculate the total number of pages within an epub document

As a beginner in the world of epub, I have acquired numerous files in different epub formats and now wish to make them easily readable online. I'm not quite sure what an epub file contains. Is there a method to determine the number of pages in my epub ...

What is the best way to dynamically resize a text field based on the length of the typed text

I am looking to dynamically expand the width of an input text field when a user enters text into it. I am not sure how to achieve this functionality. Any guidance or help would be greatly appreciated. Is it possible to do this using Jquery or javascript? ...