Skip to content

Commit b980375

Browse files
authored
VRMLLoader: Move to sRGB. (#26111)
* VRMLLoader: Move to sRGB. * Examples: Update screenshots.
1 parent 9c76ad6 commit b980375

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

examples/jsm/loaders/VRMLLoader.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
Scene,
2929
ShapeUtils,
3030
SphereGeometry,
31+
SRGBColorSpace,
3132
TextureLoader,
3233
Vector2,
3334
Vector3
@@ -1370,6 +1371,7 @@ class VRMLLoader extends Loader {
13701371
}
13711372

13721373
texture = new DataTexture( data, width, height );
1374+
texture.colorSpace = SRGBColorSpace;
13731375
texture.needsUpdate = true;
13741376
texture.__type = textureType; // needed for material modifications
13751377
break;
@@ -1442,6 +1444,7 @@ class VRMLLoader extends Loader {
14421444

14431445
texture.wrapS = wrapS;
14441446
texture.wrapT = wrapT;
1447+
texture.colorSpace = SRGBColorSpace;
14451448

14461449
}
14471450

@@ -1700,6 +1703,8 @@ class VRMLLoader extends Loader {
17001703

17011704
}
17021705

1706+
convertColorsToLinearSRGB( colorAttribute );
1707+
17031708
}
17041709

17051710
if ( normal ) {
@@ -1901,6 +1906,8 @@ class VRMLLoader extends Loader {
19011906

19021907
}
19031908

1909+
convertColorsToLinearSRGB( colorAttribute );
1910+
19041911
}
19051912

19061913
//
@@ -1966,7 +1973,15 @@ class VRMLLoader extends Loader {
19661973
const geometry = new BufferGeometry();
19671974

19681975
geometry.setAttribute( 'position', new Float32BufferAttribute( coord, 3 ) );
1969-
if ( color ) geometry.setAttribute( 'color', new Float32BufferAttribute( color, 3 ) );
1976+
1977+
if ( color ) {
1978+
1979+
const colorAttribute = new Float32BufferAttribute( color, 3 );
1980+
convertColorsToLinearSRGB( colorAttribute );
1981+
1982+
geometry.setAttribute( 'color', colorAttribute );
1983+
1984+
}
19701985

19711986
geometry._type = 'points';
19721987

@@ -2380,6 +2395,8 @@ class VRMLLoader extends Loader {
23802395

23812396
}
23822397

2398+
convertColorsToLinearSRGB( colorAttribute );
2399+
23832400
}
23842401

23852402
// normal attribute
@@ -3067,6 +3084,21 @@ class VRMLLoader extends Loader {
30673084

30683085
}
30693086

3087+
function convertColorsToLinearSRGB( attribute ) {
3088+
3089+
const color = new Color();
3090+
3091+
for ( let i = 0; i < attribute.count; i ++ ) {
3092+
3093+
color.fromBufferAttribute( attribute, i );
3094+
color.convertSRGBToLinear();
3095+
3096+
attribute.setXYZ( i, color.r, color.g, color.b );
3097+
3098+
}
3099+
3100+
}
3101+
30703102
/**
30713103
* Vertically paints the faces interpolating between the
30723104
* specified colors at the specified angels. This is used for the Background
@@ -3164,7 +3196,7 @@ class VRMLLoader extends Loader {
31643196
const colorA = colors[ thresholdIndexA ];
31653197
const colorB = colors[ thresholdIndexB ];
31663198

3167-
color.copy( colorA ).lerp( colorB, t );
3199+
color.copy( colorA ).lerp( colorB, t ).convertSRGBToLinear();
31683200

31693201
colorAttribute.setXYZ( index, color.r, color.g, color.b );
31703202

-207 Bytes
Loading

examples/webgl_loader_vrml.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
import { VRMLLoader } from 'three/addons/loaders/VRMLLoader.js';
3636
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
3737

38-
THREE.ColorManagement.enabled = false; // TODO: Confirm correct color management.
39-
4038
let camera, scene, renderer, stats, controls, loader;
4139

4240
const params = {
@@ -74,10 +72,10 @@
7472

7573
// light
7674

77-
const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x000000, 1 );
78-
scene.add( hemiLight );
75+
const ambientLight = new THREE.AmbientLight( 0xffffff, 0.4 );
76+
scene.add( ambientLight );
7977

80-
const dirLight = new THREE.DirectionalLight( 0xffffff, 0.5 );
78+
const dirLight = new THREE.DirectionalLight( 0xffffff, 0.6 );
8179
dirLight.position.set( 200, 200, 200 );
8280
scene.add( dirLight );
8381

@@ -87,7 +85,6 @@
8785
// renderer
8886

8987
renderer = new THREE.WebGLRenderer();
90-
renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
9188
renderer.setPixelRatio( window.devicePixelRatio );
9289
renderer.setSize( window.innerWidth, window.innerHeight );
9390
document.body.appendChild( renderer.domElement );

0 commit comments

Comments
 (0)