Skip to content

ColorUtils: Add setKelvin().#33381

Open
Nedunchezhiyan-M wants to merge 1 commit intomrdoob:devfrom
Nedunchezhiyan-M:feature/color-set-from-kelvin
Open

ColorUtils: Add setKelvin().#33381
Nedunchezhiyan-M wants to merge 1 commit intomrdoob:devfrom
Nedunchezhiyan-M:feature/color-set-from-kelvin

Conversation

@Nedunchezhiyan-M
Copy link
Copy Markdown

@Nedunchezhiyan-M Nedunchezhiyan-M commented Apr 13, 2026

Related issue: N/A

Description

Adds setKelvin( color, kelvin ) to a new examples/jsm/utils/ColorUtils.js module — converts a color temperature (1000K–40000K) to an approximate sRGB color using Tanner Helland's well-known algorithm.

Follows the suggestion from code review to place this in utils/ rather than core, using the same named-function module pattern as GeometryUtils, SceneUtils, etc.

import * as ColorUtils from 'three/addons/utils/ColorUtils.js';

const light = new THREE.PointLight();
ColorUtils.setKelvin( light.color, 3200 ); // tungsten studio light

Input is clamped to [1000, 40000]K. Output is passed through setRGB( r, g, b, SRGBColorSpace ) for correct color management.

Changes

  • examples/jsm/utils/ColorUtils.js — new module with setKelvin()
  • test/unit/addons/utils/ColorUtils.tests.js — unit tests (all pass, 0 failures)
  • test/unit/three.addons.unit.js — registers the new test file

@github-actions
Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 361.21
85.78
361.21
85.78
+0 B
+0 B
WebGPU 637.48
177.06
637.48
177.06
+0 B
+0 B
WebGPU Nodes 635.59
176.76
635.59
176.76
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 493.58
120.42
493.91
120.62
+335 B
+201 B
WebGPU 709.22
191.88
709.55
192.05
+335 B
+174 B
WebGPU Nodes 658.44
179.17
658.77
179.35
+335 B
+183 B

@Nedunchezhiyan-M Nedunchezhiyan-M changed the title Color: Add setFromKelvin(). ColorConverter: Add setKelvin(). Apr 14, 2026
@Nedunchezhiyan-M Nedunchezhiyan-M changed the title ColorConverter: Add setKelvin(). ColorUtils: Add setKelvin(). Apr 14, 2026
Adds setKelvin( color, kelvin ) to a new examples/jsm/utils/ColorUtils.js
module. Converts a color temperature (1000K–40000K) to an approximate sRGB
color using Tanner Helland's algorithm.

Useful for physically-based lighting setups where artists think in Kelvin
(candle ~1900K, tungsten ~3200K, daylight ~6500K, blue sky ~10000K).

  import * as ColorUtils from 'three/addons/utils/ColorUtils.js';
  ColorUtils.setKelvin( light.color, 3200 );
@Nedunchezhiyan-M Nedunchezhiyan-M force-pushed the feature/color-set-from-kelvin branch from 092d39e to e223177 Compare April 14, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants