How can I achieve super subtle shading effects in three.js?

Is there a way to achieve a very soft and subtle shadow in three.js, similar to the one in this image? https://i.sstatic.net/6B6en.jpg

So far, I have only been able to create something like this:

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

Here are my current light settings:

HemisphereLight = new THREE.HemisphereLight(0xaaaaaa,0x000000, 0.9);
ambientLight = new THREE.AmbientLight(0xdc8874, 0.5);
shadowLight = new THREE.DirectionalLight(0xffffff, 1);
shadowLight.position.set(5, 20, -5);
shadowLight.castShadow = true;
shadowLight.shadowCameraVisible = true;
shadowLight.shadowDarkness = 0.5;
shadowLight.shadow.camera.left = -500;
shadowLight.shadow.camera.right = 500;
shadowLight.shadow.camera.top = 500;
shadowLight.shadow.camera.bottom = -500;
shadowLight.shadow.camera.near = 1;
shadowLight.shadow.camera.far = 1000;
shadowLight.shadowCameraVisible = true;
shadowLight.shadow.mapSize.width = 4096; // default is 512
shadowLight.shadow.mapSize.height = 4096; // default is 512

And in the rendering section:

renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;
renderer.shadowMapType = THREE.PCFSoftShadowMap;

Thank you!

Answer №1

To reduce the harshness of shadows, adjust the radius in the following manner:

var brightness = new THREE.AmbientLight(0xffffff, 0.2);
brightness.castShadow = true;
brightness.shadow.radius = 8;

Answer №2

I was intrigued by this issue as well, so I decided to experiment with all the variables I could find. The first significant change occurred during initialization:

shadowLight.shadow.mapSize.width = 2048; // Adjusted to 4K resolution without exceeding 2K

shadowLight.shadow.mapSize.height = 2048; //   -  || - 

Next, I tried something different and found that when I set:

shadowLight = new THREE.DirectionalLight(0xffffff(COLOR), 1.75(NEAR should be less than 2), 1000 (FAR should only encompass the range between light and floor));
the shadows blended more smoothly when I also adjusted the position of my directional lights to 250 with:

shadowLight.position.set( 100(X for additional effects), 250(Y above the scene), 0(Z) );

!!!!!!!!!!!!!!!!!Delete the (VAR) parts before using!!!!!!!!!!

Afterwards, I changed these values to match the width of my floor.

d = 1000;
shadowLight.shadow.camera.left = -d;
shadowLight.shadow.camera.right = d;
shadowLight.shadow.camera.top = d;
shadowLight.shadow.camera.bottom = -d;

It's important to do this because if you utilize:

var helper = new THREE.CameraHelper( shadowLight.shadow.camera );

and include it in the render:

scenes.add( shadowLight, helper );

...you will observe the boundaries of your light box, which ideally should align with the width of your scene. I hope this information proves helpful to someone.

Answer №3

What you are observing is referred to as Ambient Occlusion. There are several resources available for further exploration, and with this knowledge in hand, you can discover even more. For instance: Exploring ambient occlusion in three.js

Answer №4

Actually, Ambient Occlusion is specifically the contact shadow between closely positioned meshes. However, if you're looking to achieve soft shadows, there are two methods you can explore:

The first method, which is simpler, involves creating lightmaps within your 3D modeling software. This process essentially bakes shadows (and potentially ambient occlusion, textures, and materials) into a single texture that can be later used in ThreeJS. Keep in mind though, once baked, the objects cannot easily have their shadows adjusted relative to each other.

The second method is demonstrated in the example linked below, although I haven't delved into it much myself:

Good luck with your project! Best regards.

EDIT: Apologies, upon further examination, the F1 car example mentioned still utilizes a lightmap. However, the shadow dynamically follows the car, resulting in a visually appealing effect. You can view the shadow texture being applied here, showcasing the baked nature of the effect:

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

Keeping JSP current with changes made to files on the client side

Currently, I am tackling a project that consists of two main components: a) A Java Application that runs on a client machine. b) A Web Application that is hosted on a web server. The Java Application generates results at random intervals. These results n ...

Why does the onBlur event function in Chrome but fails to work in Safari?

I've encountered a problem with the onBlur event in react-typescript. To replicate the issue, I clicked the upButton repeatedly to increase the number of nights to 9 or more, which is the maximum allowed. Upon further clicking the upButton, an error m ...

Loop through a collection of unique identifiers for documents and establish event listeners in Firestore

Within my Vuex store, there is an action designed to retrieve a list of uids for followed users from the current user's Firestore UserDataCollection document. The action then processes each uid to extract data that will be displayed on the UI. While t ...

