Enhance the illumination within the three.js environment

Currently, I am working on rendering solid models in three.js, inspired by the way GitHub showcases STL files like the Octocat head. However, I am facing difficulties in setting up the lighting to achieve an optimal look. The current rendering has its limitations, as shown below:

https://i.sstatic.net/82uWR.png

One of the main issues is that the model looks good only from certain angles, resulting in poor contrast and planes appearing to be the same shade of grey when viewed from different perspectives.

The snippet of code I am using for lighting is:

light = new THREE.DirectionalLight(0xffffff, 1);
light.position.copy(camera.position);
scene.add(light);

Furthermore, the light follows the camera when it moves.

Do you have any suggestions on how to enhance the overall lighting and appearance of the model?

Answer №1

If you want to enhance the lighting on your rendered object, here are a few suggestions:

Experiment with different material types:

Each material reflects light uniquely. Instead of using a Basic material, consider using a Lambert material. You can define the material when creating your mesh. For example, define your material first:

var material4 = new THREE.MeshLambertMaterial({color: 0xffffff, vertexColors: THREE.FaceColors});

Then, apply the material to your object:

var objectMesh = new THREE.Mesh(objectGeom, material4);

For more information on the Lambert Material, refer to the documentation here.

Include additional light sources:

Most objects benefit from multiple light sources coming from different angles. You can add new lights using the following code:

lights[ 0 ] = new THREE.PointLight( 0xffffff, 1, 0 );
lights[ 0 ].position.set( 0, 200, 0 );
scene.add( lights[ 0 ] );

Note that lights[] is an array where you can add multiple lights.

Use directional light helpers:

During development, it can be helpful to use directional light helpers to visualize the light sources. For example:

directionalLightHelper[0] = new THREE.PointLightHelper(lights[0], 1);
scene.add( directionalLightHelper[0] );

Answer №2

Personally, I gravitate towards utilizing the Standard material.

standardMaterial = new THREE.MeshStandardMaterial( {
                    color: 0xffffff,
                    metalness: 0.5,
                    roughness: 0.5,
                } );

I also recommend activating gammaOutput for the renderer, as it significantly enhances the appearance of overbright areas:

        renderer.gammaInput = true;
        renderer.gammaOutput = true;

From a creative perspective, it is ideal for the light to emanate from the top left corner of the screen, slightly offset. Additionally, enabling shadows ensures that the object consistently casts a shadow towards the bottom right.

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

Export data from Angular Material data table to Excel format

I'm currently utilizing the angular material data table to showcase data in a tabular layout. I have a requirement to add a feature that enables the export of tabular data to an Excel sheet. Unfortunately, I haven't been able to locate any resour ...

The charAt function in a basic JavaScript if statement is failing to execute

When a user inputs a number that does not start with 6 or 9, an error occurs: console.log($(this).val().charAt(0)); if($(this).val().charAt(0) != 6 || $(this).val().charAt(0) != 9){ x=false; }else { x=true; } The console.log function corre ...

Issue with Attaching Click Event to Dynamic Div Elements

I've implemented divs with a Click Event triggered by a value entered in a text box. See an Example Here Upon opening the page, clicking any rows will trigger an alert. However, if you change the value in the text box (Enter Number) and click load, ...

JavaScript's native innerHTML function is unable to access the content generated by Vue

I have been struggling with extracting the content from a specific div element in my HTML code. <div id="output" ref="output_data"> <h1>{{ information }}</h1> </div> I attempted to retrieve the contents using ...

Learn how to activate static methods in JavaScript while also restricting the utilization of instance functions without the necessity of using the new operator

What is the best way to allow the usage of static methods while restricting the use of instance functions without utilizing the new operator? In this scenario, the constructor will trigger an exception if it is called without the new operator. However, thi ...

Can you identify the target of the term "this" in the upcoming JavaScript code?

