Unveiling the Mystery of Shadow Acne in Three.js and Effective Solutions for Fixing

Trying to ensure that all shadows are rendered, I adjusted the shadow.camera.top / bottom / left / right properties of the directional light casting shadows. However, this adjustment led to shadow acne issues. Despite attempting to use shadow.bias, the problem persists. What exactly causes shadow acne and how can it be resolved?

https://i.sstatic.net/ixiWD.png

Below is the code snippet from my implementation:

light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 38, 82, 1 );
light.castShadow = true;
// light.shadow.bias = -0.001;
light.shadow.mapSize.width = 2048;
light.shadow.mapSize.height = 2048;
light.shadow.camera.near = 0.1;  // same as the camera
light.shadow.camera.far = 1000;  // same as the camera
light.shadow.camera.top = 120;
light.shadow.camera.bottom = -120;
light.shadow.camera.left = 120;
light.shadow.camera.right = -120;
scene.add( light );

Any insights or suggestions would be greatly appreciated!

Answer №1

By adjusting the shadow.bias to - 0.0005, I was able to eliminate shadow artifacts, but the shadows still appear blocky around the edges.

To enhance the shadow quality, you can try changing the renderer.shadowMap.type to THREE.PCFSoftShadowMap. Additionally, consider narrowing the shadow camera's frustum and focusing on a specific area for shadow casting. Another option is to create a high-quality light map and apply it to the material's lightMap property. Alternatively, increasing the resolution of the shadow map to 4096 x 4096 is possible, but this may impact performance, especially on mobile devices.

Answer №2

By adjusting the shadow.bias to -0.01, I found that it improved the appearance of the shadow. In addition, reducing the intensity also resulted in a more visually appealing shadow.

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

Tips for making a dropdown menu within an Ionic Side menu

Looking for guidance on creating a sub menu in the ionic framework? I'm new to AngularJS and ionic framework, but eager to learn. Below is the code snippet I used to create a dropdown list component: <ion-side-menu side="left"> <ion-co ...

Tips for creating a consistent format based on test cases

var years = Math.floor(seconds / (3600*24*365)) seconds -= years*3600*24*365 var days = Math.floor(seconds / (3600*24)) seconds -= days*3600*24 var hrs = Math.floor(seconds / 3600) seconds -= hrs*3600 var minutes = Math.floor(seconds / 60) ...

Cannot locate the state variable

import React, { Component } from 'react'; import { View, Text } from 'react-native'; import axios from 'axios'; class AlbumList extends Component { state = { albums: [] } ; componentWillMount(){ axios.get(&ap ...

Is it just me or does escape() not work reliably?

With the use of JavaScript, I am able to generate HTML code dynamically. For instance, I can add a function that triggers when a link is clicked, like so: $('#myDiv').append('<a href="javascript:start(\''+TERM+'\ ...

Tips on adding a base64 encoded image string to a JSON object using JavaScript

I'm trying to convert an image file into a JSON object using JavaScript. I've managed to turn the image into a string by utilizing base64 encoding, but I'm unsure how to then convert this string into a JSON object. Can anyone help? ...

Having trouble launching my Angular project

After encountering issues with my Angular project, I decided to reinstall Node.js and Angular CLI. However, when attempting to run ng serve, I was met with this error: view the image here I conducted a thorough search on Google for a solution, which direc ...

React- using this.setState in a method expecting 'this' to be already defined

Currently, I have implemented a for loop to iterate through my Google map markers using the following code snippet: for (i = 0; i < all_professionals.length; i++) { var marker = new google.maps.Marker({ position: this.props.listings[i].lat ...

Copying the position of one object to another in THREE.js does not function as expected

Recently I started experimenting with Three.js and I’m currently working on a project where I need to position a SpotLight at the same coordinates as the camera. Below is the code snippet I’m using: $(document).ready(function() { init(); }); func ...

What could be the reason my script fails to execute during an AJAX refresh?

As I was working on my project's avatar uploader, everything seemed to be going smoothly until this morning when chaos ensued. It was a moment of pure sadness. Initially, selecting a file would prompt the crop tool to appear immediately, and it worke ...

How can the required flag be integrated with rules validation in react-hook-form and material-ui (mui) for inputs?

Currently, I have implemented react-hook-forms for handling form functionality and validation in our application. On the other hand, we are utilizing MUI/Material-UI as our component library. One issue that arises is that MUI automatically adds a * to inpu ...

How can communication be established between JavaScript and a .NET app?

I've been developing a help system using HTML, and I want to include clickable links that can trigger commands in a .NET application (such as guiding users through tutorials or workflows). I have explored the TCard() method for HTML help, but it seems ...

Ensure that Angular resolver holds off until all images are loaded

Is there a way to make the resolver wait for images from the API before displaying the page in Angular? Currently, it displays the page first and then attempts to retrieve the post images. @Injectable() export class DataResolverService implements Resolv ...

I am unable to resize or reposition my r3f model

Having trouble scaling and repositioning my model, I feel like I'm overlooking something. The webpack seems fine as the rest is updating smoothly and the model is loading properly. The file was created using gltfjsx. export default function Model({ .. ...

Tips for combining two htmlelements together

I have two HTML table classes that I refer to as htmlelement and I would like to combine them. This is similar to the following code snippet: var first = document.getElementsByClassName("firstclass") as HTMLCollectionOf<HTMLElement>; var se ...

Changing between two different scenes by utilizing the same renderer in three.js

I have been experimenting with ways to toggle between two scenes in three.js. I know that one option is to load a scene using sceneLoader and exportScene together. Code extracted from josdirksen/learning-threejs - loading a scene var controls = new funct ...

Utilizing the Jquery click function to assign an element as a variable

I'm currently working on a script that aims to extract the inner text of any clicked item with the class "customclass". Keep in mind that this specifically targets anchor elements. However, I've encountered an issue where the individual element ...

Tips for submitting a form using javascript while preventing the default action

Looking for a way to submit a form in Javascript and prevent the default action? Let's explore how you can achieve this. Initially, my HTML form with the ID "contact_form" had an input element like so: <input id="contact_send_msg" type="submit" val ...

Making a modification to a specific field within a MongoDB collection

I need to make a change to the editing field: { "_id" : "C7PgEtzToNwHgJb6e", "metadata" : { "type" : "anything", "editing" : false } } If I execute the following code... Collection.update( { _id: id }, { $set: { metad ...

Tips for labeling subplots in PLOTLY JS

Looking for some guidance on adding titles to plots in Plotly JS. I've checked out the documentation but couldn't find anything helpful. Any tips or suggestions would be greatly appreciated! ...

Create an HTML table with dynamic columns generated using the ng-repeat directive

Can you assist me in creating an HTML Table using JSON data with Angular ng-repeat? Check out the demo here Here is the JSON Data: { "account": { "accountId": "54545", "premise": { "address": { "address1": "1800 Bishop Gate Boule ...