Modifying the color temperature or warmth in Three.js can enhance the visual aesthetics

In my three.js project, I've set up a room scene with various lights added to it.

Features such as exposure, power, and height adjustments have been included in the setup.

You can view the progress so far by visiting this link.

My next goal is to implement a feature to adjust the temperature of the light source.

How would I go about doing that?

Answer №1

Take a look at the following code snippet for an illustration:

var renderer = new THREE.WebGLRenderer;
var scene = new THREE.Scene;
var camera = new THREE.PerspectiveCamera;
var cube = new THREE.Mesh( new THREE.BoxGeometry, new THREE.MeshPhongMaterial );
var spot = new THREE.SpotLight;
var inputs = [ ...document.querySelectorAll( 'input' ) ];
var destinationColor = new THREE.Color( 1, 1, 1 );
var fps = 1000 / 16;
var width = innerWidth;
var height = innerHeight / 2;

renderer.setSize( width, height );

camera.aspect = innerWidth / height;
camera.updateProjectionMatrix();
camera.position.set( 0, 0, 10 );
camera.lookAt( scene.position );

spot.position.set( 0, 0, 50 );
spot.lookAt( scene.position );

scene.add( cube, spot );

function inputChanged( event ){

  destinationColor.fromArray( inputs.map(input => input.value) );

}

function update(){

  spot.color.lerp( destinationColor, fps / 1000 );

  renderer.render( scene, camera );

}

document.body.appendChild( renderer.domElement );

inputs.forEach(input => input.addEventListener( 'change', inputChanged ));

setInterval( update, fps );
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/92/three.min.js"></script>

R <input type="range" min="0" max="1" step=".1" value="1" />
G <input type="range" min="0" max="1" step=".1" value="1" />
B <input type="range" min="0" max="1" step=".1" value="1" />

Verified on version r92 and confirmed compatibility with Chrome.

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

Fetching a URL from within a PHP file using AJAX

I am fairly new to creating web applications, so please bear with me if I am not using the correct technical terms. I came across this code for using a web proxy, but it doesn't seem to be working. I suspect that the issue lies in it not retrieving th ...

Retrieve an array of information from a firestore database query

I am encountering an issue while trying to retrieve information about all users who are friends of a specific user. I have attempted to gather the data by pushing it to an array and then returning it as a single JSON array. However, it seems that the dat ...

Retrieving unprocessed HTTP response using AJAX

Is it possible to retrieve the full raw HTTP response from the server using plain JavaScript AJAX in a web browser? When I say raw response, I mean both headers and body in a raw text format like the following: < HTTP/1.1 301 Moved Permanently < Lo ...

Parent-Child Communication in VueJS 2.0: How to effectively pass data from the parent component

Does anyone know a straightforward solution to this issue? I've been struggling to find one. Within my HTML file, there's a button that looks like this: <button @click="showModal">Show Modal</button> By clicking on the button, it t ...

Is there a distinction in invoking a service through reference or directly in Dependency Injection?

QUERY: Are there any discernible differences between the two instances of utilizing a factory service? Instance 1: angular.module('ramenBattleNetworkApp') .controller('MainCtrl', function ($scope, Helpers) { var testArray = [1 ...

Using AngularJS, call the $http function in response to another HTTP request

I recently started working with angular JS and I encountered a problem while trying to implement $http within the response of another $http call. My problem is that when I make a $http call within the response of another $http call, the data is not displa ...

The window.load() function seems to be malfunctioning as the event is not being triggered. There are no error

I'm struggling with getting the window.load() event to trigger on this specific website. The issue arose last night and despite there being no visible js or php errors, pinpointing the root cause has proven to be quite challenging. In syrp.home.main ...

Is there a way to execute this process twice without duplicating the code and manually adjusting the variables?

I'm looking to modify this code so that it can be used for multiple calendars simultaneously. For example, I want something similar to the following: Here is what I currently have: This is my JavaScript code: var Calendar = { start: function () ...

tips for replacing multiple route parameters in Angular using the replace function

I am facing an issue when trying to replace multiple parameters using the angular replace function. The problem is that the function only detects the first parameter. For example, if I have this route admin/management/{type}/card/{id}, and use the route.r ...

Blurred entities aligning in front of one another (THREE.JS)

While experimenting with three.js, I encountered an issue with objects appearing fuzzy when they overlap. The distortion looks like this. Can anyone provide assistance with this problem? Below is the code I'm currently using: // Initializing basic o ...

Javascript Callback function not working as expected

I'm attempting to include an anonymous callback function in my code. I know it might seem a bit messy. By typing into the intro section, it triggers the animation using the .typed method with specific parameters. What I'm struggling to do is imp ...

Guide on passing variables along the promise chain within a Node Express router

Upon reflection, I realized the difficulty of injecting or utilizing a variable inside the Promise scope without a surrounding object or a "this" reference to attach it to. ...

Hide or show list items in an unordered list using jQuery

I am interested in creating a script that can toggle between "show more" and "show less" functionality for elements in a list. I came across this script: HTML <ul id="myList"> <li>One</li> <li>Two</li> <li> ...

What sets apart "config" from "defaults" in Sencha Touch?

As a newcomer to Sencha Touch, I have one simple question that's been on my mind... Can someone explain the distinction between "config" and "defaults" in Sencha Touch? ...

Altering the color scheme of a specific column within a stacked bar chart using C3.js

I'm currently facing a challenge with highlighting specific values in a c3.js stacked bar chart. While I was able to change the color of an individual bar in a non-stacked bar following this example, I'm struggling to determine how to identify th ...

Having trouble retrieving data passed between functions

One of my Vue components looks like this: import '../forms/form.js' import '../forms/errors.js' export default{ data(){ return{ form: new NewForm({ email: '&apos ...

Automatically trigger the expansion of all panels within Vuetify using code

I'm attempting to use Vuetify 2.3.5 to programmatically control the opening and closing of expansion panels. <v-expansion-panels accordion> <v-expansion-panel v-for="(item,i) in faqs" :key="i"> <div class ...

What are some strategies for establishing communication between sibling components in Vue?

Currently, my Vue app has a structure that includes a "blackout" component for displaying modals and a router-view for various sub-menus. These components are siblings at the same level. <blackout v-if="this.popup.currentPopup"></blacko ...

Difficulty obtaining elements in Internet Explorer, however works fine in Chrome and Firefox

My <textarea> is set up like this: <textarea class="form-control notetext" id="{{this._id}}-notetext" name="notetext">{{this.text}}</textarea> I am using ajax to send data and load a partial webpage. After loading the content, I attemp ...

The URL for the form action does not match the URL of the current page

Issue: I'm encountering an issue with a form where the form action URL is different from the page URL where the form is located. Page URL = www.page.com Form action = "" Problem: After submitting the form, it redirects to the form action URL inst ...