The color of a Three.js plane appears more intense with the addition of lights

import * as THREE from 'three';
import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'; 
import * as dat from 'dat.gui';


const renderer = new THREE.WebGL1Renderer();

renderer.shadowMap.enabled = true

renderer.setSize(window.innerWidth,window.innerHeight)

document.body.appendChild(renderer.domElement)

const scene  = new THREE.Scene()

const camera = new THREE.PerspectiveCamera(
    75,
    window.innerWidth/window.innerHeight,
    0.1,
    1000

)

const orbit = new OrbitControls(camera,renderer.domElement)

const axeHelper = new THREE.AxesHelper(5);
scene.add(axeHelper)

// scene.background = new THREE.Color(0XFFFFFF)

camera.position.set(-10,30,30)
orbit.update();

// Box
const boxGeometry =new THREE.BoxGeometry();
const boxMeterial = new THREE.MeshBasicMaterial({color:0x00FF00});
const box = new THREE.Mesh(boxGeometry,boxMeterial);
scene.add(box)

// paper
const planeGeometry = new THREE.PlaneGeometry(30,30);
const planeMaterial = new THREE.MeshLambertMaterial({color: 0xFFFFFF,side: THREE.DoubleSide});
const plane = new THREE.Mesh(planeGeometry,planeMaterial);
scene.add(plane); 
plane.rotation.x = -0.5 * Math.PI
plane.receiveShadow = true 

// Grid helper
const gridHelper = new THREE.GridHelper(30);
scene.add(gridHelper);

// Sphere
const sphereGeometry = new THREE.SphereGeometry(4,50,50);
const sphereMeterial = new THREE.MeshStandardMaterial({color:0x0000FF });
const sphere = new THREE.Mesh(sphereGeometry,sphereMeterial);
sphere.castShadow = true
scene.add(sphere);

sphere.position.set(-10,10,0);

// // Ambient Light
const ambientLight = new THREE.AmbientLight(0x222222 );
scene.add(ambientLight);

// // Direction Lights
const directionalLight = new THREE.DirectionalLight( 0xFFFFFF, 0.8 );
directionalLight.position.set(-30,50,0)
directionalLight.castShadow = true;
directionalLight.shadow.camera.bottom =-12
scene.add( directionalLight ) ;


//  Direction Light Helper
const dLightHelper = new THREE.DirectionalLightHelper(directionalLight,5);
scene.add(dLightHelper)

//  Direction Light Shadow Helper
const dLightShadowHelper = new THREE.CameraHelper(directionalLight.shadow.camera);
scene.add(dLightShadowHelper)





// Controller
const gui = new dat.GUI();
const options = {
    sphereColor: '#ffea00',
    wireframe:false,
    speed:0.01,
}

gui.addColor(options,'sphereColor').onChange(function(e){
    sphere.material.color.set(e);
})

gui.add(options,'wireframe').onChange(function(e){
    sphere.material.wireframe = e;
})

gui.add(options,'speed',0,0.1)



// box.rotation.x = 5;
// box.rotation.y = 5;

let step = 0;
let speed  = 0.1;
// Box animation
function animate(time) {
    box.rotation.x = time/1000;
    box.rotation.y = time/1000;
    renderer.render(scene,camera);

    step += options.speed;
    sphere.position.y = 10 * Math.abs(Math.sin(step))
}

renderer.render(scene,camera);


renderer.setAnimationLoop(animate);


plane color is much darker

I have a MacBook M1 and I'm currently learning three.js through tutorials. I've adapted the code from the tutorial but my rendered screens in three.js appear darker after adding lights, and I'm struggling to find a solution.

The plane material appears too gray now compared to its original white color before adding lights. This has made the shadows unclear. I want to add more color to the plane material to make it look whiter as shown in the tutorial for better clarity in shadows.

Answer №1

There doesn't appear to be any incorrect behavior here. The outcome aligns with expectations. The brightness of the DirectionalLight is influenced by its orientation in relation to the surface's normal vector (the Bidirectional reflectance distribution function) and its intensity level. Lower intensities result in a darker scene, resembling nighttime darkness in reality. On the other hand, higher intensities create a brighter environment. To achieve brighter surfaces, one can boost the light source's intensity or introduce additional light sources. Additionally, increasing the ambient light's intensity is another way to enhance overall brightness.

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 maintaining consistent heights for two div elements in jQuery MobileEnsure that two div elements in jQuery

I am brand new to the jquery mobile framework and seeking your patience as I navigate through it. In my current project, I am required to display data in a tabular format. To achieve this, I have set up a structure with left and right columns: <div dat ...

Asynchronously parsing CSV files in NodeJs using the `await` keyword within the `on('data')`

