What could be causing the shadows to move across my objects in three.js?

My three.js scene is displaying a 3D model with a DirectionalLight casting shadows on it.

However, I am noticing a strange gradient stepping effect on the model, almost as if it's composed of multiple submodels each with their own slight shadow.

Check out this screenshot for reference: https://i.sstatic.net/HEm8n.png

I'm puzzled about why this is happening and how I can fix it. Any ideas?

Here are some important code snippets from my project:

Camera & Directional Light setup:

// Camera
camera = new THREE.PerspectiveCamera( 30, (window.innerWidth / window.innerHeight), 1, 10000 );
camera.position.x = 1000;
camera.position.y = 50;
camera.position.z = 1500;
scene.add( camera );

// LIGHTS
var lightFront = new THREE.DirectionalLight( 0xffffff, 0.7 );
lightFront.position.x = 120;
lightFront.position.y = 120;
lightFront.position.z = 150;
lightFront.castShadow = true;

lightFront.shadow.camera.left = -6;
lightFront.shadow.camera.right = 6;
scene.add( lightFront );

The material used is a THREE.Mesh, configured with:

material.normalScale = new THREE.Vector2( 1, 1 );
material.castShadow = true;
material.receiveShadow = false;
material.shininess = 100;

For the renderer, these settings are applied:

renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.shadowMap.soft = true;
renderer.shadowMap.bias = 0.0039;
renderer.shadowMap.darkness = 0.5;
renderer.shadowMap.width = 1024;
renderer.shadowMap.height = 1024;

I've experimented with different renderer configurations but haven't been able to resolve the issue.

This project is currently using revision 82 of three.js.

Answer №1

The issue is most likely being caused by the low resolution of the shadow map, which is set to a default of 512 * 512.

To address this, you can adjust the resolution using the following code:

lightFront.shadow.mapSize.width = lightFront.shadow.mapSize.height = 1024;

Keep in mind that increasing the resolution will result in longer computation time and may cause a decrease in framerate.

There is a maximum limit based on your target device specifications, which can be viewed here.

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

Update the current value in array.prototype

Recently, I've noticed that the built-in JavaScript sort function can be unreliable at times. To address this issue, I decided to create my own sorting function. Consider the following scenario: Array.prototype.customSort = function(sortFunction, upd ...

jQuery is unable to manipulate newly added DOM elements that have been loaded via AJAX

Having trouble with jquery ajax. Unable to interact with newly added element through ajax. Code snippet: $(".yorum_input").keypress(function(e) { if (e.keyCode == 13) { e.preventDefault(); var alt_id = $(this).attr('yorum_id'); va ...

Tips for effectively eliminating errors in a redux store

Within my react-redux application, I have implemented a system to catch error responses from redux-saga. These errors are saved in the redux-store and rendered in the component. However, a major challenge arises when trying to remove these errors upon comp ...

Having trouble retrieving data from a JSON file using JQuery AJAX?

My JSON file structure is presented as follows: { head: { link: [], vars: [ "CompanyName", "Company_Name", "Foundation_URI", "Foundation_Name", "Latitude", "Longitude" ] }, results: { distinct: fal ...

Steps for adjusting the matMenuTriggerFor area so it only triggers when hovering over the arrow

Hello there! I'm currently working on adjusting the trigger area for opening the next menu panel. Right now, the next menu panel opens whenever I hover over either the title or the arrow. However, my goal is to have the menu open only when I hover ove ...

The length function appears to be signaling an unanticipated error

Recently, I encountered an issue with the code execution. Although the code appears to be functioning correctly, it is throwing an uncaught error. Is there a reason for concern regarding this situation? var xmlhttp = new XMLHttpRequest(); xmlhttp.onread ...

Removing the empty option from Angular

I am encountering an issue with an empty option when cycling through an array. Below is the code snippet. View: <select ng-model="getseason" class="form-control"> <option ng-repeat="season in seasons" value="{{ season }}"> Seas ...

Execute the code only if the variable is not null

I encountered an issue with my code: setInterval(function() { $.ajax({ url: url, success: function(data, count){ var obj = jQuery.parseJSON(data); var content = obj.results[0].content; }}) }, 2000) The code runs every 2 seconds an ...

Instantly reveal menu by pressing button

Is there a way to make my mobile menu open immediately upon touching the button? I have used ontouchstart="" in both buttons to create an overlay on the content when the offcanvas menu is visible. This functions well as soon as the user touches either butt ...

Retrieve information from a URL and transform it into a JSON array

One of my functions looks like this: function retrieveJsonDataFromWebsite(url, callback) { let chunks = []; return require('https').get(url, res => { res.setEncoding('utf8') .on('data', (chunk) => { ...

I am attempting to set up a live chat feature using django and orbited, however, I am encountering numerous errors along the way

Currently, I am in the process of setting up a simple Django/Orbited/Stomp live chat based on this tutorial. Despite meticulously following each step and even duplicating all the code provided, I am encountering a perplexing error that is leaving me puzzle ...

"When the value is false, use the Vue binding to apply a specific

My challenge involves managing a website that is designed to receive boolean values and store them in an array where the key represents the ID and the value represents the boolean. For example: policiesActive[ "2" => false, "3" => false] The w ...

Exploring threejs to project onto a cylindrical surface

Can you provide guidance on how to project an image onto a cylinder using threejs? Do I need to map separate portions of the image onto each face of the cylinder, or is there a more efficient method available? Appreciate any help on this matter! ...

Unable to access the length of a scope variable after it has been modified

Within my HTML markup, I have a ng-init="find()" which triggers this particular function: $scope.find = function() { $scope.vehicles = Vehicles.query(); $scope.vehiclesQtd = $scope.vehicles.length; }; The issue arises when even though the vehicle ...

Receive and process messages from RabbitMQ in a Node.js application

I am currently working on consuming messages from RabbitMQ in Node.js and so far, everything is going smoothly. During the message consumption process, I am performing some operations (such as API calls). Now, my goal is to only acknowledge the message o ...

Creating a workaround for mapping legacy URL fragments to element names in Backbone.js

Is there a workaround for linking to specific parts of a page in a backbonejs application? I have found solutions for static HTML pages by using the `name` attribute and `#fragment` in the URL, but this approach doesn't seem to work directly in backbo ...

Guide to adding a new Vue-Grid-Item with a button

Currently, I am working on a software project for the Research department at my university, specifically focusing on an Atomic Layer Deposition system. The main goal of this program is to allow users to create and customize their own 'recipe' for ...

What is the reason that setState does not update the value of the "editing" key to true?

The edit feature does not switch the state of editing to true. I am at a loss for what to do: class Note extends React.Component { constructor (props) { super(props) this.state = { editing: false } } /**edit() { this.setState = ...

Identifying repeated numbers within an array using objects

What is the most effective way to replicate array integers according to their key values retrieved from an API? Input: {1208: "1", 1209: "2"} Output: [1208, 1209, 1209] I attempted using Object.keys but it only fetched the parent key ...

Utilize the WebGLRenderTarget again

In my project, I am working with two scenes: the main scene which displays a textured plane, and a secondary scene that needs to be rendered to a texture. This texture will serve as a map for the main scene's plane. Although most THREE.WebGLRenderTar ...