Using regular expressions to identify the presence of "&", parentheses, and consecutive letters in a string

I specialize in working with JavaScript and I have a need to verify if my text contains certain characters. Specifically, I want to check for the presence of parentheses (), ampersands (&), and repeating letters within the text. Here are some examples: te ...

Using JavaScript, implement the array.filter method on a JSON array to retrieve the entire array if a specific property matches a given

Help needed with filtering an array: In the user_array, there are arrays that need to be compared to see if the header_info.sap_number matches any value in the valid_sap_number array. If a property value matches anything in the valid_sap_number array, th ...

Error: React-Redux/Jest Invariant Violation - The "store" could not be located

I have a test file set up that is similar to the one used by create-react-app. Here is my App.test.js file: App.test.js import React from 'react'; import ReactDOM from 'react-dom'; import { App } from './App'; it('rend ...

Checking the validity of a date range

Date 1: 23/05/2013 Date 2: 29/05/2013 Currently, I have two dateTimePickers named dtDateStart and dtDateFinish, along with a submit button. My goal is to implement validation on the Submit button click event so that it does not accept dates falling betwe ...

What is the best way to showcase the outcomes of a map function in JSX?

I'm currently learning react and working on implementing the searchMap function (to display movie title/poster) with the TMDB API. While I am able to successfully log the necessary information to the console, I am encountering issues such as undefined ...

Combine several objects into one consolidated object

Is there a way to combine multiple Json objects into one single object? When parsing an array from AJAX, I noticed that it logs like this: 0:{id: "24", user: "Joe", pass: "pass", name: "Joe Bloggs", role: "Technical Support", ...} 1:{id: "25", user: "Jim ...

Loading Data into Array - Angular/Ionic

I am currently developing an App and encountering issues with pushing data into an array. It seems that there is a problem in my code. Would you mind taking a look? Error Message Thrown: ionic.bundle.js:25642 TypeError: Cannot read property 'title&ap ...

Creating a personalized JavaScript clock based on a specific time

I have implemented a script below, and my goal is to customize the time displayed by the script and have it update automatically without requiring manual adjustment each time. (I want to set the time once and have the script manage the display) However, u ...

Tips for properly including my Dialog Flow access token in the environment file within the Angular CLI

I am currently in the process of creating a bot using angular cli and integrating dialog flow's API. The issue I am facing is that when I perform debugging in Chrome, I encounter the following error logs: ApiAiClientConfigurationError columnNumber: ...

Tips on implementing Piwik JavaScript code within app.js on Express

I am trying to implement Piwik tracking on my Express website using JavaScript code. I placed the code in my app.js file but encountered an error. Here is the JavaScript code snippet: <script type="text/javascript"> var _paq = _paq || []; ...

Obtain the identifier of a div within nested HTML components by utilizing jQuery

How do I retrieve the id of the first div with the class: post, which is "367", using jquery in the given HTML code: <div id="own-posts"> <span class="title">Me</span> <div class="posts_container"> <div class="post"& ...

What potential challenges could arise from granting access to all Controllers to all Data?

My AngularJS application with CRUD functionality relies on a WebSocket server for processing information. This eliminates the need for constant HTTP polling and allows updates to be automatically pushed to all users. When setting up my services, I quickly ...

`Datatables sorting feature for British date and time`

I'm currently attempting to organize a column in a table using the DataTables plugin that contains UK date and time formats such as: 21/09/2013 11:15 Implementing Ronan Guilloux's code: jQuery.extend( jQuery.fn.dataTableExt.oSort, { "uk_dat ...

What are some effective ways to slow down the image transitions in a Javascript slideshow?

I am currently developing a slideshow that updates Images, Title, and Description simultaneously based on their Array index. The slideshow is functional BUT, my goal is to achieve a smooth transition to the next/previous Image (... title & descript ...

Exploring Nashorn's Global Object Variables Through Access and Intercept Techniques

I recently came across a question called "Capturing Nashorn's Global Variables" that got me thinking. I'm facing limitations when it comes to capturing the assignment of variables to the global object. For example, let's say I evaluate the ...

Looking to show the contents of a Rails AJAX JSON response in your application? Having trouble with Javascript displaying [object HTMLDocument] instead? Let

I have been working on a Rails application where I implemented an AJAX / JSON controller to facilitate dynamic HTML updates within the view. For guidance, I referred to this helpful resource: When making a call like this: ../related.json?vendor_id=1&b ...

Unable to retrieve JSON data from a PHP file hosted on the server

I have a server-side database with a table called "customers" and a column named "names". My goal is to send a request to the server asking for the first two records in the "customers" table. However, when I execute the program, the browser does not displa ...