Opacity of Shadows in Three JS

Hello everyone, I have successfully loaded a custom model into my canvas but I am facing an issue with making the shadow transparent on the model itself. I am unsure how to achieve this as I would like the models to both cast and receive a shadow. Can anyone provide some guidance on this matter?

Here is an excerpt of my code:

var loader = new THREE.JSONLoader();
    loader.load('model/p3.json', handle_load);

    var mesh;
    function handle_load(geometry, materials) {

        var material = new THREE.MeshPhongMaterial();

        mesh = new THREE.Mesh(geometry,material);

        scene.add(mesh);
        mesh.position.z = 0;
        mesh.position.y = 0;
        mesh.rotation.y = 5;


        //LIGHT
        var ambient = new THREE.AmbientLight(0xffffff, 0.15);
        ambient.target = mesh;

        scene.add(ambient);

        var light = new THREE.DirectionalLight(0xffffff, 1);
        light.target = mesh;
        light.castShadow = true;
        light.position.z = -150;
        light.position.y = 150;
        light.position.x = 150;
        light.shadow.bias = 0;
        light.shadowDarkness = 0.2;
        light.shadow.mapSize.width = 2048 * 2;
        light.shadow.mapSize.height = 2048 * 2;
        scene.add(light);
        mesh.receiveShadow = true;
        mesh.castShadow = true;

    }

    var shadowmaterial = new THREE.ShadowMaterial();
    shadowmaterial.opacity = 0.2;


    var material2 = new THREE.MeshPhongMaterial({
        color: 0xffffff,
    });

    var geometry3 = new THREE.PlaneGeometry(500, 500, 100, 100);
    var mesh3 = new THREE.Mesh(geometry3, shadowmaterial);
    mesh3.rotation.x = -90 * Math.PI / 180;
    mesh3.position.y = 0;
    scene.add(mesh3);

     mesh3.receiveShadow = true;

Here is an image of the rendering for reference: https://i.sstatic.net/azcg2.png

Any help on this issue would be greatly appreciated. Thank you.

Answer №1

With the mesh material always gray and the floor white, shadows will always stand out. The realism of the shadows does not allow for much tweaking directly through shadow properties, so adjustments need to be made with materials and lights to achieve the desired effect.

One option is to change the plane material color to gray and increase light intensity, or brighten the mesh material and decrease light intensity.

Experimenting with adding more lights and adjusting their settings can also help reduce shadow contrast. Increasing ambient light and decreasing directional light can have an impact, along with trying different types of lights.

Changing aspects of the material, such as reflectivity, can also alter the shadows. By adjusting reflectivity and specular settings, it is possible to still achieve the desired effect even with changes made to the directional light intensity.

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

What is the best way to display the next and restart buttons at the bottom of every question?

How can I display the next and restart buttons at the bottom of each question in my JavaScript quiz web app? Why is the user unable to choose the wrong answer from the provided options? I'm facing difficulty showing the next and restart buttons for i ...

"Utilize Meteor to transmit emails to internal email addresses within the intran

I have successfully developed a Meteor App to manage requests. However, I am facing an issue where I need emails with default text to be sent whenever a request is created or updated. The challenge lies in the fact that I am operating within an intranet e ...

Utilizing Next.js to dynamically update data within a div element upon

I have a table set up to display data and I want to transfer the row data into a div when the user clicks on a table row: Currently, I can successfully get the data onclick: const handleClick = (rowData) => { console.log(rowData); } However, I am ...

Transforming a file with a node module that lacks a .js class into a browseable format

I am currently working on browserifying my module. One of the dependencies I have is on this https://www.npmjs.com/package/chilkat_win32. It is present in my node_modules folder and here is how the structure looks: https://i.stack.imgur.com/uw9Pg.png Upo ...

Displaying a loading spinner image as PHP script runs

Hey there! I've been experimenting with using a script to show a loading bar while my PHP code is running. I followed the instructions on this website, but even after following the exact steps, my loading bar still isn't showing up. Any suggestio ...

