Skip to content

Commit

Permalink
Examples: Updates for color management (pt3) (mrdoob#25889)
Browse files Browse the repository at this point in the history
* LWOLoader: Updates for color management
* MMDLoader: Updates for color management
* Examples: Update more loader examples for color management

---------

Co-authored-by: Michael Herzog <[email protected]>
  • Loading branch information
2 people authored and emmanueljl committed Apr 28, 2023
1 parent 5614fa9 commit 34d2799
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 63 deletions.
13 changes: 12 additions & 1 deletion examples/jsm/loaders/LWOLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
Points,
PointsMaterial,
RepeatWrapping,
SRGBColorSpace,
TextureLoader,
Vector2
} from 'three';
Expand Down Expand Up @@ -464,17 +465,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 +536,7 @@ class MaterialParser {

case 'Color':
maps.map = texture;
maps.map.colorSpace = SRGBColorSpace;
break;
case 'Diffuse':
maps.aoMap = texture;
Expand All @@ -542,10 +547,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 +588,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 ) {

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
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 );
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
12 changes: 5 additions & 7 deletions examples/webgl_loader_stl.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

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

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

let container, stats;

let camera, cameraTarget, scene, renderer;
Expand All @@ -61,7 +59,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 @@ -75,7 +73,7 @@
const loader = new STLLoader();
loader.load( './models/stl/ascii/slotted_disk.stl', function ( geometry ) {

const material = new THREE.MeshPhongMaterial( { color: 0xff5533, specular: 0x111111, shininess: 200 } );
const material = new THREE.MeshPhongMaterial( { color: 0xff9c7c, specular: 0x494949, shininess: 200 } );
const mesh = new THREE.Mesh( geometry, material );

mesh.position.set( 0, - 0.25, 0.6 );
Expand All @@ -92,7 +90,7 @@

// Binary files

const material = new THREE.MeshPhongMaterial( { color: 0xAAAAAA, specular: 0x111111, shininess: 200 } );
const material = new THREE.MeshPhongMaterial( { color: 0xd5d5d5, specular: 0x494949, shininess: 200 } );

loader.load( './models/stl/binary/pr2_head_pan.stl', function ( geometry ) {

Expand Down Expand Up @@ -151,10 +149,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

renderer = new THREE.WebGLRenderer( { antialias: true } );
Expand Down
Loading

0 comments on commit 34d2799

Please sign in to comment.