Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: Updates for color management (pt3) #25889

Merged
merged 11 commits into from
Apr 20, 2023
14 changes: 13 additions & 1 deletion examples/jsm/loaders/LWOLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
BufferGeometry,
ClampToEdgeWrapping,
Color,
ColorManagement,
DoubleSide,
EquirectangularReflectionMapping,
EquirectangularRefractionMapping,
Expand All @@ -35,6 +36,7 @@ import {
Points,
PointsMaterial,
RepeatWrapping,
SRGBColorSpace,
TextureLoader,
Vector2
} from 'three';
Expand Down Expand Up @@ -464,17 +466,20 @@ class MaterialParser {

case 'Color':
maps.map = texture;
maps.map.colorSpace = SRGBColorSpace;
break;
case 'Roughness':
maps.roughnessMap = texture;
maps.roughness = 1;
break;
case 'Specular':
maps.specularMap = texture;
maps.specularMap.colorSpace = SRGBColorSpace;
maps.specular = 0xffffff;
break;
case 'Luminous':
maps.emissiveMap = texture;
maps.emissiveMap.colorSpace = SRGBColorSpace;
maps.emissive = 0x808080;
break;
case 'Luminous Color':
Expand Down Expand Up @@ -532,6 +537,7 @@ class MaterialParser {

case 'Color':
maps.map = texture;
maps.map.colorSpace = SRGBColorSpace;
break;
case 'Diffuse':
maps.aoMap = texture;
Expand All @@ -542,10 +548,12 @@ class MaterialParser {
break;
case 'Specular':
maps.specularMap = texture;
maps.specularMap.colorSpace = SRGBColorSpace;
maps.specular = 0xffffff;
break;
case 'Luminosity':
maps.emissiveMap = texture;
maps.emissiveMap.colorSpace = SRGBColorSpace;
maps.emissive = 0x808080;
break;
case 'Metallic':
Expand Down Expand Up @@ -581,7 +589,11 @@ class MaterialParser {

params.color = new Color().fromArray( attributes.Color.value );

} else params.color = new Color();
} else {

params.color = new Color();

}


if ( attributes.Transparency && attributes.Transparency.value !== 0 ) {
Expand Down
9 changes: 9 additions & 0 deletions examples/jsm/loaders/MMDLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Bone,
BufferGeometry,
Color,
ColorManagement,
CustomBlending,
TangentSpaceNormalMap,
DoubleSide,
Expand Down Expand Up @@ -1108,6 +1109,14 @@ class MaterialBuilder {
params.emissive = new Color().fromArray( material.ambient );
params.transparent = params.opacity !== 1.0;

if ( ColorManagement.enabled === true ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently reviewing the remaining explicit usage of ColorManagement in the example code.

Do we need this check here? This is the only loader which conditionally performs a color space conversion based on ColorManagement.enabled. Can't we just always assume color management and sRGB output is enabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the check would also be fine to remove, yes. VOXLoader does something similar:

_color.setRGB( r, g, b, SRGBColorSpace );


params.diffuse.convertSRGBToLinear();
params.specular.convertSRGBToLinear();
params.emissive.convertSRGBToLinear();

}

//

params.fog = true;
Expand Down
Binary file modified examples/screenshots/webgl_geometry_extrude_shapes2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_lwo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_mmd.jpg
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@takahirox does this result seem acceptable for the Hatsune Miku character?

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_mmd_audio.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_mmd_pose.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_ttf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions examples/webgl_geometry_extrude_shapes2.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

THREE.ColorManagement.enabled = false; // TODO: Confirm correct color management.

// From d3-threeD.js
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
Expand Down Expand Up @@ -443,7 +441,6 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
container.appendChild( renderer.domElement );

//
Expand Down
6 changes: 2 additions & 4 deletions examples/webgl_loader_collada_kinematics.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import TWEEN from 'three/addons/libs/tween.module.js';
import { ColladaLoader } from 'three/addons/loaders/ColladaLoader.js';

THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.

let container, stats;

let camera, scene, renderer;
Expand Down Expand Up @@ -84,7 +82,7 @@

// Grid

const grid = new THREE.GridHelper( 20, 20, 0x888888, 0x444444 );
const grid = new THREE.GridHelper( 20, 20, 0xc1c1c1, 0x8d8d8d );
scene.add( grid );

// Add the COLLADA
Expand All @@ -96,7 +94,7 @@

// Lights

const light = new THREE.HemisphereLight( 0xffeeee, 0x111122 );
const light = new THREE.HemisphereLight( 0xfff7f7, 0x494966 );
scene.add( light );

const pointLight = new THREE.PointLight( 0xffffff, 0.3 );
Expand Down
4 changes: 1 addition & 3 deletions examples/webgl_loader_collada_skinning.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import { ColladaLoader } from 'three/addons/loaders/ColladaLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.

let container, stats, clock, controls;
let camera, scene, renderer, mixer;

Expand Down Expand Up @@ -72,7 +70,7 @@

//

const gridHelper = new THREE.GridHelper( 10, 20, 0x888888, 0x444444 );
const gridHelper = new THREE.GridHelper( 10, 20, 0xc1c1c1, 0x8d8d8d );
scene.add( gridHelper );

//
Expand Down
4 changes: 1 addition & 3 deletions examples/webgl_loader_kmz.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { KMZLoader } from 'three/addons/loaders/KMZLoader.js';

THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.

let camera, scene, renderer;

init();
Expand All @@ -55,7 +53,7 @@

scene.add( camera );

const grid = new THREE.GridHelper( 50, 50, 0xffffff, 0x333333 );
const grid = new THREE.GridHelper( 50, 50, 0xffffff, 0x7b7b7b );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default color values of GridHelper are 0x444444 and 0x888888 right now. Would it make sense to update these in the ctor of GridHelper as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! Replied in main thread, since it is an important question and I don't want to lose the discussion.

scene.add( grid );

renderer = new THREE.WebGLRenderer( { antialias: true } );
Expand Down
6 changes: 2 additions & 4 deletions examples/webgl_loader_lwo.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { LWOLoader } from 'three/addons/loaders/LWOLoader.js';

THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.

let camera, scene, renderer;

init();
Expand All @@ -52,10 +50,10 @@
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xa0a0a0 );

const ambientLight = new THREE.AmbientLight( 0x222222 );
const ambientLight = new THREE.AmbientLight( 0x666666 );
scene.add( ambientLight );

const light1 = new THREE.DirectionalLight( 0x888888 );
const light1 = new THREE.DirectionalLight( 0xc1c1c1 );
light1.position.set( 0, 200, 100 );
scene.add( light1 );

Expand Down
4 changes: 1 addition & 3 deletions examples/webgl_loader_md2_control.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
import { MD2CharacterComplex } from 'three/addons/misc/MD2CharacterComplex.js';
import { Gyroscope } from 'three/addons/misc/Gyroscope.js';

THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.

let SCREEN_WIDTH = window.innerWidth;
let SCREEN_HEIGHT = window.innerHeight;

Expand Down Expand Up @@ -92,7 +90,7 @@

// LIGHTS

scene.add( new THREE.AmbientLight( 0x222222 ) );
scene.add( new THREE.AmbientLight( 0x666666 ) );

const light = new THREE.DirectionalLight( 0xffffff, 2.25 );
light.position.set( 200, 450, 500 );
Expand Down
7 changes: 2 additions & 5 deletions examples/webgl_loader_mmd.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
import { MMDLoader } from 'three/addons/loaders/MMDLoader.js';
import { MMDAnimationHelper } from 'three/addons/animation/MMDAnimationHelper.js';

THREE.ColorManagement.enabled = false; // TODO: Confirm correct color management.

let stats;

let mesh, camera, scene, renderer, effect;
Expand Down Expand Up @@ -88,10 +86,10 @@
gridHelper.position.y = - 10;
scene.add( gridHelper );

const ambient = new THREE.AmbientLight( 0x666666 );
const ambient = new THREE.AmbientLight( 0xaaaaaa, 1 );
scene.add( ambient );

const directionalLight = new THREE.DirectionalLight( 0x887766 );
const directionalLight = new THREE.DirectionalLight( 0xffffff, 1 );
directionalLight.position.set( - 1, 1, 1 ).normalize();
scene.add( directionalLight );

Expand All @@ -100,7 +98,6 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
container.appendChild( renderer.domElement );

effect = new OutlineEffect( renderer );
Expand Down
7 changes: 2 additions & 5 deletions examples/webgl_loader_mmd_audio.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
import { MMDLoader } from 'three/addons/loaders/MMDLoader.js';
import { MMDAnimationHelper } from 'three/addons/animation/MMDAnimationHelper.js';

THREE.ColorManagement.enabled = false; // TODO: Confirm correct color management.

let mesh, camera, scene, renderer, effect;
let helper;

Expand Down Expand Up @@ -95,10 +93,10 @@
camera.add( listener );
scene.add( camera );

const ambient = new THREE.AmbientLight( 0x666666 );
const ambient = new THREE.AmbientLight( 0xaaaaaa, 1 );
scene.add( ambient );

const directionalLight = new THREE.DirectionalLight( 0x887766 );
const directionalLight = new THREE.DirectionalLight( 0xffffff, 1 );
directionalLight.position.set( - 1, 1, 1 ).normalize();
scene.add( directionalLight );

Expand All @@ -107,7 +105,6 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
container.appendChild( renderer.domElement );

effect = new OutlineEffect( renderer );
Expand Down
7 changes: 2 additions & 5 deletions examples/webgl_loader_mmd_pose.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
import { MMDLoader } from 'three/addons/loaders/MMDLoader.js';
import { MMDAnimationHelper } from 'three/addons/animation/MMDAnimationHelper.js';

THREE.ColorManagement.enabled = false; // TODO: Confirm correct color management.

let camera, scene, renderer, effect;
let mesh, helper;

Expand Down Expand Up @@ -79,10 +77,10 @@
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xffffff );

const ambient = new THREE.AmbientLight( 0x666666 );
const ambient = new THREE.AmbientLight( 0xaaaaaa, 1 );
scene.add( ambient );

const directionalLight = new THREE.DirectionalLight( 0x887766 );
const directionalLight = new THREE.DirectionalLight( 0xffffff, 1 );
directionalLight.position.set( - 1, 1, 1 ).normalize();
scene.add( directionalLight );

Expand All @@ -91,7 +89,6 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
container.appendChild( renderer.domElement );

effect = new OutlineEffect( renderer );
Expand Down
12 changes: 5 additions & 7 deletions examples/webgl_loader_ply.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

import { PLYLoader } from 'three/addons/loaders/PLYLoader.js';

THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.

let container, stats;

let camera, cameraTarget, scene, renderer;
Expand All @@ -62,7 +60,7 @@

const plane = new THREE.Mesh(
new THREE.PlaneGeometry( 40, 40 ),
new THREE.MeshPhongMaterial( { color: 0x999999, specular: 0x101010 } )
new THREE.MeshPhongMaterial( { color: 0xcbcbcb, specular: 0x474747 } )
);
plane.rotation.x = - Math.PI / 2;
plane.position.y = - 0.5;
Expand All @@ -78,7 +76,7 @@

geometry.computeVertexNormals();

const material = new THREE.MeshStandardMaterial( { color: 0x0055ff, flatShading: true } );
const material = new THREE.MeshStandardMaterial( { color: 0x009cff, flatShading: true } );
const mesh = new THREE.Mesh( geometry, material );

mesh.position.y = - 0.2;
Expand All @@ -97,7 +95,7 @@

geometry.computeVertexNormals();

const material = new THREE.MeshStandardMaterial( { color: 0x0055ff, flatShading: true } );
const material = new THREE.MeshStandardMaterial( { color: 0x009cff, flatShading: true } );
const mesh = new THREE.Mesh( geometry, material );

mesh.position.x = - 0.2;
Expand All @@ -114,10 +112,10 @@

// Lights

scene.add( new THREE.HemisphereLight( 0x443333, 0x111122 ) );
scene.add( new THREE.HemisphereLight( 0x8d7c7c, 0x494966 ) );

addShadowedLight( 1, 1, 1, 0xffffff, 1.35 );
addShadowedLight( 0.5, 1, - 1, 0xffaa00, 1 );
addShadowedLight( 0.5, 1, - 1, 0xffd500, 1 );

// renderer

Expand Down
Loading