-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Closed
Closed
Copy link
Labels
Description
Describe the bug
In Lut.getColor(), once the input value is converted into an alpha between 0 and 1, alpha is multiplied by the number of colors to assign it an index, and then rounded to the nearest integer using Math.round.
I think this might be wrong, as alpha should be rounded to the nearest integer below, using Math.floor.
Otherwise, values that fall under a color i but are closer to its border with the color i+1 will eventually be assigned the color i+1.
Here is the referred line in the source code:
three.js/examples/jsm/math/Lut.js
Line 108 in cd4f4e7
| let colorPosition = Math.round( alpha * this.n ); |
To Reproduce
See code snippet below.
Code
import { Lut, ColorMapKeywords } from 'three/examples/jsm/math/Lut';
const colormap = ColorMapKeywords.rainbow;
const lut = Lut( colormap, 6 );
lut.setMax( 100.0 );
lut.setMin( 0.0 );
// This value gets a correct color
// alpha = 0.7
// alpha * nrColors = 4.2
// getColor picks this.lut[4]
const a = 70;
const colorA = lut.getColor( a );
// This value gets a wrong color
// alpha = 0.6
// alpha * nrColors = 3.6
// getColor picks this.lut[4] instead of this.lut[3]
const b = 60;
const colorB = lut.getColor( b );Screenshots
Maybe this schematic helps to illustrate my point:
Platform:
- Device: Desktop
- OS: Linux
- Browser: Firefox
- Three.js version: r137
scurest