I have a specific code snippet that is designed to read lines from a .csv file one by one and then store each processed row into a database const csv = require('csv-parse') const errors = [] csv.parse(content, {}) .on('data', async ...

Why is it that HTML is not being shown?

Within my angular application, I have data that may contain line breaks, links, and other elements that need to be converted to HTML. To handle this requirement, I created a function that converts the text to HTML: $scope.textToHTML = function(text){ ...

Can someone explain the significance of receiving a TypeError when trying to access properties of null (specifically 'useRef') in a React application?

I encountered an issue while working on a React project...the browser console displays the following error. What does this mean? And how can I resolve it? react.development.js:1545 Uncaught TypeError: Cannot read properties of null (reading 'useRef ...

Managing Subdomains in Nuxt.js Using Vue.js

I am currently developing a Nuxt.js (vue.js) application. I am aware that Nuxt automatically generates routes based on the directory structure within the 'pages' folder. I am curious about how it would handle subdomains. My goal is to establish ...

Tips for handling data strings using axios

In my node.js project, I am following a manual and attempting to display data obtained from jsonplaceholder app.get('/posts', async (req, res) => { const response = await axios.get('https://jsonplaceholder.typicode.com/posts'); ...

Phone view experiencing rendering issues with 3D models because of the high strain on the mobile browser

I am facing an issue with my react-based web app that includes three 3D models. While these models render perfectly on desktop, they do not all render correctly on mobile view. When one model is rendered, the others break. There seems to be no problem with ...

The ElementNotInteractableException was thrown because the element could not be accessed via the keyboard when trying to input text into the FirstName field on Facebook

The issue is as follows: Exception encountered in thread "main" org.openqa.selenium.ElementNotInteractableException: Element is not accessible via keyboard Here is the code snippet: System.setProperty("webdriver.gecko.driver"," ...

Unable to perform the 'setSelectionRange' function on the 'HTMLInputElement' due to the input element's type being 'number', which does not allow selection

My attempt to enable text selection in an input box upon user click by using the code snippet below was unsuccessful: <input type="number" onclick="this.setSelectionRange(0, this.value.length)" name="quantity" /> Instead of achieving the desired ef ...

Passing JavaScript attribute events to alternative handler or type

As I set up a web page for a touch screen computer, I've come across an issue with triggering onclick events due to the size of my fingers causing the cursor to move as I attempt to click. To solve this problem, I am considering forwarding onmousedow ...

Steps to configure useState to manage data within an object

Having trouble setting an object with useState in my code. Despite my effort, I am only getting the initial value for the object named setWishlist. Can someone spot what mistake I am making? const CenterModal = props => { const [modalData, setModalDa ...

Display the matrix in a semi-spiral pattern

I am working with a 3 by 5 matrix, filled with numbers from 1, presented as follows: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 The task is to print the values in a half-spiral order, starting from the bottom left vertically: 11 6 1 5 10 15 12 7 2 4 9 ...

Retrieving information from a public Google spreadsheet using client-side JavaScript

How can I retrieve cell values from a public Google spreadsheet? GET https://sheets.googleapis.com/v4/spreadsheets/1vW01Y46DcpCC7aKLIUwV_W4RXLbeukVwF-G9AA7P7R0/values/A1A4?key=abcdef The above request returns a 403 error. I also included the Referrer ...

Website route organization tool

Seeking assistance with implementing a route planning feature on my website. The user should be presented with multiple route options upon entering their origin and destination. Take a look at this reference site for inspiration: Any help would be great ...

What is the best way to organize JSON files data in a specific sequence?

I successfully converted 3 JSON files into an HTML page using AngularJS. Here is the code I used: Factory code app.factory('myapp', ['$http', function($http) { function getLists() { var tab = ['url1', 'url2 ...

Is there a way to render an OBJ + MTL file with double-sided loading?

Below the obj and mtl files are loaded using the loader, so how can I access the material and make it double sided? I have tried using mtlLoader.setMaterialOptions({side: THREE.DoubleSide}) as described in the documentation on the threejs.org page, but it ...

Ways to Insert Text and Values into an Array

{{ "user": "randomuser", "message": "require assistance" }, { "user": "automated assistant", "message": "do you need any help?" }, { "user": "randomuser", "message": "another inquiry" } I am seeking to extract additional paragraphs ...

DomSanitizer in Angular is not able to bind to an Angular component

Trying to dynamically insert HTML content into a DIV has been successful when done statically. The following code is functioning properly: <popover-content #pop1 title="Cool Popover" placement="right" ...

Merge an array of objects to form a unified object

I have information structured in the following way: [ { key: 'myKey' value: 'myValue' }, { key: 'mySecondKey' value: 'mySecondValue' }, { key: 'myThirdKey' value: 'myT ...

What improvements can be made to optimize this SQL query and eliminate the need for an additional AND statement at the end

I am working on dynamically constructing a SQL query, such as: "SELECT * FROM TABLE WHERE A = B AND C = D AND E = F" Is there a more efficient way to construct this SQL query without adding an extra AND at the end? Here is my current code snippet: le ...