Skip to content

Commit

Permalink
Label and convert textures and colors correctly in MTLLoader (#23296)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Jan 24, 2022
1 parent be9d017 commit f49819b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions examples/jsm/loaders/MTLLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
MeshPhongMaterial,
RepeatWrapping,
TextureLoader,
Vector2
Vector2,
sRGBEncoding
} from 'three';

/**
Expand Down Expand Up @@ -358,6 +359,12 @@ class MaterialCreator {
map.wrapS = scope.wrap;
map.wrapT = scope.wrap;

if ( mapType === 'map' || mapType === 'emissiveMap' ) {

map.encoding = sRGBEncoding;

}

params[ mapType ] = map;

}
Expand All @@ -377,21 +384,21 @@ class MaterialCreator {

// Diffuse color (color under white light) using RGB values

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

break;

case 'ks':

// Specular color (color when light is reflected from shiny surface) using RGB values
params.specular = new Color().fromArray( value );
params.specular = new Color().fromArray( value ).convertSRGBToLinear();

break;

case 'ke':

// Emissive using RGB values
params.emissive = new Color().fromArray( value );
params.emissive = new Color().fromArray( value ).convertSRGBToLinear();

break;

Expand Down
1 change: 1 addition & 0 deletions examples/webgl_loader_obj_mtl.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
//

renderer = new THREE.WebGLRenderer();
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
Expand Down

0 comments on commit f49819b

Please sign in to comment.