DISCLAIMER: I am inquiring about a specific instance of this, not its general purpose. Please refrain from quick Google responses or copied answers (: The code snippet below demonstrates JavaScript/jQuery: var req = {}; function getData() { var from ...

What could be causing this JSON object error I'm experiencing?

res.send({ customerDetails:{ fName, lName, }, applicantDetails:{ [ {primaryApplicant:{fName1,lName1}}, {secondaryApplicant:{fName2,lName2}}, {thirdA ...

Tips for integrating Twitter sharing functionality in React JS

I am looking for a way to enable users to easily share images from my website on Twitter. Although I tried using the react-share module, it does not provide an option to directly share images. This is the snippet of code I currently have: import { Sh ...

Checkbox ensemble computes total score

I am currently working on a project that involves multiple checkbox groups, with each group containing 3 checkboxes labeled as (1, X, 2). My goal is to assign a value of 100% to each group, distributed evenly among the checkboxes within it. The distributio ...

Executing all promises later in Node.js using Promise.all

Having a series of promises set up as follows: module.exports = function (a, b, c) { return someAsync(() => { someFunc(a); }) .then(() => myPromises(a, b, c)) .then(result => { console.log(&apos ...

When attempting to utilize VueJs v-bind:type on an input element, it appears to be ineffective when the type property name is

Code: <!DOCTYPE html> <html> <head> <title>Creating a Vue app</title> <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3046455570021e061e0100">[ ...

Loading external templates in Angular2 with Webpack2

Attempting to integrate ngtemplate-loader in a project using AngularJs 2 and Webpack 2 is proving challenging. While this setup has been successful in Angular 1.x projects with Webpack 1.x, it encounters an error when running in the browser: Uncaught Type ...

Organizing a Vue.js SPA project: Implementing Vuex store and API calls efficiently

Here is how I have organized the structure of my Vue app: components/ article/ AppList.vue common/ AppObserver.vue NoSSR.vue layout/ AppFooter.vue AppHeader.vue ui/ AppButton. ...

history.push() function is ineffective within a JavaScript file that does not contain a class

I've been delving into React and encountering an issue with the history.push("/dashboard") method, it's not functioning as expected. import axios from "axios"; import { GET_ERRORS, GET_PROJECT, GET_PROJECTS } from "./types"; export const createP ...

React - error caused by an invalid hook call. Uncaught Error: React encountered a minified error with code #

My goal is to incorporate the micro-frontend concept by implementing various react apps. Container Header Dashboard All three are separate applications. I intend to utilize the Header and Dashboard apps within the Container app. For the Header app, it& ...

Executing a function automatically when a component loads in react-redux can be achieved by utilizing useEffect hook in functional components

I have developed a webpage specifically designed to manage a "Cart" feature, with Cart details being fetched from a database. Upon clicking the "Click me" button, all the retrieved data is displayed within a react component. My goal now is to showcase the ...

Obtaining and storing multiple checkbox selections in a database using a JSP page

If users are required to input data on the first page, such as City, Country, and URL of the destination, and they need to select the type of destination from options like Winter, Christmas, and Summer (max 2 selections), how can these results be connected ...

Upon upgrading to webpack 5.x, I encountered the error message `Error: getaddrinfo ENOTFOUND localhost:8081` when trying to run `npm run serve`. What could be causing

Recently, I was tasked with upgrading a Vue project from webpack 4.x to webpack 5.x. Prior to the upgrade, my vue.config.js file looked like this: devServer: { port: 8081, public: process.env.PUBLIC_ADDRESS, }, The variable PUBLIC_ADDRESS was defined ...

What is the best way to retrieve data from a JSON object?

Can the status variable be used as a JSON object? What is the method to access the values of action_success and newIndex within the status object? Server: [HttpPost] public ActionResult UploadFiles() { // save file.. return Json(new { action_suc ...

Designing a dynamic presentation with varying intervals between slides

I am working on a jQuery slideshow that smoothly transitions between different <div> elements. In the current code, the slides change every 5 seconds. Is there a way to modify this so I can specify custom durations for displaying each slide? Here i ...