What is the functionality of the post method in PHP?

Is there a solution to this issue? //error_reporting(0); $token = $_POST['token']; $invite = $_POST['invite']; $url = "https://mywebsite.com/asd/".$invite.""; $dingaling = "$token" ?> When: ERROR: Notice: Undefined index: token ...

Is there a way to retrieve the Angular-Redux store in a child module?

Within my Angular application, I utilize angular-redux for managing the application state. In my main module, I have defined the redux store in the following manner: export class MainModule { constructor(private ngRedux: NgRedux<MainAppState>, ...

Angular material is experiencing an issue where content is being cut off or

I am currently working on a project using AngularJS for a web application. I have encountered an issue where some of the content in the md-content element is being clipped. For instance, the body tag has the style: overflow: hidden, and the child md-conte ...

AngularJS - Alter the URL with $state.go without refreshing the HTML content

Struggling with routing in angularJS and can't seem to find a solution despite trying various methods online. Any assistance would be greatly appreciated. Encountering an issue with the $state.go function in which it changes the URL but fails to load ...

The initial attribute unattainable for entities processed by csv-parse

Working on parsing a csv file, I am utilizing the csv-parse library to handle the following data - userID,sysID 20,50 30,71 However, after parsing, I am encountering difficulty accessing the property generated from the first column userID. Here is the s ...

NG-model not visible to AngularJS Controller's filter

Finally, the code is working perfectly. It's a mystery to me. I created a custom filter to use with ng-repeat. The code is implemented within a Controller ... .controller('makeOrderController', function ($scope, $timeout, $ionicLoading) { ...

Issue encountered during installation of react-masonry-css using npm

PS E:\Share me\shareme_frontend\my-project> npm install react-masonry-css npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfe ...

JQuery - Triggering mouseenter/hover event only on top-level menu items, excluding the nested submenu items (list items that are not within nested lists)

I have a complex navigation menu structure with nested lists, and I'm struggling to trigger an event only on the top-level items when hovered. Despite trying different jQuery selectors and methods, such as using the NOT selector or targeting direct ch ...

Countdown timer that counts down in reverse when the browser is minimized

I am currently working on a JavaScript project where I have implemented a countdown timer in seconds. Once the timer hits zero, it triggers a specific function. The timer functions correctly, however, if the browser enters sleep mode or is minimized, the ...

What is the best way to apply a background image to a DIV element using CSS

The main aim is to change the background image of a DIV using AJAX. $.getJSON("https://itunes.apple.com/search?term=" + searchTerm + '&limit=1' + '&callback=?', function(data) { $.each(data.results, fun ...

Ajax request and the Ghostery extension in Firefox

I've implemented the following code to detect ad blockers like Ghostery: <script> var request = new XMLHttpRequest(); request.onreadystatechange = function() { if(request.readyState === 4 && request.status === 200 ) { ...

What is the best way to handle responses in axios when dealing with APIs that stream data using Server-Sent Events (S

Environment: web browser, javascript. I am looking to utilize the post method to interact with a Server-Send Events (SSE) API such as: curl https://api.openai.com/v1/completions \ -H "Content-Type: application/json" \ -H ...

Issue: AngularJS Injector Module Error

Recently started learning angularjs and trying to set up an app. Here's a simple and direct way to do it: Angular controller: (function () { 'use strict'; angular .module('myQuotesApp') .controller(' ...

What is the best way to split a single column into two using blocks?

I am working with a container that currently has all its blocks lined up in a column. I need to divide them into two columns, with 5 blocks in each. Unfortunately, the plugin I am using generates the code for me and does not allow me to insert my own div e ...

How to efficiently search MongoDB for existing records and group them by unique array values

My dataset is structured like this: { "_id" : 1, "category" : [ { "name": "category1" }, { "name": "category2" } ], "event": [ { type: "house" ...